我在单个单元格中的 google colab 中运行以下代码片段:
%debug
# Create tensors of shape (10, 3) and (10, 2).
x = torch.randn(10, 3)
y = torch.randn(10, 2)
# Build a fully connected layer.
linear = nn.Linear(3, 2)
print ('w: ', linear.weight)
print ('b: ', linear.bias)
我希望调试一段代码(逐行执行)以了解发生了什么。我希望进入函数 nn.Linear。
但是,当我单步执行时,它根本没有进入该功能。有没有办法逐行通过 nn.Linear ?另外,如何在 nn.Linear 中设置断点?此外,我也希望逐行浏览代码片段。但是,如图所示,step 命令会自动单步执行并执行 print 语句。
原文由 thegreatcoder 发布,翻译遵循 CC BY-SA 4.0 许可协议
从 Python 3.7 开始,您可以使用内置的 断点函数。如果这不可用,您可以使用
反而。
如果你想执行下一行,你可以尝试
n
(next) 而不是s
(step)。