Skip to content

Commit 64f0d0a

Browse files
authored
Isolate llama.cpp GGUF conversion env to fix LlamaForCausalLM resolution
1 parent 1c30753 commit 64f0d0a

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

.github/workflows/llama_cpp_tests.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,27 @@ jobs:
4646
repository: ggml-org/llama.cpp
4747
path: llama.cpp
4848

49-
- name: Install llama.cpp conversion requirements
50-
run: pip install -r llama.cpp/requirements/requirements-convert_hf_to_gguf.txt
51-
52-
# The conversion requirements pin a specific torch version (e.g.
53-
# torch==2.11.0), which downgrades the torch installed above. Any
54-
# torchaudio/torchvision left over from a previous torch build is then
55-
# compiled against the wrong torch and raises at import time. transformers
56-
# imports torchaudio lazily, so the mismatch surfaces as
57-
# "ModuleNotFoundError: Could not import module 'LlamaForCausalLM'".
58-
# Removing them avoids the mismatch (this test only needs torch).
59-
- name: Uninstall torchaudio and torchvision to avoid torch mismatch
60-
run: pip uninstall -y torchaudio torchvision 2>/dev/null || true
49+
# The conversion requirements pin specific torch/transformers/numpy
50+
# versions (e.g. torch==2.11.0, transformers==4.57.6, numpy~=1.26.4) that
51+
# conflict with the versions modelbuilder and onnxruntime-genai rely on.
52+
# Installing them into the main environment downgrades that stack and
53+
# breaks AutoModelForCausalLM resolution (the test then fails with
54+
# "Could not find LlamaForCausalLM neither in ... nor in ..."). To keep
55+
# the two stacks fully decoupled we install the conversion requirements
56+
# in a dedicated virtual environment and point the test at it through
57+
# LLAMA_CPP_CONVERT_PYTHON.
58+
- name: Create isolated environment for the GGUF conversion
59+
run: |
60+
python -m venv "${{ github.workspace }}/.gguf-venv"
61+
"${{ github.workspace }}/.gguf-venv/bin/python" -m pip install --upgrade pip
62+
"${{ github.workspace }}/.gguf-venv/bin/python" -m pip install -r llama.cpp/requirements/requirements-convert_hf_to_gguf.txt
6163
6264
- name: Run llama.cpp vs onnxruntime-genai tests
6365
env:
6466
HF_TOKEN: ${{ secrets.HF_TOKEN || secrets.HUGGING_FACE_HUB_TOKEN }}
6567
HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN || secrets.HF_TOKEN }}
6668
LLAMA_CPP_DIR: ${{ github.workspace }}/llama.cpp
69+
LLAMA_CPP_CONVERT_PYTHON: ${{ github.workspace }}/.gguf-venv/bin/python
6770
run: LONGTEST=1 pytest tests/fast_llama_cpp -v --cov=modelbuilder --cov-report=xml --cov-report=term-missing
6871

6972
- name: Upload coverage to Codecov

tests/fast_llama_cpp/test_llama_cpp_tiny_llm.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,16 @@ def _build_random_tiny_llm(self, model_dir):
4343
return tokenizer, config
4444

4545
def _convert_to_gguf(self, convert_script, model_dir, gguf_path):
46-
"""Converts a Hugging Face checkpoint to a float32 GGUF file."""
47-
subprocess.run([sys.executable, convert_script, model_dir, "--outfile", gguf_path, "--outtype", "f32"], check=True)
46+
"""Converts a Hugging Face checkpoint to a float32 GGUF file.
47+
48+
``convert_hf_to_gguf.py`` pins ``torch``/``transformers``/``numpy`` to
49+
versions that conflict with the ones modelbuilder and
50+
onnxruntime-genai rely on. ``LLAMA_CPP_CONVERT_PYTHON`` lets the caller
51+
run the conversion with a dedicated interpreter (e.g. an isolated
52+
virtual environment) so those pins never pollute the test environment.
53+
"""
54+
python = os.environ.get("LLAMA_CPP_CONVERT_PYTHON", sys.executable)
55+
subprocess.run([python, convert_script, model_dir, "--outfile", gguf_path, "--outtype", "f32"], check=True)
4856
self.assertExists(gguf_path)
4957

5058
def _llama_cpp_tokens(self, gguf_path, prompt_ids, max_new_tokens):

0 commit comments

Comments
 (0)