SDNQ fix hadamard with non pow2 shapes and add 16bit types to quant list

This commit is contained in:
Disty0
2026-07-08 19:29:57 +03:00
parent b257f49c31
commit 87684e1a21
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -102,7 +102,7 @@ def build_hadamard_n4(n: int, dtype: torch.dtype | None = None, device: torch.de
def build_hadamard(n: int, dtype: torch.dtype | None = None, device: torch.device | None = None) -> torch.FloatTensor:
if math.log(n, 4).is_integer():
return build_hadamard_n4(n, device=device, dtype=dtype)
elif math.log(n, 2).is_integer():
elif math.log2(n).is_integer():
return build_hadamard_n2(n, device=device, dtype=dtype)
else:
raise RuntimeError("Hadamard Group Size must be a power of 2.")
@@ -151,7 +151,7 @@ def apply_hadamard(weight: torch.Tensor, group_size: int = 256, hadamard: torch.
channel_size = weight.shape[1]
else:
channel_size = weight.shape[-1]
group_size = min(group_size, channel_size)
group_size = min(group_size, 2 ** int(math.log2(group_size)))
if channel_size % group_size != 0:
hadamard_pow2 = int(math.log2(group_size))
while channel_size % group_size != 0:
+1 -1
View File
@@ -179,5 +179,5 @@ def get_repo(model):
return None
sdnq_quant_modes = ["int8", "uint8", "int6", "uint6", "uint5", "uint4", "uint3", "uint2", "float8_e4m3fn", "float8_e3m4fn", "float6_e3m2fn", "float5_e2m2fn", "float4_e2m1fn", "float3_e1m1fn", "float2_e1m0fn"]
sdnq_quant_modes = ["int8", "uint8", "int6", "uint6", "uint5", "uint4", "uint3", "uint2", "float8_e4m3fn", "float8_e3m4fn", "float6_e3m2fn", "float5_e2m2fn", "float4_e2m1fn", "float3_e1m1fn", "float2_e1m0fn", "int16", "uint16", "float16"]
sdnq_matmul_modes = ["auto", "int8", "uint8", "float8_e4m3fn", "float16"]