Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.
Backgroud(背景信息)
ClippedSwiglu为带截断的SwiGLU(Swish Gated Linear Unit)激活函数,正向公式为 y=(clamp(x1,−l,l)+bias)⋅σ(α⋅min(x0,l))。本issue新增ClippedSwiglu反向算子的torch_extension接口,用于计算输入x的梯度。
Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.
Backgroud(背景信息)
ClippedSwiglu为带截断的SwiGLU(Swish Gated Linear Unit)激活函数,正向公式为 y=(clamp(x1,−l,l)+bias)⋅σ(α⋅min(x0,l))。本issue新增ClippedSwiglu反向算子的torch_extension接口,用于计算输入x的梯度。
正向计算流程:
dim进行合轴,合轴后维度为[pre, cut],cut必须为偶数,令 H=cut/2。interleaved切分x为 x0 和 x1 两部分:interleaved=True(奇偶切分):x0=x[:,::2],x1=x[:,1::2]interleaved=False(前后切分):x0=x[:,:H],x1=x[:,H:]反向计算流程:
interleaved散回,与正向切分方式对应)。Origin(信息来源)
大规模MOE场景容易出现激活异常值,导致MOE训练不稳定。因此DeepSeekV4、MiniMax M3等模型中MOE部分的Swiglu额外做了clamp操作。带clamp操作的Swiglu操作由小算子拼接,进行融合后预计能在整网带来5%+的性能提升,目前ClippedSwiglu正向算子已经实现,需要补齐训练场景下的反向算子实现。
Benefit / Necessity(价值/作用)
Design(设计方案)
为ClippedSwigluGrad算子新增torch_extension接口,封装对应的aclnn API,支持单算子模式和TorchAir图模式调用。
Python接口
cann_ops_nn.clipped_swiglu_grad( grad_y: Tensor, x: Tensor, *, group_index: Tensor = None, dim: int = -1, alpha: float = 1.702, limit: float = 7.0, bias: float = 1.0, interleaved: bool = True, clamp_mode: int = 0 ) -> Tensor参数说明
返回值说明
产品支持情况
约束说明