Rework merge_network_on_save to handle dequantization on merging and saving for much more efficient full finetuning.

This commit is contained in:
Jaret Burkett
2026-06-25 13:19:38 -06:00
parent 6ecff36f26
commit 5f04ae7ad5
8 changed files with 147 additions and 41 deletions

View File

@@ -489,6 +489,7 @@ class HidreamO1Model(BaseModel):
return False
def save_model(self, output_path, meta, save_dtype):
from toolkit.util.quantize import dequantize_if_quantized
transformer: Qwen3VLForConditionalGeneration = unwrap_model(self.model)
if self.is_comfy_weight:
sd = transformer.state_dict()
@@ -496,7 +497,8 @@ class HidreamO1Model(BaseModel):
for key, value in sd.items():
if "lm_head.weight" in key:
continue # comfy checkpoint doesnt have the lm head, so skip it
save_dict[key] = value.clone().to("cpu", dtype=save_dtype)
# dequantize any quantized (e.g. torchao) weights so we save plain full precision tensors
save_dict[key] = dequantize_if_quantized(value).clone().to("cpu", dtype=save_dtype)
if not output_path.endswith(".safetensors"):
output_path += ".safetensors"