Skip to content

Commit 60e36d6

Browse files
committed
cast svd to torch_dtype
1 parent 8dbbe8d commit 60e36d6

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/sdnq/loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def apply_sdnq_options_to_module(model, dtype: torch.dtype = None, dequantize_fp
184184

185185
if dtype is not None and module.sdnq_dequantizer.result_dtype not in {torch.float32, torch.float64}:
186186
module.sdnq_dequantizer.result_dtype = dtype
187+
if module.svd_up is not None:
188+
module.svd_up.data = module.svd_up.to(dtype=dtype)
189+
module.svd_down.data = module.svd_down.to(dtype=dtype)
187190

188191
upcast_scale = bool(
189192
dequantize_fp32
@@ -208,9 +211,6 @@ def apply_sdnq_options_to_module(model, dtype: torch.dtype = None, dequantize_fp
208211
module.scale.data = module.scale.to(dtype=scale_dtype)
209212
if module.zero_point is not None:
210213
module.zero_point.data = module.zero_point.to(dtype=scale_dtype)
211-
if module.svd_up is not None:
212-
module.svd_up.data = module.svd_up.to(dtype=scale_dtype)
213-
module.svd_down.data = module.svd_down.to(dtype=scale_dtype)
214214

215215
if current_use_quantized_matmul is not None and current_use_quantized_matmul != module.sdnq_dequantizer.use_quantized_matmul:
216216
if not module.sdnq_dequantizer.re_quantize_for_matmul and not dtype_dict[module.sdnq_dequantizer.weights_dtype]["is_packed"]:

src/sdnq/quantizer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def sdnq_quantize_layer_weight(weight, layer_class_name=None, weights_dtype="int
309309

310310
if use_svd:
311311
try:
312-
weight, svd_up, svd_down = apply_svdquant(weight, rank=svd_rank, niter=svd_steps, dtype=scale_dtype)
312+
weight, svd_up, svd_down = apply_svdquant(weight, rank=svd_rank, niter=svd_steps, dtype=torch_dtype)
313313
if use_quantized_matmul:
314314
svd_up = svd_up.t_()
315315
svd_down = svd_down.t_()
@@ -422,10 +422,8 @@ def sdnq_quantize_layer_weight_dynamic(weight, layer_class_name=None, weights_dt
422422

423423
if use_svd:
424424
try:
425-
svd_weight, svd_up, svd_down = apply_svdquant(weight, rank=svd_rank, niter=svd_steps)
425+
svd_weight, svd_up, svd_down = apply_svdquant(weight, rank=svd_rank, niter=svd_steps, dtype=torch_dtype)
426426
svd_up, svd_down = prepare_svd_for_matmul(svd_up, svd_down, use_quantized_matmul)
427-
svd_up = svd_up.to(dtype=torch_dtype)
428-
svd_down = svd_down.to(dtype=torch_dtype)
429427
except Exception:
430428
svd_up, svd_down = None, None
431429
svd_weight = weight

0 commit comments

Comments
 (0)