Skip to content

Commit 011a2b5

Browse files
cuichenxAmir Hussein
authored andcommitted
Add peft export check (NVIDIA-NeMo#13835)
Signed-off-by: Chen Cui <[email protected]> Signed-off-by: Amir Hussein <[email protected]>
1 parent b8f5d3a commit 011a2b5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

nemo/collections/llm/recipes/qwen3_30b_a3b.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def pretrain_recipe(
163163
seq_length=seq_length,
164164
global_batch_size=global_batch_size,
165165
micro_batch_size=micro_batch_size,
166-
tokenizer=run.Config(AutoTokenizer, "Qwen/Qwen3-30B_A3B"),
166+
tokenizer=run.Config(AutoTokenizer, "Qwen/Qwen3-30B-A3B"),
167167
),
168168
log=default_log(dir=dir, name=name, tensorboard_logger=tensorboard_logger(name=name)),
169169
optim=distributed_fused_adam_with_cosine_annealing(

nemo/lightning/io/api.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,26 @@ def load_connector_from_trainer_ckpt(path: Path, target: str) -> ModelConnector:
192192
"hf"
193193
)
194194
"""
195-
model: pl.LightningModule = load_context(path).model
195+
model: pl.LightningModule = load_context(path, subpath="model")
196196

197197
if not isinstance(model, ConnectorMixin):
198198
raise ValueError("Model must be an instance of ConnectorMixin")
199199

200200
return model.exporter(target, path)
201201

202202

203+
def _verify_peft_export(path: Path, target: str):
204+
if target == "hf" and (path / "weights" / "adapter_metadata.json").exists():
205+
raise ValueError(
206+
f"Your checkpoint \n`{path}`\ncontains PEFT weights, but your specified export target `hf` should be "
207+
f"used for full model checkpoints. "
208+
f"\nIf you want to convert NeMo 2 PEFT to Hugging Face PEFT checkpoint, set `target='hf-peft'`. "
209+
f"If you want to merge LoRA weights back to the base model and export the merged full model, "
210+
f"run `llm.peft.merge_lora` first before exporting. See "
211+
f"https://docs.nvidia.com/nemo-framework/user-guide/latest/sft_peft/peft_nemo2.html for more details."
212+
)
213+
214+
203215
def export_ckpt(
204216
path: Path,
205217
target: str,
@@ -247,6 +259,7 @@ def export_ckpt(
247259
nemo_ckpt_path = Path("/path/to/model.ckpt")
248260
export_path = export_ckpt(nemo_ckpt_path, "hf")
249261
"""
262+
_verify_peft_export(path, target)
250263
exporter: ModelConnector = load_connector(path, target)
251264
_output_path = output_path or Path(path) / target
252265

0 commit comments

Comments
 (0)