|
2 | 2 | from utils import * |
3 | 3 | import os |
4 | 4 | import shutil |
5 | | -import importlib.util |
6 | | -import json |
7 | 5 |
|
8 | 6 |
|
9 | 7 | def preprocess(i): |
@@ -46,26 +44,19 @@ def postprocess(i): |
46 | 44 |
|
47 | 45 | dest_file = os.path.join(target_dir, f"{mlc_model}.py") |
48 | 46 |
|
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() |
54 | 49 |
|
55 | | - EXPORTS = dummy_module.EXPORTS |
| 50 | + # Replace model name |
| 51 | + content = re.sub(r"'llama2-70b'", f"'{mlc_model}'", content) |
56 | 52 |
|
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 | + ) |
63 | 58 |
|
64 | | - # --- Write modified config to destination --- |
65 | 59 | 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) |
70 | 61 |
|
71 | 62 | return {'return': 0} |
0 commit comments