【问题标题】:RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phaseRuntimeError:在当前进程完成其引导阶段之前尝试启动一个新进程
【发布时间】:2021-12-30 10:28:10
【问题描述】:

我开发了一个使用 Pytorch 执行神经网络建模的代码。我的代码在我的 Pycharm 控制台中运行良好,但是当我从脚本运行它时它不起作用。我检查了几次,没有发现任何明显的问题。

我得到的完整错误是:

运行时错误: 已尝试在 当前进程已完成其引导阶段。

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

我的代码中的错误似乎源于我的培训师(更具体地说,在最后一行,即“val_split=0.1)”:

trainer.fit(
        X_tab=X_tab,
        target=target,
        n_epochs=5,
        batch_size=256,
        val_split=0.1)

我使用 Python 3.7 和 Windows,如果有帮助的话。这可能是多处理问题还是其他问题?

【问题讨论】:

    标签: python torch


    【解决方案1】:

    我得到了答案!

    我的理解是这与 reduction.py 后端代码有关。

    如果有人遇到此运行时错误,您可以添加:

    if __name__ == '__main__':
        import code
        code
        code   
    

    它会解决问题!

    【讨论】:

      猜你喜欢
      • 2021-01-28
      • 2023-01-20
      • 2019-07-30
      • 1970-01-01
      • 2022-11-29
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多