Skip to content

Commit ed8aa63

Browse files
authored
model-conversion : pass config to from_pretrained (ggml-org#16963)
This commit modifies the script `run-org-model.py` to ensure that the model configuration is explicitly passed to the `from_pretrained` method when loading the model. It also removes a duplicate configuration loading which was a mistake. The motivation for this change is that enables the config object to be modified and then passed to the model loading function, which can be useful when testing new models.
1 parent 48bd265 commit ed8aa63

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

examples/model-conversion/scripts/causal/run-org-model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def fn(_m, input, output):
138138
"Model path must be specified either via --model-path argument or MODEL_PATH environment variable"
139139
)
140140

141+
142+
print("Loading model and tokenizer using AutoTokenizer:", model_path)
143+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
141144
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
142145

143146
print("Model type: ", config.model_type)
@@ -147,10 +150,6 @@ def fn(_m, input, output):
147150
print("BOS token id: ", config.bos_token_id)
148151
print("EOS token id: ", config.eos_token_id)
149152

150-
print("Loading model and tokenizer using AutoTokenizer:", model_path)
151-
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
152-
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
153-
154153
if unreleased_model_name:
155154
model_name_lower = unreleased_model_name.lower()
156155
unreleased_module_path = (
@@ -171,7 +170,7 @@ def fn(_m, input, output):
171170
exit(1)
172171
else:
173172
model = AutoModelForCausalLM.from_pretrained(
174-
model_path, device_map="auto", offload_folder="offload", trust_remote_code=True
173+
model_path, device_map="auto", offload_folder="offload", trust_remote_code=True, config=config
175174
)
176175

177176
for name, module in model.named_modules():

0 commit comments

Comments
 (0)