You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Dynamic shapes 4/n] Skip balanced split sizing when one chunk fits - #1359
On CUDA, chunked processors fail under torch.compile with ConstraintViolationError when their row count is marked dynamic. split_size now returns the item count directly when one chunk provably holds all items.
Description of the change
On a CUDA device with gradients off, split_size balances the chunks as ceil(n / ceil(n / capacity)). For a symbolic item count n, the result is that whole expression, not n. _split_tensor then cannot prove that the tensor fits one chunk, calls Tensor.split, and PyTorch adds a guard that the expression gives one chunk. The guard is on the marked size, which contradicts the dynamic mark:
split_size now returns num_items before the arithmetic when num_items <= capacity is statically known. The balanced size equals num_items in that case anyway, so eager results are unchanged. When the count can exceed the capacity, the arithmetic runs as before.
In Kumo Tabular, ClipSigma and RankGaussian call split_size with the number of query rows during predict. On CPU split_size returns at its first line, so only CUDA is affected.
Reproduction (PyTorch 2.14.1; no GPU needed, split_size only reads the device type):
Ran the script above with TORCH_LOGS="recompiles,dynamic,graph_breaks" and the eager and inductor backends, before and after this change. Both backends give the same result (BEGIN/END lines are printed by the script):
Before: every call ends with ConstraintViolationError.
After:
BEGIN call=0 shape=(5, 3)
END call=0 graphs=1 matches_eager=True
BEGIN call=1 shape=(9, 3)
END call=1 graphs=1 matches_eager=True
BEGIN call=2 shape=(3, 3)
END call=2 graphs=1 matches_eager=True
BEGIN call=3 shape=(16, 3)
END call=3 graphs=1 matches_eager=True
On a Tesla T4, compiled Kumo Tabular predict with the query rows marked fails with this error for all 6 inputs tried without the change. With it, the error is gone.
This change avoids a torch.compile constraint error when a row count is marked dynamic, and eager results stay the same. No merge-blocking risk was found.
Architecture risk: Low · up to 0da9c
The change affects 1 system.
Changed systems:sdm
Architecture concerns
No architecture-level concerns identified.
Review details
Systems and components
observed — sdm (service) was modified; 1 changed file maps to changed impact.
Before / after behavior
observed — Modified behavior in sdm/_memory.py: split_size now returns at least 1 directly when num_items <= capacity is statically known true; otherwise, execution continues to the existing balanced-chunk calculation.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly identifies the main change: skipping balanced split sizing when one chunk can hold all items, including the dynamic-shape context.
Description check
The description directly explains the CUDA dynamic-shape failure, the split_size change, the affected callers, reproduction steps, and validation results.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between a00920e and 0da9c57.
Files selected for processing: 1
sdm/_memory.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.25%. Comparing base (df0da4c) to head (9cdea2b).
✅ All tests successful. No failed tests found.
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
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
On CUDA, chunked processors fail under
torch.compilewithConstraintViolationErrorwhen their row count is marked dynamic.split_sizenow returns the item count directly when one chunk provably holds all items.Description of the change
On a CUDA device with gradients off,
split_sizebalances the chunks asceil(n / ceil(n / capacity)). For a symbolic item countn, the result is that whole expression, notn._split_tensorthen cannot prove that the tensor fits one chunk, callsTensor.split, and PyTorch adds a guard that the expression gives one chunk. The guard is on the marked size, which contradicts the dynamic mark:split_sizenow returnsnum_itemsbefore the arithmetic whennum_items <= capacityis statically known. The balanced size equalsnum_itemsin that case anyway, so eager results are unchanged. When the count can exceed the capacity, the arithmetic runs as before.In Kumo Tabular,
ClipSigmaandRankGaussiancallsplit_sizewith the number of query rows duringpredict. On CPUsplit_sizereturns at its first line, so only CUDA is affected.Reproduction (PyTorch 2.14.1; no GPU needed,
split_sizeonly reads the device type):Validation
Ran the script above with
TORCH_LOGS="recompiles,dynamic,graph_breaks"and theeagerandinductorbackends, before and after this change. Both backends give the same result (BEGIN/ENDlines are printed by the script):Before: every call ends with
ConstraintViolationError.After:
On a Tesla T4, compiled Kumo Tabular
predictwith the query rows marked fails with this error for all 6 inputs tried without the change. With it, the error is gone.FULL_TEST=1 pytest test/processing: 451 passed.