4. stable_topological_sort 对节点依赖进行排序 5. quant_lift_up """Lift up the quant node before view like nodes. It can benefit performanceof Attention like block. For example, we have the pattern as:DQDQ LINEARLINEAR VIEWVIEW PERMUTEPERMUTE TRANSPOSEQ QDQ DQMatmulDIVADDSOFTMAXWe want to ...
topological_sort(variable)是得到以variable为最右节点的计算图梯度的计算顺序,即有向无环图的拓扑排序。即每次寻找计算图中入度为0(没有inputs)的节点,再倒序。 backpropagate(variable, deriv)是计算以variable为最右侧节点,上层传递梯度为deriv时,最终传递给计算图的叶子节点的梯度,由backward()调用。其步骤是根据t...
可以从top也可以从bottom来时传播,本教程使用BFS topological sort of a directed acyclic graph Steps: Call topological sort create a dictionary to record derivatives if the scalar is leaf, record to tensor.grad, else call chainrule and accumulate derivatives Q: 为什么只在leaf tensor记录Grad?A: 是为...
pytorch torch fx 计算图变换 计算图匹配 融合 torch.fx设计的目标就是在图上做各种变换,以完成图优化、量化等图功能性的改变。torch.fx在python函数调用层级利用符号追踪技术symbolic trace,将一个Module转换为静态图,然后在计算图上做IR到IR的变换,之后可以反向生成源代码。整个流程就是,python code ->symbolic tr...
ScalarFunction父类与各种运算子类 Context 前向传播的过程 反向传播的过程 chain_rule Backpropagation topological_sort backpropagate 训练过程 模型定义 数据集 本文是我完成minitorch的Autodiff部分后所记笔记,完成这一部分后,minitorch已经可以进行简单的模型训练了,但由于没有tensor化,训练效率不高。