连接服务器的vscode在虚拟环境中调试具有命令行参数使用gpu的python代码
·
值得专门一篇文章,把链接存在乱七八糟小技巧中吧。
首先,在run中点击 add configuration。进行编辑,示例如下:
{
// 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: Current File",
"python": "/S/xj/anaconda3/envs/sum/bin/python",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env":{
"CUDA_VISIBLE_DEVICES":"1"
},
"args": [
"gigaword-graph",
"-a", "transformer_stack_with_graph_copy_gigaword_big",
"--optimizer", "adam",
"--lr", "0.0001",
"-s", "src",
"-t", "tgt",
"--dropout", "0.1",
"--max-tokens", "2000",
"--share-decoder-input-output-embed",
"--task", "translation_with_graph_attention_with_copy",
"--adam-betas", "(0.9, 0.98)" ,
"--save-dir", "checkpoints/transformer-graph-gigaword",
"--share-all-embeddings",
"--lr-scheduler", "reduce_lr_on_plateau",
"--lr-shrink", "0.5",
"--criterion", "cross_entropy_copy",
"--update-freq", "2"
]
}
]
}
主要有:
- python中写你虚拟环境的python的路径
- env 写你使用哪个gpu。想必也可以增加其他的环境变量。
- args中写入你传入的命令行参数。看来数字也可以作为字符串传入,名字和值直接用逗号。格式模仿上面就行。
然后就可以设断点,在程序入口debug开始run了
参考:https://code.visualstudio.com/docs/python/debugging
更多推荐
所有评论(0)