Skip to content

Commit 525ef3a

Browse files
authored
Fix uninitialized variable in quantized compressors (#205)
Both compressors have a can_quantize() check, which if ever doesn't succeed would trigger: > UnboundLocalError: cannot access local variable 'quantized_weight' where it is not associated with a value
1 parent c6197ce commit 525ef3a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/compressed_tensors/compressors/quantized_compressors/naive_quantized.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ def compress_weight(
9393
args=quantization_args,
9494
dtype=quantization_args.pytorch_dtype(),
9595
)
96+
else:
97+
quantized_weight = weight
9698

97-
if device is not None:
98-
quantized_weight = quantized_weight.to(device)
99+
if device is not None:
100+
quantized_weight = quantized_weight.to(device)
99101

100102
return {"weight": quantized_weight}
101103

src/compressed_tensors/compressors/quantized_compressors/pack_quantized.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def compress_weight(
9494
args=quantization_args,
9595
dtype=torch.int8,
9696
)
97+
else:
98+
quantized_weight = weight
9799

98100
packed_weight = pack_to_int32(quantized_weight, quantization_args.num_bits)
99101
weight_shape = torch.tensor(weight.shape)

0 commit comments

Comments
 (0)