model: use F.scaled_dot_product_attention for ViT-family attention#548
Open
rebel-junamsong wants to merge 1 commit intomainfrom
Open
model: use F.scaled_dot_product_attention for ViT-family attention#548rebel-junamsong wants to merge 1 commit intomainfrom
rebel-junamsong wants to merge 1 commit intomainfrom
Conversation
Replace manual matmul+softmax+matmul in ViT-family vision attention
with F.scaled_dot_product_attention so the rbln-compiler lowers it
through the dedicated SDPA custom op path (mapped to the
__paged_normal_*_sdpa_{5d,6d}_ kernels) instead of the generic
relay fallback.
Affected models: Qwen2-VL, Qwen2.5-VL (full and window), Pixtral.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
Replace manual
matmul → softmax → matmulattention in ViT-family vision modules withF.scaled_dot_product_attention. This routes the op through rbln-compiler's dedicated SDPA custom-op path (mapped to__paged_normal_*_sdpa_{5d,6d}_kernels) instead of the generic relay fallback, improving numerical stability undercompDtype=bfloat.Affected models
qwen2_vl—VisionAttentionqwen2_5_vl—Qwen2_5_VLVisionFullAttention,Qwen2_5_VLVisionWindowAttentionpixtral—PixtralAttentionQwen3VLVisionAttentionalready uses SDPA. GroundingDINO variants use non-standard attention (dual-softmax / grid_sample) and are not applicable.4D vs 5D tensor rank
Each model keeps its original Q/K/V rank — no forced unification. rbln-compiler dispatches to different kernels based on rank:
[B, H, L, D]NHCW64c__paged_normal_*_sdpa_5d_[B, H, 1, L, D]NDHCW64c__paged_normal_*_sdpa_6d_The SDPA converter path in
rebel.core.custom_converter._pt_attentionhas no rank assertion, so both 4D and 5D work._5d__5d__6d__5d_Test plan