mirror of
https://github.com/OpenBMB/VoxCPM.git
synced 2026-09-20 10:53:32 +08:00
Fix load saved lora_config.json when loading LoRA weights
from_pretrained(lora_weights_path=...) built a default r=8 LoRAConfig and crashed for checkpoints trained with other ranks (e.g. r=32). Load the checkpoint's lora_config.json so r/alpha match; fall back to the default.
This commit is contained in:
@@ -45,13 +45,16 @@ class VoxCPM:
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
# If lora_weights_path is provided but no lora_config, create a default one
|
||||
# If lora_weights_path is provided but no lora_config, load the saved
|
||||
# lora_config.json (so r/alpha match the checkpoint); else use a default.
|
||||
if lora_weights_path is not None and lora_config is None:
|
||||
lora_config = LoRAConfig(
|
||||
enable_lm=True,
|
||||
enable_dit=True,
|
||||
enable_proj=False,
|
||||
)
|
||||
cfg_path = os.path.join(lora_weights_path, "lora_config.json")
|
||||
if os.path.isdir(lora_weights_path) and os.path.isfile(cfg_path):
|
||||
with open(cfg_path, "r", encoding="utf-8") as f:
|
||||
lora_config = LoRAConfig(**json.load(f)["lora_config"])
|
||||
print(f"Loaded LoRAConfig from: {cfg_path}", file=sys.stderr)
|
||||
else:
|
||||
lora_config = LoRAConfig(enable_lm=True, enable_dit=True, enable_proj=False)
|
||||
print(f"Auto-created default LoRAConfig for loading weights from: {lora_weights_path}", file=sys.stderr)
|
||||
|
||||
# Determine model type from config.json architecture field
|
||||
|
||||
Reference in New Issue
Block a user