Skip to content

Simplify slice expressions at concretization#511

Draft
jacobhinkle wants to merge 16 commits intomainfrom
dynamic_slice
Draft

Simplify slice expressions at concretization#511
jacobhinkle wants to merge 16 commits intomainfrom
dynamic_slice

Conversation

@jacobhinkle
Copy link
Collaborator

@jacobhinkle jacobhinkle commented Jun 22, 2023

As discussed in #460 and #439, start & stop arguments to slice must be normalized, resulting in complicated branching expressions. In this PR, we make slices dynamic and decide the branches for these expressions at concretization, which lets us simplify the expressions. In some special cases this also lets us replace the slice with a set or full (for empty tensors).

NOTE: since #460 uses proper expressions for slice ranges, the original unnormalized expressions can be hard to find. This PR will need to either carefully unwrap those expressions or attach the original expressions to the SliceOp for the purposes of determining the slice concretization branches.

Fixes #439. Fixes #52.

Should use id->extent()->isConstInt() instead.
This is in lieu of replacing all uses of symbolic extents, which cannot
be done reliably since they might appear as attributes or members of
objects which are untracked. See #420
This lets us process ops in topological order instead of doing all
reshapes followed by all slices etc. This is very helpful since we need
to evaluate vals that are not defined until their upstream ops are
concretized.
Previously we concretized all reshapes then all slices then all resizes.
This failed the FusionSliceForNanoGPT3_CUDA test which has the
slice->reshape->slice->reshape pattern, since we were concretizing
reshapes that had inputs which were not yet concretized and which
actually needed to be replaced. Since concretization of slices and
reshapes can actually replace a TensorView, we need to ensure that those
are done in the correct order.
This will remove more trivial slices, but means we trigger a recompile
between x[0:m] and x[1:m].
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.

Slice should clip to end of tensor slice corner case: Index range at runtime that is beyond a tensor does not return a zero-element tensor

1 participant