英文:
How does PyTorch know to differentiate functions?
问题
我对PyTorch Autograd的工作原理有一些了解 - 主要基于PyTorch文档。从概念上来说,我明白我们使用链式法则,沿途相乘导数等等。
我的问题是PyTorch如何知道要区分叶节点。具体来说,PyTorch如何知道...
- x的导数是1?
- sin(x)的导数是cos(x)?
- log_a(x)的导数是1/ (x * ln a)?
对于这些函数,PyTorch是否仅仅使用查找表?
此外,我认为sin、cos等的实现与库/系统有关。在不同架构(x86、Arm、Power、GPU等)上训练的深度学习模型是否会产生显著不同的结果(准确性)?还是这种差异只是与模型的训练变化一样的?
英文:
I have some understanding of how PyTorch Autograd works - mostly based on the PyTorch documentation. Conceptually I get that we use the chain rule and multiply the derivatives along the way etc.
My question is how PyTorch knows to differentiate the leaf nodes. Specifically, how does PyTorch know...
- the derivative of x is 1?
- that of sin(x) is cos(x)
- that of log_a(x) is 1/ (x * ln a)
For these kind of functions does PyTorch just use a lookup table?
Also, I believe the implementation of sin, cos etc are library/system dependent. Will DL models trained on different architectures (x86, Arm, Power, GPU etc) give significantly different results (accuracy). Or is this difference just the same as train-to-train variation ?
答案1
得分: 1
PyTorch不使用查找表,它将这些实用工具实现为autograd.Function
类。这些类提供了每个函数的forward
和backward
实现(用于功能接口的使用,例如torch.sin
,torch.log
等)。当进行推断时,图形会保留在输出张量中,并通过grad_fn
回调函数进行访问(通过backward
调用、autograd.grad
或其他自动图接口)以通过这个隐式图进行反向传播。然后,每个节点依次调用其底层autograd Function
的反向实现。
要了解有关Autograd功能的更多信息,建议访问“如何扩展Autograd”页面,该页面提供了关于Autograd内部工作方式的清晰指南和见解。
英文:
PyTorch does not use a lookup table, it implements these utilities as autograd.Function
classes. These provide the forward
and backward
implementations of each function (for functional interface to then utilize: eg. torch.sin
, torch.log
, ...). When an inference is made, the graph is kept in memory from the output tensor, and a grad_fn
callback function is accessed (via a backward
call, autograd.grad
, or other autograph interface) to backpropagate through this implicit graph. Each node in turn calls the backward implementation of its underlying autograd Function
.
For more information on Autograd's functionality I would suggest visiting the "How to extend Autograd" page which offers a clear guideline and insights as to how Autograd works under the hood.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论