Skip to content

Fix slice_scatter open end - #4512

Open
jloftin-nv wants to merge 2 commits into
pytorch:mainfrom
jloftin-nv:dev-jloftin-slice-scatter
Open

Fix slice_scatter open end#4512
jloftin-nv wants to merge 2 commits into
pytorch:mainfrom
jloftin-nv:dev-jloftin-slice-scatter

Conversation

@jloftin-nv

Copy link
Copy Markdown
Contributor

Description

Export encodes open-ended slice ends as 2**63-1. The converter feeds that into np.arange / broadcast_to without clamping to the dim size, causing “array is too big” or broadcast errors.

Clamp end (and related bounds) to the input length along dim before building NumPy indices, matching aten runtime behavior.

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • [ X] My code follows the style guidelines of this project (You can use the linters)
  • [ X] I have performed a self-review of my own code
  • [ X] I have commented my code, particularly in hard-to-understand areas and hacks
  • [X ] I have made corresponding changes to the documentation
  • [X ] I have added tests to verify my fix or my feature
  • [ X] New and existing unit tests pass locally with my changes
  • [ X] I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions Bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Aug 18, 2026
@meta-cla meta-cla Bot added the cla signed label Aug 18, 2026
@github-actions
github-actions Bot requested a review from cehongwang August 18, 2026 21:53
@narendasan
narendasan requested a review from apbose August 18, 2026 22:56
@lanluo-nvidia lanluo-nvidia added this to the v2.14.0 milestone Aug 20, 2026
@jloftin-nv
jloftin-nv force-pushed the dev-jloftin-slice-scatter branch from 442b3bc to 277fcdb Compare August 20, 2026 23:32
update = torch.randn(2, 4, 13, 8)
self.run_test(module, [cache, update])

def test_full_overwrite_is_identity(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dynamic sliced dimensions remain broken. The clamp is skipped when dim_size == DYNAMIC_DIM The code then reaches np.arange(0, 2**63-1), causing compilation failure or a huge-allocation error. The existing dynamic test varies batch and other dimensions while keeping the sliced dimension fixed at 64, so it does not cover this. We should include this test

@jloftin-nv jloftin-nv Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we land dynamic support here or keep in torch and follow up?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can have it another PR. Just that we should have a validator then

@lanluo-nvidia lanluo-nvidia modified the milestones: v2.14.0, v2.15.0 Aug 22, 2026
@jloftin-nv
jloftin-nv force-pushed the dev-jloftin-slice-scatter branch from 277fcdb to 8a66bc6 Compare August 25, 2026 22:06
@github-actions github-actions Bot added the component: lowering Issues re: The lowering / preprocessing passes label Aug 25, 2026
@apbose

apbose commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

_needs_dim_size() misses a case when the dim_is_static=False . A positive literal bound slips through unchecked.

resolve_slice_scatter_write does correctly attempt to guard the dynamic-dim case:
if not dim_is_static and (_needs_dim_size(start) or _needs_dim_size(end)):
return None, None, None, KVWriteStatus.DYNAMIC_DIM_SIZE
but _needs_dim_size() only flags three of the four bound shapes that actually depend on the dim's unknown size:
repro: slice_scatter(cache, update, dim=2, start=0, end=40, step=1) where dim 2's declared dynamic range is 8 to 32

bound _needs_dim_size(bound) caught?
None True yes
negative (-4) True yes
open-end sentinel True yes
positive literal (40) False no

I think we should widen the _needs_dim_size so concrete bound on dim isnt considered safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants