kempnerforge.config.vision¶
Vision-encoder configuration.
VisionEncoderConfig selects and parameterizes the vision encoder
that the VLMWrapper composes alongside the text backbone and
adapter. It is a top-level section in TOML ([vision_encoder]),
sibling to [model], [adapter], and [vlm].
Field summary:
typeselects the encoder by registry key (seeregistry.register_vision_encoder). Defaults to"random"for tests; production configs set"siglip2"/"clip"etc.pathis the HF Hub id or local path passed to the encoder builder. Empty string is accepted for stub encoders ("random");JobConfig.validaterefuses it for the HF-backed"siglip2"and"clip".feature_dimis the output feature dim of the encoder.0means “infer from the encoder at build time”; an HF-backed encoder reads its model config’shidden_size, and its build raises when that is missing, asking forfeature_dim.num_tokensis the number of image tokens the encoder produces per image.0means “infer at build time”. When> 0it is cross- checked againstmodel.max_seq_lenat config time insideJobConfig.__post_init__.mixed_precisionis the dtype the encoder computes in ("bf16"or"fp32"), independent oftrain.mixed_precision, for image and video runs alike, also under thetorch.autocastthattrain.fp32_master_weightsruns without an FSDP2 wrap. Its parameters, gradients and optimizer state keep the dtype the encoder was loaded in, on any number of GPUs. Its floating-point buffers are cast to the set dtype, so a checkpoint holds them in it. Unset, the encoder keeps the default: an FSDP2-wrapped encoder computes in the language model’s dtype, and an unwrapped one in its loaded dtype, with that autocast reaching its matmuls where it runs. It applies to the training build (build_parallel_model);build_vlm_wrapperleaves every dtype to its caller.grad_reduce_dtypeis the dtype FSDP2 reduces the encoder’s gradients in ("fp32", the default, or"bf16"), set apart fromtrain.grad_reduce_dtypeand frommixed_precision: a bf16 reduce of an encoder that computes in fp32 rounds its gradients to bf16 for the reduce only. With"bf16"the encoder’s unit syncs on every micro-step (seekempnerforge.training.grad.maybe_no_sync), so gradients are accumulated and stepped in the encoder’s parameter dtype either way."bf16"is refused where the encoder is not FSDP2-wrapped: byJobConfig.validatewithout a data-parallel mesh, and at build when no step of the run trains it.drop_pooling_headremoves a SigLIP tower’s attention-pooling head, which HF runs for a pooled output the encoder never returns. Only an encoder whose builder declares adrop_pooling_headparameter takes it (siglip2); any other type is refused here. A checkpoint saved with the head loads into a model built without it, since the head’s tensors are not requested; one saved without the head does not load into a model that has it.
Classes
Configuration for the vision encoder component of a VLM. |
- class kempnerforge.config.vision.VisionEncoderConfig[source]¶
Bases:
objectConfiguration for the vision encoder component of a VLM.
drop_pooling_headremoves a SigLIP tower’s attention-pooling head, whose pooled output the encoder never returns; the encoder’s builder must declare it.- property compute_dtype: torch.dtype | None¶
The dtype the encoder computes in, or
Nonewhenmixed_precisionis unset.
- property reduce_dtype: torch.dtype¶
Dtype FSDP2 reduces the encoder’s gradients in.
- __init__(type='random', path='', feature_dim=0, num_tokens=0, mixed_precision=None, grad_reduce_dtype='fp32', drop_pooling_head=False)¶