# SPDX-License-Identifier: Apache-2.0 """Host tests of the server-start configuration (COMPILE-TIME surface) and the model constants.""" import pytest from tt_embgemma import config as C from tt_embgemma import model_spec as S def test_defaults(): c = C.resolve_config({}) assert c.modalities == ("text", "image", "video", "audio") assert (c.max_batch, c.max_seq_len, c.image_tokens_max) == (32, 2048, 280) assert c.text_buckets == (32, 64, 128, 256, 512, 1024, 2048) and c.long_buckets == (1024, 2048) assert c.vision_buckets == (864, 1440, 2592) assert c.audio_buckets == (512, 1024, 2048, 3072) assert c.max_images == 64 and c.text_engine == "ttnn" assert not hasattr(c, "vision_engine") and not hasattr(c, "audio_engine") def test_overrides(): c = C.resolve_config({"EMBGEMMA_MODALITIES": "audio,text", "EMBGEMMA_MAX_SEQ_LEN": "512", "EMBGEMMA_IMAGE_TOKENS_MAX": "1120", "EMBGEMMA_DEFAULT_PROMPT": "SearchQuery", "EMBGEMMA_TEXT_BUCKETS": "64,32,512"}) assert c.modalities == ("text", "audio") assert c.max_seq_len == 512 and c.long_buckets == () and c.text_buckets == (32, 64, 512) assert c.vision_buckets == (864, 1440, 2592, 5184, 10368) assert c.default_prompt == "SearchQuery" c = C.resolve_config({"EMBGEMMA_MAX_SEQ_LEN": "8192"}) assert max(c.long_buckets) == 8192 and max(c.text_buckets) == 8192 @pytest.mark.parametrize("env", [ {"EMBGEMMA_MODALITIES": "text,smell"}, {"EMBGEMMA_MAX_BATCH": "33"}, {"EMBGEMMA_MAX_SEQ_LEN": "9000"}, {"EMBGEMMA_IMAGE_TOKENS_MAX": "300"}, {"EMBGEMMA_TEXT_BUCKETS": "33"}, {"EMBGEMMA_AUDIO_BUCKETS": "100"}, {"EMBGEMMA_FIDELITY": "LoFi"}, {"EMBGEMMA_WEIGHTS": "fp8"}, {"EMBGEMMA_TRACE": "maybe"}, {"EMBGEMMA_MAX_SEQ_LEN": "4096", "EMBGEMMA_LONG_BUCKETS": "1024"}, {"EMBGEMMA_VISION_ENGINE": "cpu"}, {"EMBGEMMA_AUDIO_ENGINE": "ttnn"}, # every stage follows TEXT_ENGINE {"EMBGEMMA_WEIGHTS": "bfp8"}, {"EMBGEMMA_MAX_IMAGES": "0"}, ]) def test_refusals(env): with pytest.raises(ValueError): C.resolve_config(env) def test_audio_tokens(): assert S.audio_tokens_for_samples(16000) == 25 assert S.audio_tokens_for_samples(480000) == 750 assert S.audio_tokens_for_samples(10 ** 7) == 750 assert S.audio_tokens_for_samples(100) == 0 def test_server_import_has_no_device_side_effects(): import sys import tt_embgemma.server.app as a assert a.app is not None and "ttnn" not in sys.modules