[ROCM] DSfp4 mla projection gemms weight dynamic quantization (#32238)

Signed-off-by: Aleksandr Malyshev <maleksan@amd.com>
Co-authored-by: Aleksandr Malyshev <maleksan@amd.com>
This commit is contained in:
Aleksandr Malyshev
2026-01-15 14:13:08 -06:00
committed by GitHub
co-authored by Aleksandr Malyshev
parent bd292be0c0
commit 8c11001ba2
4 changed files with 97 additions and 80 deletions
@@ -6,6 +6,7 @@ from types import MappingProxyType
from typing import Any
import regex as re
import torch
def deep_compare(dict1: Any, dict2: Any) -> bool:
@@ -103,3 +104,16 @@ def _is_equal_or_regex_match(
elif target == value:
return True
return False
# utility for tensor dims > 2 cases
def quark_quantize_weight_to_mxfp4(w: torch.Tensor):
assert w.dtype == torch.bfloat16, (
"Quark dynamic quantization is supported only for fp16 weights and only to MXF4"
)
from aiter.ops.triton.quant import dynamic_mxfp4_quant
*dims, d = w.shape
w, w_scales = dynamic_mxfp4_quant(w.reshape(-1, d))
return w.view(*dims, d // 2), w_scales.view(*dims, d // 32)