Skip to content

Preserve nonempty categorical vocabulary bounds during compilation - #1260

Merged
aw471 merged 3 commits into
mainfrom
compile-tabular-align-value-routing
Oct 23, 2026
Merged

aw471 merged 3 commits into
mainfrom
compile-tabular-align-value-routing

Conversation

@aw471

@aw471 aw471 commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Record that a nonempty input column produces at least one unique category. This lets torch.compile resolve subsequent empty-vocabulary checks without changing category values or codes.

Description of the change

Encountered during raw-label preparation for compiled KumoTabular fitting. This localized reproduction isolates the same empty-vocabulary check used by AlignCategories (CPU, PyTorch 2.14):

import torch
from sdm import CategoricalTensor
from sdm.tensor.categorical import _iter_categories

def prepare(labels):
    categorical = CategoricalTensor.from_tensor(labels)
    for category in _iter_categories(categorical):
        if category.numel() == 0:
            return category
    return categorical.code

torch.compile(prepare, backend="inductor", fullgraph=True)(
    torch.tensor([[0], [1], [0]])
)
torch._dynamo.exc.UserError:
Could not guard on data-dependent expression Eq(u0, 0)
Caused by: if category.numel() == 0

unique() already compiles, but its learned output size can appear to be zero. Four added lines use torch._check to tell the compiler each vocabulary is nonempty when the input is nonempty. Empty rows and columns retain their existing behavior. This fixes this bound only; other KumoTabular fitting blockers remain.

Validation

  • Reproducer fails before and passes after the fix with Inductor and fullgraph=True.
  • Six strict CPU cases passed: regular, all-NaN, empty rows, empty columns, batched and strided inputs; one graph and zero breaks each.
  • Existing categorical checks: 84 passed, 24 skipped; applicable pre-commit checks passed.

@copy-pr-bot

copy-pr-bot Bot commented Oct 23, 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.

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1260   +/-   ##
=======================================
  Coverage   82.91%   82.91%           
=======================================
  Files         173      173           
  Lines       11191    11194    +3     
=======================================
+ Hits         9279     9282    +3     
  Misses       1912     1912           

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

@aw471
aw471 force-pushed the compile-tabular-align-value-routing branch from d01d0ea to 24b0bc8 Compare October 23, 2026 01:42
@aw471 aw471 changed the title Prototype compiled value-category alignment Preserve nonempty categorical vocabulary bounds during compilation Oct 23, 2026
@aw471
aw471 changed the base branch from compile-tabular-shuffle-strict to main October 23, 2026 01:42
@aw471
aw471 marked this pull request as ready for review October 23, 2026 01:42
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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 567e527 and b58d1bd.

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

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Categorical tensor conversion now checks that each generated category vector contains at least one category when the input has elements. Empty inputs remain supported and are not subject to this check. This validation helps identify invalid empty category vectors during conversion.

CategoricalTensor.from_tensor checks that generated category vectors are nonempty when the input tensor has at least one element. Empty inputs bypass the check.

Changes: Categorical tensor validation

Layer / File(s) Summary
Check generated category vectors
sdm/tensor/categorical.py
When the input tensor has elements, from_tensor checks that each generated category vector contains at least one value. Empty inputs skip this check.

Priority: ➖ Normal

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

Merge Risk: ⚪ Minimal · up to b58d1

No actionable merge-blocking risk was found in this change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving nonempty categorical vocabulary bounds during compilation.
Description check Passed The description directly explains the compilation issue, the torch._check fix, preserved empty-input behavior, and validation results.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
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.
✨ 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

Comment @coderabbitai help to get the list of available commands.

@aw471
aw471 merged commit e6f62d5 into main Oct 23, 2026
7 checks passed
@aw471
aw471 deleted the compile-tabular-align-value-routing branch October 23, 2026 03:35
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