DebertaV2 fix for running with large batches#846
Open
vrdn-23 wants to merge 1 commit intohuggingface:mainfrom
Open
DebertaV2 fix for running with large batches#846vrdn-23 wants to merge 1 commit intohuggingface:mainfrom
vrdn-23 wants to merge 1 commit intohuggingface:mainfrom
Conversation
Contributor
Author
|
The load test I ran to replicate this. It is easy to see the error from main when running this |
Contributor
|
@vrdn-23 How is this not caught during warmup? Isn't that what warmup is for? |
Contributor
Author
|
I think it's cause warmup always creates batches of same size and this particular branch of the code for padding/masking only gets activated when we have batches of unequal length. I think it might also be helpful to have the warmup run for batches of same size (which is max size to ensure GPU has memory) and unequal sizes (to help check padding issues). Or I don't know if that is overkill. Any thoughts @michaelfeil ? |
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.
What does this PR do?
Fix shape mismatch in DeBERTa v2 embeddings mask during batched inference
Problem
DeBERTa v2 models fail with a
shape mismatch in broadcast_mulerror under concurrent load when requests get batched together (batch_size > 1 with padding).{ "level": "ERROR", "message": "shape mismatch in broadcast_mul, lhs: [2, 348, 768], rhs: [2, 348, 1, 1]" }At 50 concurrent users, 91% of requests fail with this error. Single requests always succeed because they bypass the padding/masking path.
Root Cause
In
DebertaV2Embeddings::forward, the mask reshape guard at line 179 compared shape values instead of rank (number of dimensions):When
batch_size > 1with padding, the attention mask is created as[B, L, 1](3D) and embeddings are[B, L, H](3D). Same rank, different values. The condition incorrectly evaluates totrue, causing an unnecessaryunsqueeze(2)that produces a 4D tensor[B, L, 1, 1]which cannot broadcast with the 3D embeddings[B, L, H].This only affects DeBERTa v2 — no other model applies a mask inside the embeddings layer.
Fix
Compare tensor rank instead of shape values:
A 3D mask
[B, L, 1]already broadcasts correctly with[B, L, H]. The reshape block is only needed when the mask has a different number of dimensions (e.g., 2D[B, L]→ needsunsqueezeto become[B, L, 1]).Verification
Load tested with k6 ramping to 50 concurrent users:
Before submitting
instasnapshots?Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@alvarobartt @kozistr