怎么XXX.sh后再debug torchrun 以及 deepspeed,如何追进transformers库里面

安装

  1. 安装包 pip install debugpy -U
  2. 安装vscode关于python的相关插件

写配置

一般情况下,大家都是使用deepspeed、torchrun运行代码。参数都特别多,然后都是使用sh xxxx.sh启动脚本。

例如

deepspeed --num_nodes=1 --num_gpus=2 \
    testcode003.py  \
    --deepspeed "./config/default_offlload_zero2.json" \
    --model_name_or_path my_model \
    --output_dir hhh


在python代码里面(最前面加上这句话)
import debugpy
try:
    # 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
    debugpy.listen(("localhost", 9501))
    print("Waiting for debugger attach")
    debugpy.wait_for_client()
except Exception as e:
    pass
在vscode的launch.json的configuration里面,加上这个配置
        {
            "name": "sh_file_debug",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 9501
            },
            "justMyCode": false// 表示不只是我自己写的代码,还有库的可以追入
        },

🚨 上面的端口号都写一样。别搞错了。

启动

  1. 就正常启动,直接sh xxx.sh
  2. 在你需要debug的python文件,打上debug断点。
  3. 你看打印出来的东西,是不是出现Waiting for debugger attach.
  4. 再在vscode的debug页面,选择sh_file_debug进行debug。
  5. 就基本上完成了。确实是很方便。
  6. debug结束之后,别忘记把代码里面的 添加的代码,注销掉
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值