From 77e6dcbbfad8cfca6867663b164f038820f7a0be Mon Sep 17 00:00:00 2001 From: Shanshan Shen <467638484@qq.com> Date: Wed, 4 Mar 2026 11:41:27 +0800 Subject: [PATCH] [PluggableLayer][MM] Add PluggableLayer for RelPosAttention (#33753) Signed-off-by: shen-shanshan <467638484@qq.com> --- docs/design/custom_op.md | 2 ++ vllm/model_executor/models/deepencoder.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/design/custom_op.md b/docs/design/custom_op.md index 034736ec66..a62d033072 100644 --- a/docs/design/custom_op.md +++ b/docs/design/custom_op.md @@ -54,6 +54,8 @@ For example: --8<-- "vllm/model_executor/layers/attention/mm_encoder_attention.py:mm_encoder_attn" --8<-- "vllm/model_executor/layers/mla.py:multi_head_latent_attention" + +--8<-- "vllm/model_executor/models/deepencoder.py:rel_pos_attention" ``` **2. Activation:** diff --git a/vllm/model_executor/models/deepencoder.py b/vllm/model_executor/models/deepencoder.py index f7ae4264f6..68c101460d 100644 --- a/vllm/model_executor/models/deepencoder.py +++ b/vllm/model_executor/models/deepencoder.py @@ -18,6 +18,7 @@ import torch.nn as nn import torch.nn.functional as F from transformers import CLIPVisionConfig +from vllm.model_executor.custom_op import PluggableLayer from vllm.model_executor.layers.attention import MMEncoderAttention from vllm.model_executor.layers.conv import Conv2dLayer from vllm.model_executor.layers.quantization import QuantizationConfig @@ -263,9 +264,13 @@ class Block(nn.Module): return x -class RelPosAttention(nn.Module): +# --8<-- [start:rel_pos_attention] +@PluggableLayer.register("rel_pos_attention") +class RelPosAttention(PluggableLayer): """Multi-head Attention block with relative position embeddings.""" + # --8<-- [end:rel_pos_attention] + def __init__( self, dim: int,