Fix duplicate custom op registration error when adding new operations#2
Draft
Fix duplicate custom op registration error when adding new operations#2
Conversation
Co-authored-by: izhuhaoran <43847754+izhuhaoran@users.noreply.github.com>
…direct_register_custom_op Co-authored-by: izhuhaoran <43847754+izhuhaoran@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] 我在vllm/attention/layer.py这个文件下添加了:
def creat_attn_output_buffer(
output_shape: torch.Size,
device: torch.device,
dtype: torch.dtype,
need_init: bool,
) -> torch.Tensor:
if need_init:
# Avoid output con...
Fix duplicate custom op registration error when adding new operations
Sep 22, 2025
izhuhaoran
pushed a commit
that referenced
this pull request
Oct 13, 2025
…ect#26445) Signed-off-by: Nick Hill <nhill@redhat.com>
izhuhaoran
pushed a commit
that referenced
this pull request
Jan 28, 2026
…3058) Signed-off-by: ramos <49182011+nemoramo@users.noreply.github.com> Signed-off-by: mayufeng <mayufeng@example.com> Co-authored-by: mayufeng <mayufeng@example.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users encountered a
RuntimeErrorwhen adding new custom operations to vLLM modules:This error occurred when users added new custom operations like:
The issue was that adding new custom operations could trigger module re-imports in complex scenarios, causing existing operations to be registered multiple times, which PyTorch's library system doesn't allow.
Solution
1. Graceful Duplicate Registration Handling
Modified
direct_register_custom_opinvllm/utils/__init__.pyto handle duplicate registrations gracefully:2. Type Annotation Compatibility
Fixed type annotation issues in custom function signatures. Changed
torch.Sizetotorch.Tensorastorch.Sizeis not compatible with PyTorch's schema inference system:Benefits
Testing
Added comprehensive tests that validate:
This fix resolves the registration conflicts that prevented users from extending vLLM with custom operations.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.