[TF FE] Use Convert instead of ConvertLike for Slice stop#36209
Open
evkotov wants to merge 1 commit into
Open
Conversation
The TF/TFLite Slice translator builds the absolute `stop` as
Select(Less(size, 0), ConvertLike(ShapeOf(data), size), Add(start, size)).
v8::Slice resolves `stop` through value-bounds propagation
(evaluate_both_bounds), not constant folding. ConvertLike implements only
constant_fold, not evaluate_lower/upper, so the bound walk breaks at
ConvertLike before reaching Select, and the Slice output is left dynamic even
when the data shape and start/size are fully static. This trips downstream
consumers that require a static shape.
Build the negative-size branch with v0::Convert (to size's element type)
instead of v1::ConvertLike. Convert is value-identical here but already
implements bound evaluation, so bounds propagate through the whole cascade:
Select resolves its statically-false condition and Slice infers a static
output during validate_and_infer_types(), with no folding pass. This also
makes the size = -1 ("to end") case static whenever the data shape is static.
Add a TF frontend regression test (slice_static_shape.pbtxt) that converts a
static-input Slice without MOC and asserts the Slice output stays static.
mvafin
reviewed
Jun 3, 2026
| // resolve `stop` and keep the output static when the data shape is static. | ||
| Output<Node> stop_neg = make_shared<v3::ShapeOf>(input); | ||
| stop_neg = make_shared<v1::ConvertLike>(stop_neg, size); | ||
| stop_neg = make_shared<v0::Convert>(stop_neg, size.get_element_type()); |
Contributor
There was a problem hiding this comment.
That is not good, because size is input to operation, it can be dynamic and can have dynamic type, that is why ConvertLike was used here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details:
The TF/TFLite Slice translator builds the absolute
stopasSelect(Less(size, 0), ConvertLike(ShapeOf(data), size), Add(start, size)).v8::Slice resolves
stopthrough value-bound propagation (evaluate_both_bounds),not constant folding. ConvertLike implements only
constant_fold, notevaluate_lower/evaluate_upper, so the bound walk breaks at ConvertLike beforereaching Select. As a result the Slice output stays dynamic even when the data
shape and start/size are static. This later trips consumers that need a static
shape (e.g. read_model fed into NPUW: "to_shape was called on a dynamic shape").
Build the negative-size branch with
v0::Convert(to size's element type)instead of
v1::ConvertLike. Convert is value-identical here but alreadyimplements bound evaluation, so bounds propagate through the cascade: Select
resolves its statically-false condition and Slice infers a static output during
validate_and_infer_types(), with no folding pass. This also makes thesize = -1case static when the data shape is static.Add a TF frontend test that converts a static-input Slice without MOC and checks
the Slice output stays static.
Tickets: