简体   繁体   English

使用 pytorch 进行训练时,调试器挂起,即使运行正常

[英]When training with pytorch, debugger hangs, even though running works fine

Trying to train with pytorch hangs in debug mode, but works in run mode.尝试使用 pytorch 进行训练会在调试模式下挂起,但可以在运行模式下工作。

    sampler_train = WeightedRandomSampler(
        sample_weights_train,
        num_samples=len(sample_weights_train),
        replacement=True
    )

    train_loader = torch.utils.data.DataLoader(
        train_set,
        sampler=sampler_train,
        batch_size=32,
        num_workers=2
    )


   for epoch in range(10): 
        for i, data in enumerate(train_loader, 0):
            model.train()
            print("something")

After placing a breakpoint on model.train() , then moving on to the next line, "something" is never printed in debug mode, but is printed in run mode in Pycharm.model.train()上放置断点,然后转到下一行后,“something”永远不会在调试模式下打印,而是在 Pycharm 中以运行模式打印。

How to debug my code?如何调试我的代码?

After a long search, I found the answer here , which led to here经过长时间的搜索,我在这里找到了答案,导致这里

Setting Gevent Compatible in Preferences |在首选项中设置 Gevent 兼容 | Build, Execution, Deployment |构建、执行、部署 | Python Debugger solves the issue. Python 调试器解决了这个问题。

暂无
暂无

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

相关问题 使用 mediainfo 在 python3 中运行 check_output 会产生错误,即使终端中的相同调用工作正常 - Running a check_output in python3 with mediainfo produces an error, even though the same call in terminal works fine 即使测试工作正常,气流回填作业也会失败 - Airflow backfill job failing even though test works fine 虽然循环只运行一次,即使它之前运行良好 - While loop only running once even though it worked fine earlier 特定 DAG 停止在 Airflow 中运行,即使调度程序运行良好 - A specific DAG stops running in Airflow, even when the scheduler is running fine Pycharm未解析引用,即使使用这些“未解析”引用的代码也可以正常工作 - Pycharm unresolved reference, even though the code using these “unresolved” references works just fine 即使我在虚拟环境中安装了模块,“没有模块命名”错误也可以在本地主机上正常运行 - 'no module named' error even though I installed module in virtual environment and it works fine on localhost 即使代码的 rest 工作正常,我的打印语句也会被忽略 - My print statements get ignored even though the rest of the code works fine Integer List 在 Kattis 上的挑战不断得到错误的答案,即使它对测试用例工作得很好 - Keep getting wrong answer for Integer List challenge on Kattis even though it works just fine for the test case Python 代码在正常运行但在调试器中不起作用时有效 - groupby().max().unstack() - Python code works when running normally but not in the debugger - groupby().max().unstack() TensorFlow:运行training_op永远挂起 - TensorFlow: running training_op hangs forever
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM