Skip to content

Commit

Permalink
make tensorflow be optional for unittest (#394)
Browse files Browse the repository at this point in the history
* make tensorflow be optional for unitest.

* typo
  • Loading branch information
wenbingl authored Apr 12, 2023
1 parent b5dce95 commit 2202e3e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ requires = ["setuptools", "wheel", "numpy>=1.18.5", "cmake"] # PEP 508 specific

[tool.black]
line-length = 120

[tool.ruff]
line-length = 120
5 changes: 3 additions & 2 deletions test/test_audio_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def test_mp3_decoder(self):
pcm_tensor = self.decoder(np.expand_dims(np.asarray(blob), axis=(0,)))
self.assertTrue(pcm_tensor.shape[1] > len(blob))
# lossy compression, so we can only check the range
np.testing.assert_allclose(np.asarray([np.max(pcm_tensor), np.average(pcm_tensor), np.min(pcm_tensor)]),
np.asarray([np.max(self.raw_data), np.average(self.raw_data), np.min(self.raw_data)]), atol=1e-01)
np.testing.assert_allclose(
np.asarray([np.max(pcm_tensor), np.average(pcm_tensor), np.min(pcm_tensor)]),
np.asarray([np.max(self.raw_data), np.average(self.raw_data), np.min(self.raw_data)]), atol=1e-01)


if __name__ == "__main__":
Expand Down
14 changes: 12 additions & 2 deletions test/test_sentencepiece_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
OrtPyFunction,
make_onnx_model,
get_library_path as _get_library_path)
import tensorflow as tf
from tensorflow_text import SentencepieceTokenizer


_is_tensorflow_avaliable = False
try:
import tensorflow as tf
from tensorflow_text import SentencepieceTokenizer
_is_tensorflow_avaliable = True
except ImportError:
pass


def load_piece(name):
Expand Down Expand Up @@ -235,6 +242,7 @@ def _create_test_model_ragged_to_dense(
return model


@unittest.skipIf(not _is_tensorflow_avaliable, "tensorflow/tensorflow-text is unavailable")
class TestPythonOpSentencePiece(unittest.TestCase):

@classmethod
Expand Down Expand Up @@ -430,6 +438,8 @@ def test_string_sentencepiece_tokenizer_bin(self):
assert_almost_equal(exp[i], py_txout[i])
assert_almost_equal(exp[i], cc_txout[i])


class TestOrtXSentencePiece(unittest.TestCase):
def test_external_pretrained_model(self):
fullname = util.get_test_data_file('data', 'en.wiki.bpe.vs100000.model')
ofunc = OrtPyFunction.from_customop('SentencepieceTokenizer', model=open(fullname, 'rb').read())
Expand Down
3 changes: 2 additions & 1 deletion tutorials/whisper_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def postprocessing(token_ids, hf_processor):
model_name = "openai/whisper-base.en"
onnx_model_name = "whisper-base.en_beamsearch.onnx"
if not Path(onnx_model_name).is_file():
raise RuntimeError("Please run the script from where Whisper ONNX model was exported. like */onnx_models/openai")
raise RuntimeError(
"Please run the script from where Whisper ONNX model was exported. like */onnx_models/openai")

_processor = WhisperProcessor.from_pretrained(model_name)
if USE_ONNX_COREMODEL:
Expand Down

0 comments on commit 2202e3e

Please sign in to comment.