Skip to content

vllm.model_executor.models.transformers.pooling

Transformers modeling backend mixins for pooling models.

Classes:

ClassifierWithReshape

Bases: Module

Token extraction has already been applied in pooler.pooling.

Add dim to match expected input shape of classifier.forward, and remove it again if the classifier is applied at every position (e.g. LayoutLMv3's).

Source code in vllm/model_executor/models/transformers/pooling.py
class ClassifierWithReshape(nn.Module):
    """Token extraction has already been applied in `pooler.pooling`.

    Add dim to match expected input shape of `classifier.forward`, and remove it
    again if the classifier is applied at every position (e.g. LayoutLMv3's).
    """

    def forward(self, *args, **kwargs):
        if len(args) > 0:
            args = (args[0].unsqueeze(1), *args[1:])
        output = super().forward(*args, **kwargs)
        return output.squeeze(1) if output.dim() == 3 else output