【问题标题】:How to make VScode launch.json for a Python module如何为 Python 模块制作 VScode launch.json
【发布时间】:2021-08-03 17:15:41
【问题描述】:

我正在研究self-supervised muchine learning code

我想用python debugger 而不是pdb.set_trace() 来调试代码。 这是 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

为了使用 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"]
        }
    ]
}

我知道这行不通……TT

你能给我一些建议吗?

感谢您的宝贵时间。

【问题讨论】:

  • args 用于将命令行参数传递给正在启动的应用程序。 program 用于指定python文件。在开始调试之前查看debug python in vscode

标签: python visual-studio-code pytorch vscode-debugger


【解决方案1】:

指定要运行的模块 "module": "torch.distributed.launch"

您可以忽略-m 标志。将其他所有内容放在args 键下。

注意:确保在参数列表中包含 --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",
                    ]
                }
            ]
        }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-16
    • 2019-02-03
    • 2019-07-30
    • 2022-01-13
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多