"""Make NOOSPHERE reachable from the offline ``LLM`` API, not only from serving. The mechanism this checkpoint is named for hangs off the multimodal processor: ``LomonosovZenitAltayMultiModalProcessor._cached_apply_hf_processor`` is where the additive contract is applied. The model's renderer deliberately routes even text-only prompts through that processor - that is why the renderer exists. But the renderer belongs to vLLM's serving stack. The offline ``LLM`` API goes through ``InputPreprocessor._process_tokens``, which reads: if multi_modal_data := parsed_content.get("multi_modal_data"): inputs = self._process_multimodal(...) else: inputs = tokens_input(prompt_token_ids) So a text-only ``TokensPrompt`` skips the processor entirely, and NOOSPHERE never runs. Measured, not inferred: a 1,005,334-token retention run with ``ZENIT_NOOSPHERE_MODE=auto`` scored 0/14 in 1293.4 s, against 0/14 in 1295.7 s with the mode forced to ``raw`` - the same score and the same time to within two tenths of a per cent, and no receipt emitted in either. That is a defect, not a design choice: most scripts and every benchmark harness use the offline API, and they were silently getting a different model from the one a served endpoint gives. This wrapper closes the gap for this architecture only, and leaves every other model on vLLM's own path. """ from __future__ import annotations from typing import Any REPAIR_ID = "ZENIT_OFFLINE_NOOSPHERE_PATH_V1" ARCHITECTURE_ID = "LomonosovZenitAltayForConditionalGeneration" def _logger(): from vllm.logger import init_logger return init_logger("vllm.lomonosov_zenit_altay.offline_path") def _is_our_model(preprocessor: Any) -> bool: """True only for this architecture, so no other model changes behaviour.""" model_config = getattr(preprocessor, "model_config", None) architectures = getattr(model_config, "architectures", None) or [] if ARCHITECTURE_ID in architectures: return True # Older vLLM builds expose a single resolved architecture instead. return getattr(model_config, "architecture", None) == ARCHITECTURE_ID def install_offline_noosphere_path() -> bool: """Route text-only token prompts through the multimodal processor.""" from vllm.inputs.preprocess import InputPreprocessor if getattr(InputPreprocessor, "_zenit_offline_noosphere_path", False): return False original = InputPreprocessor._process_tokens def patched(self, parsed_content, tokenization_kwargs=None): if parsed_content.get("multi_modal_data") or not _is_our_model(self): return original(self, parsed_content, tokenization_kwargs) try: prompt_token_ids = self._truncate_inputs( parsed_content["prompt_token_ids"], tokenization_kwargs ) inputs = self._process_multimodal( prompt_token_ids, {}, parsed_content.get("mm_processor_kwargs"), tokenization_kwargs=tokenization_kwargs, mm_uuids=parsed_content.get("multi_modal_uuids"), ) except Exception: # noqa: BLE001 - never fail a request over this _logger().exception( "%s: falling back to vLLM's own token path", REPAIR_ID ) return original(self, parsed_content, tokenization_kwargs) if prompt_text := parsed_content.get("prompt"): inputs["prompt"] = prompt_text if cache_salt := parsed_content.get("cache_salt"): inputs["cache_salt"] = cache_salt return inputs InputPreprocessor._process_tokens = patched InputPreprocessor._zenit_offline_noosphere_path = True return True __all__ = ["ARCHITECTURE_ID", "REPAIR_ID", "install_offline_noosphere_path"]