From 74027ccf44e5cd305332a4e06830ee048f5483bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 18:28:14 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/_compressed_quantize.py | 2 +- unsloth/save.py | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/unsloth/_compressed_quantize.py b/unsloth/_compressed_quantize.py index 015a23a975..1b3b0d57db 100644 --- a/unsloth/_compressed_quantize.py +++ b/unsloth/_compressed_quantize.py @@ -186,7 +186,7 @@ def main(): cfg_path = os.path.join(args.out, "config.json") cfg = {} if os.path.exists(cfg_path): - with open(cfg_path, "r", encoding="utf-8") as f: + with open(cfg_path, "r", encoding = "utf-8") as f: cfg = json.load(f) if "quantization_config" not in cfg: print(f"Unsloth: ERROR - no quantization_config written to {cfg_path}", flush = True) diff --git a/unsloth/save.py b/unsloth/save.py index 0ea734950e..8fd9377a4f 100644 --- a/unsloth/save.py +++ b/unsloth/save.py @@ -3700,15 +3700,17 @@ def _unsloth_save_compressed_tensors( # merge_and_overwrite_lora deletes save_directory when push_to_hub=True. print(f"Unsloth: Merging to 16bit before {scheme} quantization...") merge_args = dict(merge_kwargs) - merge_args.update(dict( - model = model, - tokenizer = tokenizer, - save_directory = save_directory, - save_method = "merged_16bit", - push_to_hub = False, - token = token, - is_main_process = is_main_process, - )) + merge_args.update( + dict( + model = model, + tokenizer = tokenizer, + save_directory = save_directory, + save_method = "merged_16bit", + push_to_hub = False, + token = token, + is_main_process = is_main_process, + ) + ) unsloth_generic_save(**merge_args) for _ in range(3): @@ -3764,11 +3766,15 @@ def _unsloth_save_compressed_tensors( calib_kind = "disk" if os.path.isdir(calib_value) else "hfid" elif hasattr(calibration_dataset, "save_to_disk"): import tempfile + # Only persist the samples we need, so multi-GB training sets are not fully copied. ds_to_save = calibration_dataset try: - if (num_calibration_samples and hasattr(ds_to_save, "select") - and len(ds_to_save) > num_calibration_samples): + if ( + num_calibration_samples + and hasattr(ds_to_save, "select") + and len(ds_to_save) > num_calibration_samples + ): ds_to_save = ds_to_save.shuffle(seed = 42).select(range(num_calibration_samples)) except Exception: ds_to_save = calibration_dataset