Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions utils/model_ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ uv sync --group models-ops

The driver scripts require an NVIDIA GPU, so install a CUDA-enabled build of
PyTorch separately. The exact index URL depends on your CUDA version (replace
`cu128` with the build that matches your driver, e.g. `cu121`, `cu124`):
`cu130` with the build that matches your driver, e.g. `cu121`, `cu124`):

```
uv pip install --upgrade torch --index-url https://download.pytorch.org/whl/cu128
uv pip install --upgrade --force-reinstall "torch==2.13.0+cu130" --index-url https://download.pytorch.org/whl/cu130
uv pip install mistral_common[opencv]
```

Then change directory into `utils/models_ops/` to run the drivers (the absolute
Expand Down
2 changes: 1 addition & 1 deletion utils/model_ops/models/ministral3_14b/run_huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main():
model = Mistral3ForConditionalGeneration.from_pretrained(
model_path,
device_map=device,
torch_dtype=torch.float16,
torch_dtype=torch.bfloat16,
trust_remote_code=False,
)
tokenizer = MistralCommonBackend.from_pretrained(model_path)
Expand Down
78 changes: 78 additions & 0 deletions utils/model_ops/models/qwen25/run_huggingface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2026 The Torch-Spyre Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, StaticCache
from utils.torchop_yaml import TorchOpCollector, require_cuda, setup_logging


def main():
setup_logging()
require_cuda()

model_path = "Qwen/Qwen2.5-7B-Instruct"
prompt = "Give me a short introduction to large language model."
messages = [
{
"role": "system",
"content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant.",
},
{"role": "user", "content": prompt},
]

device = "cuda"
model = AutoModelForCausalLM.from_pretrained(
model_path, device_map="auto", dtype=torch.bfloat16
).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_path)
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
encoded_input = tokenizer(text, return_tensors="pt").to(device)

past_key_values = StaticCache(config=model.config, max_cache_len=2048)

torch.backends.cuda.enable_flash_sdp(False)
torch.backends.cuda.enable_mem_efficient_sdp(False)
torch.backends.cuda.enable_math_sdp(True)

model.forward = torch.compile(model.forward)

with TorchOpCollector() as ctx:
with torch.no_grad():
model.generate(
**encoded_input,
past_key_values=past_key_values,
use_cache=True,
max_new_tokens=16,
)

# print traced torch op
for op in ctx.ops_list:
print(op)
print(f"Total ops traced: {len(ctx.ops_list)}")

# List of ops with generated test cases
print("List of ops with test cases generated")
for op in ctx.test_gen_ops:
print(op, ctx.test_case_count[op])
print(f"Total ops with test configs generated: {len(ctx.test_gen_ops)}")

ctx.write_yaml(os.path.basename(model_path))


if __name__ == "__main__":
main()
Loading