mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
SDNQ fix hadamard with non pow2 shapes and add 16bit types to quant list
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user