-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63ab780
commit 4ad89ea
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import pytest | ||
import torch | ||
from loguru import logger | ||
from transformers import AutoTokenizer, Phi3Config, Phi3ForCausalLM | ||
|
||
import forge | ||
|
||
from test.models.utils import Framework, Source, Task, build_module_name | ||
|
||
variants = ["microsoft/Phi-3-medium-128k-instruct"] | ||
|
||
|
||
@pytest.mark.parametrize("variant", variants) | ||
def test_phi3_causal_lm(variant): | ||
config = Phi3Config.from_pretrained(variant) | ||
config_dict = config.to_dict() | ||
config_dict["return_dict"] = False | ||
config_dict["use_cache"] = False | ||
config = Phi3Config(**config_dict) | ||
tokenizer = AutoTokenizer.from_pretrained(variant) | ||
framework_model = Phi3ForCausalLM.from_pretrained(variant, config=config).to("cpu") | ||
framework_model.eval() | ||
input_prompt = "Africa is an emerging economy because" | ||
inputs = tokenizer(input_prompt, return_tensors="pt").to("cpu") | ||
with torch.no_grad(): | ||
op = framework_model(inputs["input_ids"], inputs["attention_mask"]) | ||
logger.info(f"op={op}") | ||
module_name = build_module_name(variant, Source.HUGGINGFACE, Framework.PYTORCH, Task.CAUSAL_LM) | ||
compiled_model = forge.compile(framework_model, [inputs["input_ids"], inputs["attention_mask"]], module_name) |