-
Notifications
You must be signed in to change notification settings - Fork 3
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
d960be9
commit 3f4a9e7
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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,42 @@ | ||
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import FlaxBertForMaskedLMTester | ||
|
||
MODEL_PATH = "google-bert/bert-base-uncased" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> FlaxBertForMaskedLMTester: | ||
return FlaxBertForMaskedLMTester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> FlaxBertForMaskedLMTester: | ||
return FlaxBertForMaskedLMTester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.xfail( | ||
reason="Cannot get the device from a tensor with host storage (https://github.com/tenstorrent/tt-xla/issues/171)" | ||
) | ||
def test_flax_bert_base_inference( | ||
inference_tester: FlaxBertForMaskedLMTester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_bert_base_training( | ||
training_tester: FlaxBertForMaskedLMTester, | ||
): | ||
training_tester.test() |
Empty file.
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,42 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import FlaxBertForMaskedLMTester | ||
|
||
MODEL_PATH = "google-bert/bert-large-uncased" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> FlaxBertForMaskedLMTester: | ||
return FlaxBertForMaskedLMTester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> FlaxBertForMaskedLMTester: | ||
return FlaxBertForMaskedLMTester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.xfail( | ||
reason="Cannot get the device from a tensor with host storage (https://github.com/tenstorrent/tt-xla/issues/171)" | ||
) | ||
def test_flax_bert_large_inference( | ||
inference_tester: FlaxBertForMaskedLMTester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_bert_large_training( | ||
training_tester: FlaxBertForMaskedLMTester, | ||
): | ||
training_tester.test() |
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,41 @@ | ||
# SPDX-FileCopyrightText: (c) 2025 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import Dict, Sequence | ||
|
||
import jax | ||
from flax import linen as nn | ||
from infra import ComparisonConfig, ModelTester, RunMode | ||
from transformers import AutoTokenizer, FlaxBertForMaskedLM | ||
|
||
|
||
class FlaxBertForMaskedLMTester(ModelTester): | ||
"""Tester for BERT model variants on masked language modeling task.""" | ||
|
||
def __init__( | ||
self, | ||
model_name: str, | ||
comparison_config: ComparisonConfig = ComparisonConfig(), | ||
run_mode: RunMode = RunMode.INFERENCE, | ||
) -> None: | ||
self._model_name = model_name | ||
super().__init__(comparison_config, run_mode) | ||
|
||
# @override | ||
def _get_model(self) -> nn.Module: | ||
return FlaxBertForMaskedLM.from_pretrained(self._model_name) | ||
|
||
# @override | ||
def _get_input_activations(self) -> Sequence[jax.Array]: | ||
tokenizer = AutoTokenizer.from_pretrained(self._model_name) | ||
inputs = tokenizer("Hello [MASK]", return_tensors="np") | ||
return inputs["input_ids"] | ||
|
||
# @override | ||
def _get_forward_method_kwargs(self) -> Dict[str, jax.Array]: | ||
assert hasattr(self._model, "params") | ||
return { | ||
"params": self._model.params, | ||
"input_ids": self._get_input_activations(), | ||
} |