TensorFlow中的一个重要ops---MatMul的实现(二)

本文深入探讨了在TensorFlow中如何为MatMul操作实现梯度计算。通过自动微分和链式法则,将梯度从损失函数L对输出y的导数转换为对输入x的导数,以便进行梯度下降优化。文章解释了MatMul梯度节点的Python实现,并给出了矩阵求导的公式,帮助理解这一过程。
摘要由CSDN通过智能技术生成

上面一篇文章我们主要介绍了MatMul这个ops的正向计算的实现,我们知道模型的最后一步是计算优化模型的参数,而一般采用的方法是梯度下降法,所以每个ops节点不仅要实现一个正向的计算节点,还要实现一个反向的梯度计算节点。

关于反向计算的结点官网有如下一段介绍:


Implement the gradient in Python

Given a graph of ops, TensorFlow uses automatic differentiation (backpropagation) to add new ops representing gradients with respect to the existing ops (seeGradient Computation). To make automatic differentiation work for new ops, you must register a gradient function which computes gradients with respect to the ops' inputs given gradients with respect to the ops' outputs.Mathematically, if an op computes y = f(x) the registered gradient op converts gradients ∂L/∂y 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值