-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for mamba and mamba2. Tests are marked xfail because they yield 'AssertionError: Attempt to trace forbidden callable <function mark_static_address at 0x744a0d11d3a0>' error. However, the tests generate a graph.
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
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
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,59 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Reference: https://huggingface.co/state-spaces/mamba-2.8b-hf | ||
|
||
from transformers import MambaForCausalLM, AutoTokenizer, GenerationConfig | ||
import pytest | ||
from tests.utils import ModelTester | ||
import torch | ||
|
||
|
||
class ThisTester(ModelTester): | ||
def _load_model(self): | ||
model = MambaForCausalLM.from_pretrained( | ||
self.model_name, torch_dtype=torch.bfloat16 | ||
) | ||
self.tokenizer = AutoTokenizer.from_pretrained( | ||
self.model_name, torch_dtype=torch.bfloat16 | ||
) | ||
return model.generate | ||
|
||
def _load_inputs(self): | ||
prompt = "Hey how are you doing?" | ||
input_ids = self.tokenizer(prompt, return_tensors="pt")["input_ids"] | ||
generation_config = GenerationConfig(max_new_tokens=10) | ||
arguments = {"input_ids": input_ids, "generation_config": generation_config} | ||
return arguments | ||
|
||
def set_model_eval(self, model): | ||
return model | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mode", | ||
["eval"], | ||
) | ||
@pytest.mark.parametrize( | ||
"model_name", | ||
[ | ||
"state-spaces/mamba-790m-hf", | ||
"state-spaces/mamba-2.8b-hf", | ||
"state-spaces/mamba-1.4b-hf", | ||
"state-spaces/mamba-370m-hf", | ||
], | ||
) | ||
@pytest.mark.xfail( | ||
reason="Fails due to 'Attempt to trace forbidden callable', but we can still generate a graph" | ||
) | ||
def test_mamba(record_property, mode, model_name): | ||
record_property("model_name", model_name) | ||
record_property("mode", mode) | ||
|
||
tester = ThisTester(model_name, mode) | ||
results = tester.test_model() | ||
if mode == "eval": | ||
gen_text = tester.tokenizer.batch_decode(results) | ||
print("Generated text: ", gen_text) | ||
|
||
record_property("torch_ttnn", (tester, results)) |