{"record":{"id":"9036312f54bc1ff4","repo":"headroomlabs-ai/headroom","slug":"answerdotai-modernbert-base","errorCode":null,"errorMessage":"answerdotai/ModernBERT-base","messagePattern":"answerdotai/ModernBERT-base","errorType":"exception","errorClass":"KompressModelNotCached","httpStatus":null,"severity":"error","filePath":"headroom/transforms/kompress_compressor.py","lineNumber":767,"sourceCode":"    \"\"\"Load the ModernBERT tokenizer, cache-only when ``allow_download`` is False.\n\n    Always tries the local cache FIRST, even when downloading is allowed. With\n    ``local_files_only=False`` transformers re-validates against the Hub on every\n    load — a tree listing plus a HEAD per tokenizer file — even when the repo is\n    fully cached. MEASURED ~900ms warm-cache versus ~150ms local-only, i.e. ~750ms\n    of pure network round-trip on every process start, and it is also what makes\n    a cold start slow on a bad network rather than merely offline.\n\n    Same files, same tokenizer, so the loaded object is identical; this only\n    changes whether the Hub is consulted to confirm what is already on disk.\n    Mirrors ``onnx_runtime.hf_hub_download_local_first``, which the ONNX half of\n    this loader already uses.\n    \"\"\"\n    try:\n        return auto_tokenizer.from_pretrained(\"answerdotai/ModernBERT-base\", local_files_only=True)\n    except _NOT_CACHED_ERRORS as exc:\n        if not allow_download:\n            raise KompressModelNotCached(\"answerdotai/ModernBERT-base\") from exc\n    # Genuine cache miss and downloading is permitted: fetch it.\n    return auto_tokenizer.from_pretrained(\"answerdotai/ModernBERT-base\", local_files_only=False)\n\n\n# Sub-state-dict keys inside a merged v2-style checkpoint (see\n# scripts/export_kompress_v2_onnx.py, which this mirrors).\n_MERGED_CHECKPOINT_KEYS = (\"encoder_state_dict\", \"token_head_state_dict\", \"span_conv_state_dict\")\n\n\ndef _load_merged_state_dict(model: Any, ckpt_path: str, model_id: str) -> None:\n    \"\"\"Load a merged v2-style checkpoint (LoRA already folded into the encoder).\n\n    The checkpoint is a dict of per-submodule state-dicts\n    (``encoder_state_dict`` / ``token_head_state_dict`` / ``span_conv_state_dict``)\n    rather than a single flat state-dict, so each piece is loaded into its\n    matching submodule directly instead of via a single ``load_state_dict``\n    call on the whole model.\n    \"\"\"","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/transforms/kompress_compressor.py#L749-L785","documentation":"This is KompressModelNotCached(\"answerdotai/ModernBERT-base\") raised while loading the tokenizer: the shim tries transformers' auto_tokenizer.from_pretrained(..., local_files_only=True), catches the not-cached error class, and when allow_download=False refuses to hit the network, raising this RuntimeError instead. The tokenizer is hardcoded to the ModernBERT-base repo because it pairs with the Kompress ONNX/PyTorch artifacts.","triggerScenarios":"Loading Kompress in cache-only mode (allow_download=False) on a machine whose HF cache has the model weights but not the answerdotai/ModernBERT-base tokenizer files (or a completely cold cache).","commonSituations":"Offline deployments that cached the ONNX model via a different tool but never fetched the tokenizer; partial caches from interrupted downloads; containers built from a weights-only cache mount.","solutions":["Warm the tokenizer cache once with network allowed: huggingface-cli download answerdotai/ModernBERT-base (or run one load with allow_download=True).","Catch KompressModelNotCached and defer Kompress, falling back to a non-neural compressor.","Include the tokenizer files in the baked HF cache image alongside the model artifacts."],"exampleFix":"# before\nload_kompress_model(model_id, allow_download=False)  # tokenizer not cached -> raises\n\n# after (deploy step)\n# huggingface-cli download answerdotai/ModernBERT-base --local-dir $HF_HOME/hub/...\ntry:\n    load_kompress_model(model_id, allow_download=False)\nexcept KompressModelNotCached:\n    use_fallback_compressor()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    load_kompress_model(model_id, allow_download=False)\nexcept KompressModelNotCached:\n    use_fallback_compressor()  # tokenizer not cached; defer to a warm-up window","preventionTips":["Cache the tokenizer repo (answerdotai/ModernBERT-base) alongside model weights in deploy images.","Run one network-enabled load per environment to populate the full cache.","Handle KompressModelNotCached uniformly: it covers both weights and tokenizer cache misses."],"tags":["tokenizer","cache","offline","huggingface","transformers"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}