Skip to content

Commit 15e33a7

Browse files
authored
Enhance customize.py to handle dynamic exports
Added dynamic configuration handling for llama2-70b model.
1 parent 8a14e60 commit 15e33a7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

script/add-custom-nvidia-system/customize.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from utils import *
33
import os
44
import shutil
5-
5+
import importlib.util
6+
import json
67

78
def preprocess(i):
89

@@ -43,6 +44,26 @@ def postprocess(i):
4344
src_file = os.path.join(tmp_script_path, "dummy_config.py")
4445

4546
dest_file = os.path.join(target_dir, f"{mlc_model}.py")
46-
shutil.copy(src_file, dest_file)
47+
48+
dummy_config_path = os.path.join(tmp_script_path, "dummy_config.py")
49+
spec = importlib.util.spec_from_file_location("dummy_config", dummy_config_path)
50+
dummy_module = importlib.util.module_from_spec(spec)
51+
spec.loader.exec_module(dummy_module)
52+
53+
EXPORTS = dummy_module.EXPORTS
54+
55+
# --- Example dynamic insertion ---
56+
if mlc_model == "llama2-70b":
57+
for k, v in EXPORTS.items():
58+
if isinstance(v, dict):
59+
v.setdefault('llm_fields.llm_gen_config_path',
60+
'code/llama2-70b/tensorrt/generation_config.json')
61+
62+
# --- Write modified config to destination ---
63+
with open(dest_file, "w") as f:
64+
f.write("# Auto-generated config\n\n")
65+
f.write("EXPORTS = ")
66+
f.write(repr(EXPORTS))
67+
f.write("\n")
4768

4869
return {'return': 0}

0 commit comments

Comments
 (0)