Skip to content

Handle empty ragged copies during compilation - #1328

Merged
aw471 merged 1 commit into
mainfrom
fix/empty-varlen-copy
Nov 2, 2026
Merged

aw471 merged 1 commit into
mainfrom
fix/empty-varlen-copy

Conversation

@aw471

@aw471 aw471 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Copy empty ragged tensors without using tensor values as Python slice bounds. This removes a full-graph failure when KumoTabular casts prediction outputs.

Description of the change

An empty table text block has no payload to copy. Select an empty data slice directly, then keep the existing device/dtype transfer, offset normalization and validity handling.

Before: torch._dynamo.exc.UserError: Could not extract specialized integer from data-dependent expression u0 (unhinted: u0). (Size-like symbols: none) on PyTorch 2.14.1.

Validation

112 CPU and 8 CUDA eager/actual-Inductor cases passed on PyTorch 2.14.1, including views, validity, dtype/device copies, and empty views with 1,000,000 unused backing bytes. The result has zero payload bytes.

Combined with the other three predict fixes: pretrained KumoTabular large, default recipe, 8 estimators, 10k context / 512 queries, RTX PRO 6000, PyTorch 2.14.1+cu130 and FP16 autocast. Main and #1275 each passed three actual-Inductor fullgraph=True predictions with one graph, zero breaks/recompiles, and max probability error 1.47e-4 versus eager; predicted classes matched. This is correctness validation, not a performance benchmark.

Minimal reproducer
import torch
from sdm import StringTensor

value = StringTensor(
    data=torch.empty(0, dtype=torch.uint8),
    offset=torch.zeros(1, dtype=torch.int64),
    valid=None,
    size=(0,),
)
with torch.inference_mode():
    torch.compile(lambda x: x.to(copy=True), fullgraph=True)(value)

@copy-pr-bot

copy-pr-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@aw471

aw471 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

The author requested and pre-approved a full review of this PR.

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Full review finished.

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.39%. Comparing base (b5c3641) to head (6927739).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1328   +/-   ##
=======================================
  Coverage   82.39%   82.39%           
=======================================
  Files         185      185           
  Lines       11773    11775    +2     
=======================================
+ Hits         9700     9702    +2     
  Misses       2073     2073           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b5c3641 and 6927739.

Files selected for processing: 1
  • sdm/tensor/var_len.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where converting an empty variable-length tensor to a different data type or device could fail. Empty inputs are now handled correctly, while non-empty inputs continue to convert as expected.

_to_dtype_layout now selects an empty data slice when the input has zero elements. For non-empty inputs, it retains offset-based slicing. The selected data is still converted to the requested device and dtype.

Changes: Empty input conversion

Layer / File(s) Summary
Data slice selection
sdm/tensor/var_len.py
_to_dtype_layout selects an empty slice when inp.numel() == 0. Non-empty inputs retain offset-based slicing. The selected data is converted as before.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: Minimal · up to 69277

The change addresses empty ragged tensor conversion without introducing an actionable correctness or availability risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: supporting empty ragged tensor copies during compilation.
Description check Passed The description directly explains the empty ragged tensor compilation failure, the implementation change, and the reported validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. 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.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

@aw471
aw471 marked this pull request as ready for review November 2, 2026 23:13
@aw471
aw471 merged commit e32a878 into main Nov 2, 2026
7 checks passed
@aw471
aw471 deleted the fix/empty-varlen-copy branch November 2, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant