vscodetransformers_0">简要介绍如何使用vscode调试transformers源码
transformersEditable_install_1">以源码的方式安装transformers(官方手册为Editable install)
优先参考官方手册
git clone https://github.com/huggingface/transformers.git
cd transformers
pip install -e .
transformersexamplespytorchimageclassification_8">以下展示transformers/examples/pytorch/image-classification样例的调试方法
-
阅读image-classification的README.md文件,可知需要下载数据集beans和ViT模型(默认为google/vit-base-patch16-224-in21k),下图是我的数据集目录:
-
配置launch.json文件,这里面需要根据自己的路径修改一些变量,仅供参考:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "run_image_classification.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/transformers/examples/pytorch/image-classification/run_image_classification.py",
"args": [
"--train_dir", "transformers/examples/pytorch/image-classification/beans/data/train",
"--validation_dir", "transformers/examples/pytorch/image-classification/beans/data/validation",
"--output_dir", "./beans_outputs/",
"--remove_unused_columns","False",
"--label_column_name", "label",
"--do_train",
"--do_eval",
"--num_train_epochs", "5",
],
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTHONPATH": "${workspaceFolder}"
}
},
]
}