-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial batch of JAX model tests (#129)
- Loading branch information
1 parent
02f0440
commit 51d5799
Showing
26 changed files
with
627 additions
and
70 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
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
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
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,41 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import AlbertV2Tester | ||
|
||
|
||
MODEL_PATH = "albert/albert-base-v2" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.skip(reason="failed to legalize operation 'stablehlo.dot_general'") | ||
def test_flax_albert_v2_base_inference( | ||
inference_tester: AlbertV2Tester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_albert_v2_base_training( | ||
training_tester: AlbertV2Tester, | ||
): | ||
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,40 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import AlbertV2Tester | ||
|
||
MODEL_PATH = "albert/albert-large-v2" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.skip(reason="failed to legalize operation 'stablehlo.dot_general'") | ||
def test_flax_albert_v2_large_inference( | ||
inference_tester: AlbertV2Tester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_albert_v2_large_training( | ||
training_tester: AlbertV2Tester, | ||
): | ||
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,48 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 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 ModelTester, RunMode, ComparisonConfig | ||
from transformers import AutoTokenizer, FlaxAlbertForMaskedLM | ||
|
||
|
||
class AlbertV2Tester(ModelTester): | ||
"""Tester for Albert model on a 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 FlaxAlbertForMaskedLM.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(), | ||
} | ||
|
||
# @ override | ||
def _get_static_argnames(self): | ||
return ["train"] | ||
|
||
|
||
# TODO(stefan): Add testers for Albert when used as a question answering or sentiment analysis model. |
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,40 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import AlbertV2Tester | ||
|
||
MODEL_PATH = "albert/albert-xlarge-v2" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.skip(reason="failed to legalize operation 'stablehlo.dot_general'") | ||
def test_flax_albert_v2_xlarge_inference( | ||
inference_tester: AlbertV2Tester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_albert_v2_xlarge_training( | ||
training_tester: AlbertV2Tester, | ||
): | ||
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,40 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import AlbertV2Tester | ||
|
||
MODEL_PATH = "albert/albert-xxlarge-v2" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> AlbertV2Tester: | ||
return AlbertV2Tester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.skip(reason="failed to legalize operation 'stablehlo.dot_general'") | ||
def test_flax_albert_v2_xxlarge_inference( | ||
inference_tester: AlbertV2Tester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_albert_v2_xxlarge_training( | ||
training_tester: AlbertV2Tester, | ||
): | ||
training_tester.test() |
Oops, something went wrong.