Skip to content

Commit fd1085f

Browse files
authored
model-conversion : use CONVERTED_MODEL value for converted model [no ci] (#17984)
* model-conversion : use CONVERTED_MODEL value for converted model [no ci] This commit updates the model verification scripts to use the CONVERTED_MODEL environment variable instead of using the MODEL_PATH (the original model path) as the basis for the converted model file name. The motivation for this that currently if the converted model file name differs from the original model directory/name the verification scripts will look for the wrong .bin files that were generating when running the models. For example, the following steps were not possible: ```console (venv) $ huggingface-cli download google/gemma-3-270m-it --local-dir ggml-org/gemma-3-270m (venv) $ python3 convert_hf_to_gguf.py ggml-org/gemma-3-270m --outfile test-bf16.gguf --outtype bf16 (venv) $ cd examples/model-conversion/ (venv) $ export MODEL_PATH=../../ggml-org/gemma-3-270m (venv) $ export CONVERTED_MODEL=../../test-bf16.gguf (venv) $ make causal-verify-logits ... Data saved to data/llamacpp-test-bf16.bin Data saved to data/llamacpp-test-bf16.txt Error: llama.cpp logits file not found: data/llamacpp-gemma-3-270m.bin Please run scripts/run-converted-model.sh first to generate this file. make: *** [Makefile:62: causal-verify-logits] Error 1 ``` With the changes in this commit, the above steps will now work as expected.
1 parent 380b4c9 commit fd1085f

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

examples/model-conversion/scripts/causal/compare-logits.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/usr/bin/env python3
22

3-
import numpy as np
43
import sys
5-
import os
4+
import numpy as np
65
from pathlib import Path
76

7+
# Add utils directory to path for direct script execution
8+
sys.path.insert(0, str(Path(__file__).parent.parent / "utils"))
9+
from common import get_model_name_from_env_path # type: ignore[import-not-found]
10+
811
def quick_logits_check(pytorch_file, llamacpp_file):
912
"""Lightweight sanity check before NMSE"""
1013

@@ -35,20 +38,13 @@ def quick_logits_check(pytorch_file, llamacpp_file):
3538
return True
3639

3740
def main():
38-
model_path = os.getenv('MODEL_PATH')
39-
if not model_path:
40-
print("Error: MODEL_PATH environment variable not set")
41-
sys.exit(1)
42-
43-
if not os.path.exists(model_path):
44-
print(f"Error: Model file not found: {model_path}")
45-
sys.exit(1)
46-
47-
model_name = os.path.basename(model_path)
41+
model_name = get_model_name_from_env_path('MODEL_PATH')
4842
data_dir = Path("data")
49-
5043
pytorch_file = data_dir / f"pytorch-{model_name}.bin"
51-
llamacpp_file = data_dir / f"llamacpp-{model_name}.bin"
44+
45+
llamacpp_model_name = get_model_name_from_env_path('CONVERTED_MODEL')
46+
print(f"Using converted model: {llamacpp_model_name}")
47+
llamacpp_file = data_dir / f"llamacpp-{llamacpp_model_name}.bin"
5248

5349
if not pytorch_file.exists():
5450
print(f"Error: PyTorch logits file not found: {pytorch_file}")

examples/model-conversion/scripts/utils/__init__.py

Whitespace-only changes.

examples/model-conversion/scripts/utils/check-nmse.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import argparse
77
from pathlib import Path
8+
from common import get_model_name_from_env_path # type: ignore[import-not-found]
89

910
def calculate_nmse(reference, test):
1011
mse = np.mean((test - reference) ** 2)
@@ -67,11 +68,13 @@ def main():
6768
parser.add_argument('-m', '--model-path', required=True, help='Path to the model directory')
6869
args = parser.parse_args()
6970

70-
model_name = os.path.basename(args.model_path)
71+
model_name = get_model_name_from_env_path('MODEL_PATH')
7172
data_dir = Path("data")
7273

7374
pytorch_file = data_dir / f"pytorch-{model_name}.bin"
74-
llamacpp_file = data_dir / f"llamacpp-{model_name}.bin"
75+
76+
llamacpp_model_name = get_model_name_from_env_path('CONVERTED_MODEL')
77+
llamacpp_file = data_dir / f"llamacpp-{llamacpp_model_name}.bin"
7578

7679
print(f"Model name: {model_name}")
7780
print(f"PyTorch logits file: {pytorch_file}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
6+
def get_model_name_from_env_path(env_path_name):
7+
model_path = os.getenv(env_path_name)
8+
if not model_path:
9+
print(f"Error: {env_path_name} environment variable not set")
10+
sys.exit(1)
11+
12+
if not os.path.exists(model_path):
13+
print(f"Error: Model file not found: {model_path}")
14+
sys.exit(1)
15+
16+
name = os.path.basename(os.path.normpath(model_path))
17+
if name.endswith(".gguf"):
18+
name = name[:-5]
19+
20+
return name

pyrightconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extraPaths": ["gguf-py"],
2+
"extraPaths": ["gguf-py", "examples/model-conversion/scripts"],
33
"pythonVersion": "3.9",
44
"pythonPlatform": "All",
55
"reportUnusedImport": "warning",

0 commit comments

Comments
 (0)