tech
最后关于HC到mHC的地方讲的不是很好,我在这里补充一下: mHC 没有改变 HC 的基本数据流: $(h1,h2,\dots,hn) \rightarrow \text{mix} \rightarrow \text{Attention/FFN} \rightarrow \text{写回多个 stream}$ 1. HC 的问题:$H^{res}$ 完全自由 假设 $n=2$: $\begin{bmatrix} h'1\\ h'2 \end{bmatrix} = \underbrace{ \begin{bmatrix} a{11} & a{21}\\ a{12} & a{22} \end{bmatrix}}{H^{res}} \begin{bmatrix} h1\\ h2 \end{bmatrix} +\text{Attention output}$ 在普通 HC 中,这四个数基本可以自由学习。 于是可能学成: $H^{res}= \begin{bmatrix} 1.3 & 0.7\\ 0.4 &
Read note0 comments0 likes
Uncategorized
1. realize 是什么? 在 Inductor 里,realize 的意思是:把一个还没有真正落到内存里的中间表达式,强制变成一个真实 buffer。 例如: a + b 不一定会生成中间 tensor。Inductor 可以直接融合成: 这里 a+b 没有 realize,没有写 HBM。 但如果是: 如果 mm lowering 到 cuBLAS,cuBLAS 只能接受真实矩阵指针: 它不能接受表达式: 所以必须先: 因此: 不是因为“后面要读数据”,而是因为后面的 extern kernel 需要真实 storage pointer。 Reduction 不一定需要 realize,因为如果 reduction 是 Inductor 自己生成的 kernel,它可以把表达式 inline 进去: 可以生成: 不需要先生成 tmp =
Read note0 comments0 likes
tech
torch.compile粒度 torch.compile 的编译入口通常是一个 Python function/callable,但它的实际 JIT 粒度并不等于“整个函数大小”。更准确地说,Dynamo 会在函数执行过程中捕获能够连续 trace 的 tensor computation,并把这段连续区域表示成 FX graph;因此 torch.compile 的实际编译粒度是 FX graph region。一个函数可能被完整捕获成一张 FX graph,也可能因为 graph break 被切成多个 FX graph region;同时,同一个 region 还可能因为不同的 shape、dtype、device、Python flag 或控制流路径生成多个 specialized graph。 例如: 这里是以整个f作为一整个compiled region如果第一次调用是 f(x, True),Dynamo 实际 trace 到的是 x add mul relu 这条路径,并生成一张带有 guard 的 specialized
Read note0 comments0 likes