interlens.loading.load¶
interlens.loading.load
¶
derive_chat_flags
¶
Probe a tokenizer's chat template to derive (supports_system_role, requires_alternating_roles).
supports_system_role is True iff the template renders a leading system turn without raising;
requires_alternating_roles is True iff the template rejects two consecutive same-role turns. Each probe is
wrapped in try/except so a raising template simply reads as the corresponding boolean. This replaces per-family
flag declarations: an unknown model gets correct chat behavior with zero configuration.
Source code in src/interlens/loading/load.py
load_model
¶
load_model(
id_or_path: str | Path,
device: str | device = "cuda",
dtype: dtype = torch.bfloat16,
attn: str = "flash_attention_2",
quant: str | None = None,
revision: str | None = None,
)
Load a causal LM + tokenizer, sharing through the process-local caches.
id_or_path is the HF id or a local path to load directly (a Path is normalized to str so it shares
the same cache slot as its string form). Identical (hf_id, device, dtype, attn, quant) pairings share the one
model object, and the tokenizer is cached by hf_id. Flash-attention is the default with automatic fallback to
sdpa/eager; quantization is opt-in.
Source code in src/interlens/loading/load.py
load_tokenizer
¶
Load a tokenizer for hf_id (or a local path), defaulting pad_token to eos_token when absent —
the single source of the pad-token convention, shared by load_model and AutoModelParticipant when it
has to infer a tokenizer from a bare model.