Skip to content

fix: normalize slice bounds after view functionalization - #44

Merged
frlai merged 4 commits into
feature/view-mutation-functionalizationfrom
fix/functionalized-slice-bounds
Oct 22, 2026
Merged

frlai merged 4 commits into
feature/view-mutation-functionalizationfrom
fix/functionalized-slice-bounds

Conversation

@frlai

@frlai frlai commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

After mutation functionalization, Python slices become ATen slices and enter LEAPP's slice-to-narrow rewrite. The rewrite currently uses raw bounds: on six elements, x[-3:], x[2:100], and x[4:2] produce invalid narrow lengths instead of the expected suffix, clipped slice, and empty result.

Normalize unit-step bounds against the runtime dimension size before calling torch.narrow: translate negative bounds, clip to [0, size], and make the length nonnegative. Preserve slice_copy allocation independence, including whole-axis copies. A scripted helper retains runtime size arithmetic under legacy tracing. Functionalization, the slice helpers, and the ATen rewrite pass live in leapp/leapp_graph/aten_rewrites.py; TracedTensorNode controls when the passes run. The separate functionalization.py module is removed. rewrite_aten_ops owns traversal, operator identification, applicability checks, and dispatch; module-level helpers perform the selected graph edits. Adding a rewrite means adding its helper and an explicit dispatch branch.

This is a stacked draft targeting feature/view-mutation-functionalization (PR #33), addressing #33 (comment). The independent-buffer copy_ aliasing issue remains separate.

Validation:

  • PyTorch 2.14: affected Torch, NumPy, view-mutation, and conversion suites — 408 tests and 1,742 subtests passed.
  • Minimum PyTorch 2.7.0: complete view-mutation suite — 49 tests passed.
  • Torch and NumPy mutation/slice capture replayed on changed inputs through reloaded TorchScript, PT2, and ONNX artifacts.
  • Internal graph unit checks execute slice/slice_copy rewrites directly, plus scripting and tracing at dimension sizes 0, 1, 3, 6, 11, and 101; copied outputs remain independent. Direct FX graph execution is unit coverage, not a supported LEAPP export backend.
  • Variable-width PT2 and ONNX artifacts reloaded and checked at widths 8, 11, 12, 20, and 32 within the declared 8–32 range. Symbolic export still requires a shape range accepted by PyTorch; this does not introduce LEAPP dynamic-shape annotations.
  • Before/after dispatch probes matched graph structure across 27 cases, with executable results also compared for 24 cases; the remaining three check copy-option guards and Warp skip behavior.
  • Ruff 0.17.1 formatting and git diff --check passed.

frlai added 4 commits October 22, 2026 02:14
Signed-off-by: Frank Lai <frlai@nvidia.com>
Signed-off-by: Frank Lai <frlai@nvidia.com>
Signed-off-by: Frank Lai <frlai@nvidia.com>
Signed-off-by: Frank Lai <frlai@nvidia.com>
@frlai
frlai marked this pull request as ready for review October 22, 2026 09:36
@frlai
frlai merged commit 914d27a into feature/view-mutation-functionalization Oct 22, 2026
5 checks passed
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