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

AdapterConfig

Selects the adapter type and parameterizes it.

class kempnerforge.config.adapter.AdapterConfig[source]

Bases: object

Selects 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”. For avgpool, a positive value replaces the single Linear after the pool with a 2-layer MLP head ([pre_norm ->] Linear(in_dim, hidden_dim) -> activation -> Linear(hidden_dim, out_dim)), and 0 keeps the Linear.

activation: Activation between the two MLP projections. One of

"gelu" (default), "silu", "relu". Used by mlp_2layer, and by avgpool when hidden_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 by mlp_2layer over the vision features, and by avgpool over the pooled features when hidden_dim > 0.

pool_window: Pooling kernel side for the pooling adapters (e.g. 2

for image 2×2, 3 for 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 ValueError naming 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. accepts in registry.register_adapter overrides that, and an adapter whose builder reads any other ** parameter and declares nothing accepts every field.

type: str = 'mlp_2layer'
hidden_dim: int = 0
activation: str = 'gelu'
pre_norm: str = ''
pool_window: int = 2
pool_heads: int = 16
extra_kwargs()[source]

Builder kwargs beyond in_dim / out_dim.

hidden_dim=0 maps to None, which each adapter reads as its own default (out_dim wide for MLP2LayerAdapter, no MLP head for AvgPoolAdapter). 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).

Return type:

dict[str, Any]

output_num_tokens(num_input_tokens)[source]

Predict the post-adapter token count for num_input_tokens in.

Mirrors the built module’s output_num_tokens so config-time sequence-length checks match the build-time/runtime token budget. Projection adapters are the identity; pooling adapters apply the shared pooled_token_count math. Non-positive inputs (e.g. the num_tokens=0 “infer at build time” sentinel) pass through.

Parameters:

num_input_tokens (int)

Return type:

int

__init__(type='mlp_2layer', hidden_dim=0, activation='gelu', pre_norm='', pool_window=2, pool_heads=16)
Parameters:
  • type (str)

  • hidden_dim (int)

  • activation (str)

  • pre_norm (str)

  • pool_window (int)

  • pool_heads (int)

Return type:

None