-
Notifications
You must be signed in to change notification settings - Fork 381
Limit forward_backward queue drain size #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
j316chuck
wants to merge
5
commits into
NovaSky-AI:main
from
j316chuck:chuck/forward-backward-batch-limit
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f307961
Limit forward_backward queue drain size
j316chuck b2caedb
Make forward_backward repro hit real service
j316chuck d393a39
Perturb forward_backward repro lengths
j316chuck 771fbea
Correct forward_backward repro mechanism
j316chuck fb4ba2e
Fix capped forward-backward microbatch padding
j316chuck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| """Reproduce the forward_backward queue shape that can create oversized batches. | ||
|
|
||
| This script is intentionally synthetic: it does not allocate tensors or require a | ||
| GPU. It models a client submitting many pending FORWARD_BACKWARD requests with | ||
| uneven sequence lengths, then compares the single-drain behavior with the | ||
| request-count limited behavior. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| REQUEST_COUNT = 47 | ||
| EXAMPLE_COUNT = 63 | ||
| MAX_SEQUENCE_LENGTH = 147_472 | ||
| TOTAL_INPUT_TOKENS = 5_153_654 | ||
| OBSERVED_CUDA_ALLOCATION_GIB = 40.02 | ||
| FORWARD_BACKWARD_MAX_REQUEST_COUNT = 4 | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ForwardBackwardRequest: | ||
| request_id: int | ||
| sequence_lengths: list[int] | ||
|
|
||
|
|
||
| def build_repro_requests() -> list[ForwardBackwardRequest]: | ||
| other_token_budget = TOTAL_INPUT_TOKENS - MAX_SEQUENCE_LENGTH | ||
| other_lengths = [other_token_budget // (EXAMPLE_COUNT - 1)] * (EXAMPLE_COUNT - 1) | ||
| for index in range(other_token_budget % (EXAMPLE_COUNT - 1)): | ||
| other_lengths[index] += 1 | ||
|
|
||
| example_lengths = [MAX_SEQUENCE_LENGTH, *other_lengths] | ||
| requests = [] | ||
| cursor = 0 | ||
| for request_id in range(1, REQUEST_COUNT + 1): | ||
| examples_in_request = 2 if request_id <= EXAMPLE_COUNT - REQUEST_COUNT else 1 | ||
| requests.append( | ||
| ForwardBackwardRequest( | ||
| request_id=request_id, | ||
| sequence_lengths=example_lengths[cursor : cursor + examples_in_request], | ||
| ) | ||
| ) | ||
| cursor += examples_in_request | ||
| return requests | ||
|
|
||
|
|
||
| def chunk_by_request_count( | ||
| requests: list[ForwardBackwardRequest], max_request_count: int | ||
| ) -> list[list[ForwardBackwardRequest]]: | ||
| return [requests[start : start + max_request_count] for start in range(0, len(requests), max_request_count)] | ||
|
|
||
|
|
||
| def summarize_batch(batch: list[ForwardBackwardRequest]) -> tuple[int, int, int, int]: | ||
| lengths = [length for request in batch for length in request.sequence_lengths] | ||
| request_count = len(batch) | ||
| example_count = len(lengths) | ||
| max_sequence_length = max(lengths) | ||
| input_tokens = sum(lengths) | ||
| return request_count, example_count, max_sequence_length, input_tokens | ||
|
|
||
|
|
||
| def print_batch(label: str, batch: list[ForwardBackwardRequest]) -> None: | ||
| request_count, example_count, max_sequence_length, input_tokens = summarize_batch(batch) | ||
| print( | ||
| f"{label}: requests={request_count}, examples={example_count}, " | ||
| f"max_sequence_length={max_sequence_length:,}, input_tokens={input_tokens:,}" | ||
| ) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| requests = build_repro_requests() | ||
|
|
||
| print("Client submits pending FORWARD_BACKWARD requests with uneven sequence lengths.") | ||
| print_batch("single queue drain before limiting", requests) | ||
| print(f"observed failure symptom: CUDA OOM while trying to allocate {OBSERVED_CUDA_ALLOCATION_GIB:.2f} GiB") | ||
| print() | ||
|
|
||
| chunks = chunk_by_request_count(requests, FORWARD_BACKWARD_MAX_REQUEST_COUNT) | ||
| print( | ||
| "with forward_backward_max_request_count=" f"{FORWARD_BACKWARD_MAX_REQUEST_COUNT}: {len(chunks)} backend calls" | ||
| ) | ||
| for index, chunk in enumerate(chunks, start=1): | ||
| print_batch(f"chunk {index:02d}", chunk) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent silent configuration errors where a user might accidentally configure a non-positive value (e.g.,
0or a negative integer) and experience unexpected CUDA OOMs due to the engine falling back to unlimited batching, we should enforce thatforward_backward_max_request_countis strictly greater than zero using Pydantic'sgt=0validation.