Rework merge_network_on_save to handle dequantization on merging and saving for much more efficient full finetuning.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user