Skip to content

Commit 070fa81

Browse files
authored
Refactor preprocess function for model configuration
Refactor the preprocess function to read and modify the content of a source file directly instead of using dynamic module loading. Remove unnecessary lines related to EXPORTS and adjust content based on model type.
1 parent 2a82381 commit 070fa81

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

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

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

86

97
def preprocess(i):
@@ -46,26 +44,19 @@ def postprocess(i):
4644

4745
dest_file = os.path.join(target_dir, f"{mlc_model}.py")
4846

49-
dummy_config_path = os.path.join(tmp_script_path, "dummy_config.py")
50-
spec = importlib.util.spec_from_file_location(
51-
"dummy_config", dummy_config_path)
52-
dummy_module = importlib.util.module_from_spec(spec)
53-
spec.loader.exec_module(dummy_module)
47+
with open(src_file, "r") as f:
48+
content = f.read()
5449

55-
EXPORTS = dummy_module.EXPORTS
50+
# Replace model name
51+
content = re.sub(r"'llama2-70b'", f"'{mlc_model}'", content)
5652

57-
# --- Example dynamic insertion ---
58-
if mlc_model == "llama2-70b":
59-
for k, v in EXPORTS.items():
60-
if isinstance(v, dict):
61-
v.setdefault('llm_fields.llm_gen_config_path',
62-
'code/llama2-70b/tensorrt/generation_config.json')
53+
# Remove llm_fields line if not an LLM model
54+
if not any(x in mlc_model.lower() for x in ["llama"]):
55+
content = "\n".join(
56+
[line for line in content.splitlines() if "llm_fields.llm_gen_config_path" not in line]
57+
)
6358

64-
# --- Write modified config to destination ---
6559
with open(dest_file, "w") as f:
66-
f.write("# Auto-generated config\n\n")
67-
f.write("EXPORTS = ")
68-
f.write(repr(EXPORTS))
69-
f.write("\n")
60+
f.write(content)
7061

7162
return {'return': 0}

0 commit comments

Comments
 (0)