简体   繁体   English

如何使 VScode launch.json 用于 Python 模块

[英]How to make VScode launch.json for a Python module

I'm reseaching self-supervised muchine learning code .我正在研究自我监督的 muchine 学习代码

And I have wanted to debug the code with python debugger not pdb.set_trace() .而且我想用python debugger而不是pdb.set_trace()来调试代码。 This is python command for ubuntu terminal.这是 ubuntu 终端的 python 命令。

python -m torch.distributed.launch --nproc_per_node=1 main_swav.py \
--data_path /dataset/imagenet/train \
--epochs 400 \
--base_lr 0.6 \
--final_lr 0.0006 \
--warmup_epochs 0 \
--batch_size 8 \
--size_crops 224 96 \
--nmb_crops 2 6 \
--min_scale_crops 0.14 0.05 \
--max_scale_crops 1. 0.14 \
--use_fp16 true \
--freeze_prototypes_niters 5005 \
--queue_length 380 \
--epoch_queue_starts 15\
--workers 10

In order to debug the code with VScode, I tried to revise launch.json like below as referring stackoverflow -question为了使用 VScode 调试代码,我尝试修改 launch.json 如下所示,参考stackoverflow -question

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "module": "torch.distributed.launch --nproc_per_node=1 main_swav.py",
            "request": "launch",
            "console": "integratedTerminal",
            "args": ["--data_path", "/dataset/imagenet/train"]
        }
    ]
}

I knew this would not work... TT我知道这行不通... TT

Could you give me some advice?你能给我一些建议吗?

Thank you for your time.感谢您的时间。

Specify the module you want to run with "module": "torch.distributed.launch"使用“module”指定要运行的"module": "torch.distributed.launch"

You can ignore the -m flag.您可以忽略-m标志。 Put everything else under the args key.将其他所有内容放在args键下。

Note: Make sure to include --nproc_per_node and the name of file ( main_swav.py ) in the list of arguments注意:确保在 arguments 列表中包含--nproc_per_node和文件名 ( main_swav.py )

{
            "version": "0.2.0",
            "configurations": [
                {
                    "name": "Python: Current File",
                    "type": "python",
                    "module": "torch.distributed.launch",
                    "request": "launch",
                    "console": "integratedTerminal",
                    "args": [
                        "--nproc_per_node", "1", 
                        "main_swav.py",
                        "--data_path", "/dataset/imagenet/train",
                    ]
                }
            ]
        }

Read more here: https://code.visualstudio.com/docs/python/debugging#_module在此处阅读更多信息: https://code.visualstudio.com/docs/python/debugging#_module

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VSCode:launch.json runtimeExecutable for Python? - VSCode: launch.json runtimeExecutable for Python? 在具有活动 virtualenv 的 python 模块上使用 vscode 调试器,在 launch.json 中显示“配置文件中的 python 路径无效” - Using vscode debugger on python module with active virtualenv, "the python path in your configuration file is invalid" in launch.json python 程序无法从 VSCode 的 launch.json 获取参数? - python program can not get the args from the launch.json of VSCode? vscode python调试,launch.json中带有参数语法错误 - vscode python debug with arguments syntax error in launch.json 如何设置 VsCode launch.json 用于 python 调试特定 function 等? - How do I set VsCode launch.json for python debugging of specific function among others? 如何在vscode的launch.json中为gdb启用自定义python脚本? - how to enable self-defined python script for gdb in launch.json of vscode? 如何在使用vscode进行调试时执行设置python虚拟环境的shell脚本(我需要对launch.json进行哪些更改) - how to execute a shell script which sets up the python virtual environment when debugging with vscode ( What changes do i need to make to launch.json) 如何在 Visual Studio Code 的 launch.json 中调试 Python 模块 - How to debug a Python module in Visual Studio Code's launch.json VSCode无效语法(launch.json,第2行) - VSCode invalid syntax (launch.json, line 2) 在 python 中,VSCode 调试器不会进入外部代码。 无法弄清楚如何在 launch.json 中编辑“justMyCode” - In python, VSCode debugger won't step into external code. Can't figure out how to edit "justMyCode" in launch.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM