[Bugfix][ROCm] Fix MiniMax-M3 fused MXFP8 block scale (#53674)
Signed-off-by: maithilijoshi20 <97733343+maithilijoshi20@users.noreply.github.com>
This commit is contained in:
@@ -83,6 +83,8 @@ def _swiglu_oai_quant_kernel(
|
||||
limit,
|
||||
HAS_LIMIT: tl.constexpr,
|
||||
BLOCK_M: tl.constexpr,
|
||||
FP8_MAX: tl.constexpr,
|
||||
TINY: tl.constexpr,
|
||||
):
|
||||
"""SwiGLU-OAI (split layout) fused with per-32-block MXFP8 (E4M3 + E8M0)
|
||||
quant. Each program handles ``[BLOCK_M, 32]`` of the ``[M, I]`` output (one
|
||||
@@ -109,8 +111,8 @@ def _swiglu_oai_quant_kernel(
|
||||
gate = tl.minimum(gate, limit)
|
||||
up = tl.minimum(tl.maximum(up, -limit), limit)
|
||||
act = gate * tl.sigmoid(alpha * gate) * (up + beta) # [BLOCK_M, 32] fp32
|
||||
amax = tl.maximum(tl.max(tl.abs(act), axis=1), 1e-30) # [BLOCK_M]
|
||||
sb = tl.minimum(tl.maximum(tl.floor(tl.log2(amax)) + 127.0, 0.0), 254.0)
|
||||
amax = tl.maximum(tl.max(tl.abs(act), axis=1), TINY) # [BLOCK_M]
|
||||
sb = tl.minimum(tl.maximum(tl.ceil(tl.log2(amax / FP8_MAX)) + 127.0, 0.0), 254.0)
|
||||
descale = tl.exp2(sb - 127.0)
|
||||
aq = (act / descale[:, None]).to(aq_ptr.dtype.element_ty)
|
||||
tl.store(
|
||||
@@ -173,6 +175,8 @@ def swiglu_oai_quantize_mxfp8(
|
||||
0.0 if limit is None else float(limit),
|
||||
HAS_LIMIT=limit is not None,
|
||||
BLOCK_M=block_m,
|
||||
FP8_MAX=float(torch.finfo(MXFP8_VALUE_DTYPE).max),
|
||||
TINY=float(torch.finfo(torch.float32).tiny),
|
||||
num_warps=4,
|
||||
)
|
||||
return aq, asc
|
||||
|
||||
Reference in New Issue
Block a user