@@ -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 } `\n contains PEFT weights, but your specified export target `hf` should be "
207+ f"used for full model checkpoints. "
208+ f"\n If 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+
203215def 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