diff --git a/quantize_streaming.py b/quantize_streaming.py index b85546f..bf580df 100644 --- a/quantize_streaming.py +++ b/quantize_streaming.py @@ -69,11 +69,14 @@ def streaming_quantize(model_path: str, output_path: str): print(f" Quantizing {len(weight_keys)} tensors...") + quant_states = {} for key in weight_keys: try: weight = state_dict[key] qweight, qstate = quantize_weight_nf4(weight) state_dict[key] = qweight + if qstate is not None: + quant_states[f"{key}.quant_state"] = qstate del weight, qweight, qstate gc.collect() torch.cuda.empty_cache() @@ -88,8 +91,8 @@ def streaming_quantize(model_path: str, output_path: str): for k, v in state_dict.items() } - save_file(state_dict, output_path / shard_name) - print(f" ✓ Saved {shard_name}") + torch.save({**state_dict, **quant_states}, output_path / shard_name) + print(f" ✓ Saved {shard_name} ({len(quant_states)} quant states)") del state_dict gc.collect()