Skip to main content

Module encoder_weights

Module encoder_weights 

Source
Expand description

Encoder-model configuration: config.json → the declarative fields the encoder executor branches on.

The “any embedding model” contract: the executor never matches on EncArch — only on PosKind, NormKind, MlpKind, MaskKind, the per-layer layer_window, and the Pooling mode. Supporting a new encoder architecture is therefore (1) one EncArch variant + one from_json arm mapping its HF config keys onto these fields, and (2) one tensor-name table in the weight loader. Anything a config asks for that the fields cannot express is refused loudly at parse time — never silently mis-computed.

Structs§

EncBatch
A ragged batch of token sequences: tokens is every sequence concatenated, seq_starts (length B+1) delimits them. No padding exists anywhere — attention masking is exact by construction because kernels iterate seq_starts[s]..seq_starts[s+1].
EncoderConfig
Encoder hyper-parameters — the declarative surface the executor and loaders consume.
RelAttn
DeBERTa’s disentangled (relative) attention. On top of the usual content→content term, the score gains a content→position (c2p) and a position→content (p2c) term, both indexed by a LOG-BUCKETED relative distance:
SiglipVisionSpec
Vision-tower spec: the declarative config plus the patch geometry the preprocessing needs.

Enums§

Act
Activation function (shared by the GEMM epilogue and the GLU split kernel).
EncArch
Which encoder architecture the checkpoint is (drives tensor names at load; NOT executor logic).
MaskKind
Attention mask mode.
MlpKind
Feed-forward block shape.
NormKind
Normalization operator.
PosKind
Position-information scheme.

Functions§

encoder_arch
Map an HF architectures[0] name to its encoder family, if it is one.
encoder_config_from_dir
Resolve a checkpoint DIRECTORY to an encoder configuration: encoder architectures parse via EncoderConfig::from_json (the pooling marker, when present, overrides the per-arch default); decoder architectures are accepted only with an explicit embedder marker — Qwen3ForCausalLM + pooling_mode_lasttoken is Qwen3-Embedding. Everything else refuses loudly: a generation checkpoint must never be silently embedded.
pooling_marker
Read the sentence-transformers pooling marker (1_Pooling/config.json) from a checkpoint directory, if present. This is the data-driven signal that turns a decoder-architecture checkpoint (e.g. Qwen3-Embedding, whose config.json says Qwen3ForCausalLM) into an EMBEDDER — no per-model special-casing.
siglip_configs_from_dir
Detect a SigLIP checkpoint directory (joint text+vision config.json; architectures may be absent — model_type: "siglip"/"siglip2" is the signal) and return both tower configs.
siglip_text_config
Build the SigLIP TEXT-tower config from the joint config.json (HF SiglipConfig defaults apply when the sub-config omits keys — verified against google/siglip2-base-patch16-224). Text tower: learned positions (offset 0, no embedding-stage norm), biased pre-LN layers, final_layer_norm, last-token pooling followed by the head projection. NOTE the canonical SigLIP text tower attends WITHOUT a padding mask — the adapter pads to max_pos and the final (padded) position is the pooled token, exactly as trained.
siglip_vision_config
Build the SigLIP VISION-tower config: 2D patch embedding (image_size/patch_size(image/patch)² positions), learned per-patch positions, biased pre-LN layers, post_layernorm, MAP attention-pooling head.