kempnerforge.config.adapter¶
Adapter (connector) configuration.
AdapterConfig selects which adapter the VLM wrapper instantiates and
parameterizes the chosen adapter. Dispatched via the adapter registry
at build time (see kempnerforge/model/adapter.py).
In TOML, [adapter] is a top-level section parallel to [model],
[vision_encoder], and [vlm]. When [vlm] is set without an
[adapter] section, JobConfig materializes the default AdapterConfig.
Classes
Selects the adapter type and parameterizes it. |
- class kempnerforge.config.adapter.AdapterConfig[source]¶
Bases:
objectSelects the adapter type and parameterizes it.
- Fields:
- type: Registry key for the adapter builder. Projection adapters
"mlp_2layer"(default) /"linear"keep the token count; pooling adapters"avgpool"/"attentional_pool"reduce it.- hidden_dim: Hidden width of a 2-layer MLP. For
mlp_2layer,0 means “match
out_dim”. Foravgpool, a positive value replaces the singleLinearafter the pool with a 2-layer MLP head ([pre_norm ->] Linear(in_dim, hidden_dim) -> activation -> Linear(hidden_dim, out_dim)), and0keeps theLinear.- activation: Activation between the two MLP projections. One of
"gelu"(default),"silu","relu". Used bymlp_2layer, and byavgpoolwhenhidden_dim > 0.- pre_norm: Norm-registry key (
"rmsnorm"/"layernorm") for a norm ahead of the MLP’s first projection (exposed as
ln_q);""(default) builds none. Used bymlp_2layerover the vision features, and byavgpoolover the pooled features whenhidden_dim > 0.- pool_window: Pooling kernel side for the pooling adapters (e.g.
2 for image 2×2,
3for video 3×3).- pool_heads: Number of attention heads for
attentional_pool; must divide the vision feature dim.
A field the selected adapter does not use must keep its default, or construction raises
ValueErrornaming the field and the adapter type. The fields an adapter uses are the ones its builder takes as parameters that can be passed by keyword, when the builder’s**parameter is named_or it has none.acceptsinregistry.register_adapteroverrides that, and an adapter whose builder reads any other**parameter and declares nothing accepts every field.- extra_kwargs()[source]¶
Builder kwargs beyond
in_dim/out_dim.hidden_dim=0maps toNone, which each adapter reads as its own default (out_dimwide forMLP2LayerAdapter, no MLP head forAvgPoolAdapter). Every field is passed; a builder takes the ones it uses and swallows the rest via**_, which construction has checked are at their defaults unless the adapter accepts every field (see the class docstring).
- output_num_tokens(num_input_tokens)[source]¶
Predict the post-adapter token count for
num_input_tokensin.Mirrors the built module’s
output_num_tokensso config-time sequence-length checks match the build-time/runtime token budget. Projection adapters are the identity; pooling adapters apply the sharedpooled_token_countmath. Non-positive inputs (e.g. thenum_tokens=0“infer at build time” sentinel) pass through.