Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ jobs:
tests/models/stable_diffusion/test_stable_diffusion_transformer.py::test_stable_diffusion_transformer[full-SD3.5-large-transformer-eval]
tests/models/detr/test_detr_onnx.py::test_detr_onnx[full-eval]
tests/models/centernet/test_centernet_onnx.py::test_centernet_onnx[full-eval]
tests/models/phi/test_phi_3p5_moe.py::test_phi[full-phi3p5_moe-eval]
"
},
# This test group needs to be moved. This will be done once multichip tests are refactored: #780
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/run-op-by-op-model-tests-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ jobs:
tests/models/d_fine/test_d_fine.py::test_d_fine[op_by_op_torch-dfine-xlarge-eval]
"
},
{
runs-on: wormhole_b0, name: "phi3p5_moe", tests: "
tests/models/phi/test_phi_3p5_moe.py::test_phi[op_by_op_torch-phi3p5_moe-eval]
"
}
]
runs-on:
- ${{ matrix.build.sh-run && format('tt-beta-ubuntu-2204-{0}-large-stable', matrix.build.runs-on) || matrix.build.runs-on }}
Expand Down
105 changes: 105 additions & 0 deletions tests/models/phi/test_phi_3p5_moe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC
#
# SPDX-License-Identifier: Apache-2.0
# Phi-3.5-MoE-instruct: https://huggingface.co/microsoft/Phi-3.5-MoE-instruct

import torch
import pytest

from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
from tests.utils import ModelTester, skip_full_eval_test
from tt_torch.tools.utils import CompilerConfig, CompileDepth, OpByOpBackend


class ThisTester(ModelTester):
def _load_model(self):

self.tokenizer = AutoTokenizer.from_pretrained(
self.model_name, torch_dtype=torch.bfloat16
)

self.model = AutoModelForCausalLM.from_pretrained(
self.model_name,
return_dict=True,
torch_dtype=torch.bfloat16,
)
pipe = pipeline(
"text-generation",
model=self.model,
tokenizer=self.tokenizer,
torch_dtype=torch.bfloat16,
pad_token_id=self.tokenizer.eos_token_id,
)
return pipe

def _load_inputs(self):
self.prompt = """
Write a short story about a cat:
"""
arguments = {
"text_inputs": self.prompt,
"max_new_tokens": 120,
"do_sample": True,
}
return arguments


model_info_list = [
("phi3p5_moe", "microsoft/Phi-3.5-MoE-instruct"),
]


@pytest.mark.parametrize(
"mode",
["eval"],
)
@pytest.mark.parametrize(
"model_info",
model_info_list,
ids=[model_info[0] for model_info in model_info_list],
)
@pytest.mark.parametrize(
"op_by_op",
[OpByOpBackend.STABLEHLO, OpByOpBackend.TORCH, None],
ids=["op_by_op_stablehlo", "op_by_op_torch", "full"],
)
def test_phi(record_property, model_info, mode, op_by_op):
model_group = "red"
__, model_name = model_info
cc = CompilerConfig()
cc.enable_consteval = True
# consteval_parameters is disabled because it results in a memory related crash

if op_by_op:
cc.compile_depth = CompileDepth.EXECUTE_OP_BY_OP
if op_by_op == OpByOpBackend.STABLEHLO:
cc.op_by_op_backend = OpByOpBackend.STABLEHLO

skip_full_eval_test(
record_property,
cc,
model_name,
bringup_status="FAILED_FE_COMPILATION",
reason="failed to legalize operation 'stablehlo.reduce'",
)

tester = ThisTester(
model_name,
mode,
compiler_config=cc,
record_property_handle=record_property,
model_group=model_group,
)

results = tester.test_model()

if mode == "eval":
decoded_output = results[0]["generated_text"]
print(
f"""
model_name: {model_name}
input: {tester.prompt}
output: {decoded_output}
"""
)
tester.finalize()