Skip to content

Commit

Permalink
Fix uninitialized variable in quantized compressors (#205)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markmc authored Nov 26, 2024
1 parent c6197ce commit 525ef3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ def compress_weight(
args=quantization_args,
dtype=quantization_args.pytorch_dtype(),
)
else:
quantized_weight = weight

if device is not None:
quantized_weight = quantized_weight.to(device)
if device is not None:
quantized_weight = quantized_weight.to(device)

return {"weight": quantized_weight}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def compress_weight(
args=quantization_args,
dtype=torch.int8,
)
else:
quantized_weight = weight

packed_weight = pack_to_int32(quantized_weight, quantization_args.num_bits)
weight_shape = torch.tensor(weight.shape)
Expand Down

0 comments on commit 525ef3a

Please sign in to comment.