Skip to content

Fix a bug in aliaser for pipelines with concat + slice - #851

Open
vksnk wants to merge 1 commit into
mainfrom
vksnk/multi-aliasing
Open

Fix a bug in aliaser for pipelines with concat + slice#851
vksnk wants to merge 1 commit into
mainfrom
vksnk/multi-aliasing

Conversation

@vksnk

@vksnk vksnk commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

The test is created by AI based on the internal pipeline which was failing for me, it's a little convoluted and I tried to simplify it further, but without much success.

@vksnk
vksnk requested a review from dsharlet July 2, 2026 05:18
@vksnk

vksnk commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

I asked AI agent to try to narrow the initial condition I had and it came up with this:

"The narrowing experiment turned into a root-cause revision. Blocking on !alias.assume_in_bounds (write-side only) initially failed cannot_alias — but the failing IR showed the read-side slice views were generated correctly and then destroyed later: simplify rewrites an offset-0 slice view into a crop_buffer, and crop_needed() (simplify.cc:2114) drops crops that are only call inputs. Kernels that read input extents (reductions, dot k-dims, the test's combine3) then see the full packed buffer → OOB. Offset slices survive only because offset views aren't crop-expressible. With deps.buffer_input added to crop_needed, the narrowed guard passes everything — and notably, the guard fully removed still passes all of slinky (but breaks ynn attention with NaN, so the write-side block is genuinely needed).

One thing for the discussion: the crop_needed change touches slinky's implicit contract that call inputs "may be larger than requested" — ynnpack kernels already violate that contract wherever they read reduction extents from inputs, so I'd argue the fix is right, but it deserves a discussion."

I think it makes sense, what do you think?

@dsharlet

dsharlet commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Hmm, I wonder if this last thing might clear up the first:

ynnpack kernels already violate that contract wherever they read reduction extents from inputs, so I'd argue the fix is right, but it deserves a discussion.

Didn't we fix that? I think we read reduction bounds from the reduction description, which is an output buffer, not an input.

@vksnk

vksnk commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

it might be not exactly correct in details, but I think simplifier does lose some crops necessary for slices.

Regardless, it's a real bug and we can submit a wider "fix" I had initially, if you think it's better/safer (or maybe you have some other suggestions).

@vksnk
vksnk force-pushed the vksnk/multi-aliasing branch from e0d70af to 8002e0b Compare July 6, 2026 18:30
@vksnk

vksnk commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

I reverted the change to the simplifier, but the condition is wider now. PTAL.

pc.store_outputs_innermost();
slice_a.store_outputs_innermost();
slice_b.store_outputs_innermost();
slice_c.store_outputs_innermost();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I've been thinking about what to do about this, this is a brutal test to have in the repo IMO.

I think a better test would be to implement a new example for the attention operator, like we have for softmax, that actually implements the op, instead of an abstract reproducer. What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm fine with that, but it still will need to have some specific schedule to hit the bug.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes that's OK, I commented in the wrong place. My thinking is, it will be easier to understand the test/pipeline if it is a concrete thing, instead of an abstract pipeline, even if it is the same operation as this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I started to look into it and realized that in order to reproduce it the attention isn't enough, we need tiled attention and even there we need to replicate the schedule and maybe some strides/extents to reproduce it. It kind of seems like it's going to be even more complicated, so I'm not sure now.

@dsharlet

Copy link
Copy Markdown
Owner

I wonder where we are at with this after some other recent fixes to concat related issues? Is this still needed?

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.

2 participants