Skip to content

Commit

Permalink
Improve memory usage by properly cleaning up weights as quantized
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoin committed Jun 13, 2024
1 parent ffea17e commit 9b8abad
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions auto_fp8/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ def quantize_weights(
or name in quantize_config.ignored_layers
):
continue
quant_weight, quant_scale = per_tensor_quantize(linear.weight)
quant_linear = FP8DynamicLinear(quant_weight, quant_scale, linear.bias)
quant_weight, quant_scale = per_tensor_quantize(linear.weight.clone())
bias = linear.bias.clone() if linear.bias is not None else None
quant_linear = FP8DynamicLinear(quant_weight, quant_scale, bias)
replace_module(model, name, quant_linear)
del linear.weight
del linear.bias
del linear
cleanup_memory()
cleanup_memory()


def quantize_activations(
Expand Down

0 comments on commit 9b8abad

Please sign in to comment.