-
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.
Added tests for HF BART base and large model variant with a language modeling head on top.
- Loading branch information
Showing
6 changed files
with
123 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,40 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
from infra import RunMode | ||
|
||
from ..tester import FlaxBartForCausalLMTester | ||
|
||
MODEL_PATH = "facebook/bart-base" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> FlaxBartForCausalLMTester: | ||
return FlaxBartForCausalLMTester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> FlaxBartForCausalLMTester: | ||
return FlaxBartForCausalLMTester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.xfail(reason="failed to legalize operation 'stablehlo.reduce'") | ||
def test_flax_bart_base_inference( | ||
inference_tester: FlaxBartForCausalLMTester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_bart_base_training( | ||
training_tester: FlaxBartForCausalLMTester, | ||
): | ||
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 FlaxBartForCausalLMTester | ||
|
||
MODEL_PATH = "facebook/bart-large" | ||
|
||
|
||
# ----- Fixtures ----- | ||
|
||
|
||
@pytest.fixture | ||
def inference_tester() -> FlaxBartForCausalLMTester: | ||
return FlaxBartForCausalLMTester(MODEL_PATH) | ||
|
||
|
||
@pytest.fixture | ||
def training_tester() -> FlaxBartForCausalLMTester: | ||
return FlaxBartForCausalLMTester(MODEL_PATH, RunMode.TRAINING) | ||
|
||
|
||
# ----- Tests ----- | ||
|
||
|
||
@pytest.mark.xfail(reason="failed to legalize operation 'stablehlo.reduce'") | ||
def test_flax_bart_large_inference( | ||
inference_tester: FlaxBartForCausalLMTester, | ||
): | ||
inference_tester.test() | ||
|
||
|
||
@pytest.mark.skip(reason="Support for training not implemented") | ||
def test_flax_bart_large_training( | ||
training_tester: FlaxBartForCausalLMTester, | ||
): | ||
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,43 @@ | ||
# 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 ComparisonConfig, ModelTester, RunMode | ||
from transformers import AutoTokenizer, FlaxBartForCausalLM | ||
|
||
|
||
class FlaxBartForCausalLMTester(ModelTester): | ||
"""Tester for BART model variants with a language modeling head on top.""" | ||
|
||
# TODO(mrakita): Add tests for other variants. | ||
|
||
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 FlaxBartForCausalLM.from_pretrained(self._model_name, from_pt=True) | ||
|
||
# @override | ||
def _get_input_activations(self) -> Sequence[jax.Array]: | ||
tokenizer = AutoTokenizer.from_pretrained(self._model_name) | ||
inputs = tokenizer("Hello", 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(), | ||
} |