Skip to content

vllm.model_executor.models.bert_with_rope

Classes:

GteForSequenceClassification

Bases: GteNewForSequenceClassification

GteNewForSequenceClassification for LoRA adapters trained on the native Transformers GTE (model_type: gte), whose split q/k/v_proj and gate/up_proj pack into the fused layers. Checkpoint weights load as for GteNewForSequenceClassification.

Source code in vllm/model_executor/models/bert_with_rope.py
class GteForSequenceClassification(GteNewForSequenceClassification):
    """`GteNewForSequenceClassification` for LoRA adapters trained on the native
    Transformers GTE (`model_type: gte`), whose split `q/k/v_proj` and
    `gate/up_proj` pack into the fused layers. Checkpoint weights load as for
    `GteNewForSequenceClassification`."""

    packed_modules_mapping = {
        "qkv_proj": ["q_proj", "k_proj", "v_proj"],
        "up_gate_proj": ["up_proj", "gate_proj"],
    }
    hf_to_vllm_mapper = WeightsMapper(
        orig_to_new_substr={
            ".self_attn.o_proj": ".attn.out_proj",
            ".self_attn.": ".attn.",
        },
        orig_to_new_prefix={"gte.layers.": "new.encoder.layers."},
    )

GteNewMLP

Bases: Module

GTE's GeGLU MLP in the checkpoint's fused [up; gate] layout (no up_gate_proj bias), so LoRA adapters on up_gate_proj apply as trained.

Source code in vllm/model_executor/models/bert_with_rope.py
class GteNewMLP(nn.Module):
    """GTE's GeGLU MLP in the checkpoint's fused `[up; gate]` layout (no
    `up_gate_proj` bias), so LoRA adapters on `up_gate_proj` apply as trained."""

    def __init__(
        self,
        hidden_size: int,
        intermediate_size: int,
        bias: bool = True,
        quant_config: QuantizationConfig | None = None,
        prefix: str = "",
    ):
        super().__init__()
        self.act_fn = get_act_fn("gelu")
        self.up_gate_proj = MergedColumnParallelLinear(
            hidden_size,
            [intermediate_size] * 2,
            bias=False,
            quant_config=quant_config,
            prefix=f"{prefix}.up_gate_proj",
        )
        self.down_proj = RowParallelLinear(
            input_size=intermediate_size,
            output_size=hidden_size,
            bias=bias,
            quant_config=quant_config,
            prefix=f"{prefix}.down_proj",
        )

    def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
        up_gate, _ = self.up_gate_proj(hidden_states)
        up, gate = up_gate.chunk(2, dim=-1)
        hidden_states, _ = self.down_proj(self.act_fn(gate) * up)
        return hidden_states