MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / test_model_unload

Function test_model_unload

python/tests/test_translator.py:751–765  ·  view source on GitHub ↗
(to_cpu)

Source from the content-addressed store, hash-verified

749
750@pytest.mark.parametrize("to_cpu", [False, True])
751def test_model_unload(to_cpu):
752 batch = [["آ", "ت", "ز", "م", "و", "ن"]]
753 translator = _get_transliterator()
754 translator.unload_model(to_cpu=to_cpu)
755 if not to_cpu:
756 assert not translator.model_is_loaded
757 with pytest.raises(RuntimeError, match="unloaded"):
758 translator.translate_batch(batch)
759 else:
760 assert translator.model_is_loaded
761 translator.load_model()
762 assert translator.model_is_loaded
763 output = translator.translate_batch(batch)
764 assert len(output) == 1
765 assert output[0].hypotheses[0] == ["a", "t", "z", "m", "o", "n"]
766
767
768def test_model_unload_while_async_translation():

Callers

nothing calls this directly

Calls 4

_get_transliteratorFunction · 0.85
unload_modelMethod · 0.80
translate_batchMethod · 0.45
load_modelMethod · 0.45

Tested by

no test coverage detected