Skip to content

Commit 21fa47f

Browse files
committed
copy over json files in export path as well
Signed-off-by: Zhiyu Cheng <[email protected]>
1 parent 9d305fa commit 21fa47f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

examples/llm_ptq/example_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ def _resolve_model_path(model_name_or_path: str, trust_remote_code: bool = False
345345

346346

347347
def copy_custom_model_files(source_path: str, export_path: str, trust_remote_code: bool = False):
348-
"""Copy custom model files (configuration_*.py, modeling_*.py, etc.) from source to export directory.
348+
"""Copy custom model files (configuration_*.py, modeling_*.py, *.json, etc.) from source to export directory.
349+
350+
This function copies custom Python files and JSON configuration files that are needed for
351+
models with custom code. It excludes config.json and model.safetensors.index.json as these
352+
are typically handled separately by the model export process.
349353
350354
Args:
351355
source_path: Path to the original model directory or HuggingFace model ID
@@ -383,12 +387,16 @@ def copy_custom_model_files(source_path: str, export_path: str, trust_remote_cod
383387
"processing_*.py",
384388
"image_processing_*.py",
385389
"feature_extraction_*.py",
390+
"*.json",
386391
]
387392

388393
copied_files = []
389394
for pattern in custom_file_patterns:
390395
for file_path in source_dir.glob(pattern):
391396
if file_path.is_file():
397+
# Skip config.json and model.safetensors.index.json as they're handled separately
398+
if file_path.name in ["config.json", "model.safetensors.index.json"]:
399+
continue
392400
dest_path = export_dir / file_path.name
393401
try:
394402
shutil.copy2(file_path, dest_path)

examples/llm_ptq/hf_ptq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def output_decode(generated_ids, input_shape):
612612
inference_pipeline_parallel=args.inference_pipeline_parallel,
613613
)
614614

615-
# Copy custom model files for TensorRT-LLM export as well
615+
# Copy custom model files (Python files and JSON configs) for TensorRT-LLM export
616616
copy_custom_model_files(args.pyt_ckpt_path, export_path, args.trust_remote_code)
617617
else:
618618
# Check arguments for unified_hf export format and set to default if unsupported arguments are provided
@@ -631,7 +631,7 @@ def output_decode(generated_ids, input_shape):
631631
export_dir=export_path,
632632
)
633633

634-
# Copy custom model files (configuration_*.py, modeling_*.py, etc.) if trust_remote_code is used
634+
# Copy custom model files (Python files and JSON configs) if trust_remote_code is used
635635
copy_custom_model_files(args.pyt_ckpt_path, export_path, args.trust_remote_code)
636636

637637
# Restore default padding and export the tokenizer as well.

0 commit comments

Comments
 (0)