Skip to content

dyn_slice operator for symbolics and data-dependent operators - #5112

Open
CharlieL7 wants to merge 6 commits into
developfrom
dyn_slice_new
Open

dyn_slice operator for symbolics and data-dependent operators#5112
CharlieL7 wants to merge 6 commits into
developfrom
dyn_slice_new

Conversation

@CharlieL7

@CharlieL7 CharlieL7 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

Always called with three inputs dyn_slice(input, starts, ends).
starts and ends attribute are vector<dim_like> so that they can contain symbolic expressions.
Use a literal for the starts or ends input if they should be constant.

input_shape = {2, 10}
dyn_slice(input, starts_input, ends_input, starts = {0}, ends = {N}, axes = {1})
dyn_slice.compute_shape() => {2, N}
  • When slice.compute() is called, the value at ends_input is used to determine the output shape.

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@CharlieL7 CharlieL7 self-assigned this Aug 4, 2026
@CharlieL7 CharlieL7 changed the title Dynamic slice from symbolic slice in other branch dyn_slice operator for symbolics and data-dependent operators Aug 4, 2026
@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Aug 5, 2026

Copy link
Copy Markdown
Test Batch New Rate (205efd) Old Rate (3a503c)* Diff Status
torchvision-resnet50 64 1,799.89 3,264.92 -44.87% 🔴
torchvision-resnet50_fp16 64 2,874.03 7,548.67 -61.93% 🔴
torchvision-densenet121 32 1,651.18 2,483.99 -33.53% 🔴
torchvision-densenet121_fp16 32 3,978.91 5,004.24 -20.49% 🔴
torchvision-inceptionv3 32 1,650.32 2,058.51 -19.83% 🔴
torchvision-inceptionv3_fp16 32 2,017.16 4,416.99 -54.33% 🔴
cadene-inceptionv4 16 724.34 820.61 -11.73% 🔴
cadene-resnext64x4 16 773.50 782.78 -1.18%
slim-mobilenet 64 8,236.06 8,386.36 -1.79%
slim-nasnetalarge 64 nan 228.86 nan
slim-resnet50v2 64 1,048.21 3,180.91 -67.05% 🔴
bert-mrpc-onnx 8 579.04 1,168.84 -50.46% 🔴
bert-mrpc-tf 1 415.66 498.63 -16.64% 🔴
pytorch-examples-wlang-gru 1 533.52 473.35 12.71% 🔆
pytorch-examples-wlang-lstm 1 356.42 384.83 -7.38% 🔴
torchvision-resnet50_1 1 336.27 1,046.63 -67.87% 🔴
cadene-dpn92_1 1 469.21 437.32 7.29% 🔆
cadene-resnext101_1 1 364.88 365.89 -0.28%
onnx-taau-downsample 1 839.41 844.09 -0.55%
dlrm-criteoterabyte 1 10.11 32.42 -68.83% 🔴
dlrm-criteoterabyte_fp16 1 12.29 51.80 -76.27% 🔴
agentmodel 1 9,782.34 9,209.12 6.22% 🔆
unet_fp16 2 3.95 58.80 -93.29% 🔴
resnet50v1_fp16 1 197.42 1,366.11 -85.55% 🔴
resnet50v1_int8 1 34.20 1,883.96 -98.18% 🔴
bert_base_cased_fp16 64 631.92 1,098.16 -42.46% 🔴
bert_large_uncased_fp16 32 133.80 345.59 -61.28% 🔴
bert_large_fp16 1 53.73 206.59 -73.99% 🔴
distilgpt2_fp16 16 1,899.76 2,092.89 -9.23% 🔴
yolov5s 1 92.82 558.33 -83.37% 🔴
tinyllama 1 10.06 45.83 -78.06% 🔴
vicuna-fastchat 1 29.11 44.20 -34.14% 🔴
whisper-tiny-encoder 1 171.22 411.87 -58.43% 🔴
whisper-tiny-decoder 1 388.26 408.48 -4.95%
llama2_7b 1 20.49 20.84 -1.67%
qwen1.5-7b 1 22.34 23.58 -5.25% 🔴
phi3-3.8b 1 26.74 26.72 0.08%
llama3-8b 1 15.05 21.80 -30.95% 🔴
whisper-large-encoder 1 7.55 10.18 -25.78% 🔴
whisper-large-decoder 1 35.80 105.30 -66.00% 🔴
mistral-7b 1 5.45 23.78 -77.08% 🔴
FLUX.1-schnell 1 768.10 755.22 1.71%

Regressions detected 🔴

* No develop baseline was found for this PR's branch point; compared against the latest available develop run instead.

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Aug 5, 2026

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-gru PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-lstm PASSED: MIGraphX meets tolerance
dlrm-criteoterabyte PASSED: MIGraphX meets tolerance
agentmodel PASSED: MIGraphX meets tolerance
unet PASSED: MIGraphX meets tolerance
resnet50v1 PASSED: MIGraphX meets tolerance
bert_base_cased_fp16 PASSED: MIGraphX meets tolerance
bert_large_uncased_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
bert_large PASSED: MIGraphX meets tolerance
yolov5s PASSED: MIGraphX meets tolerance
tinyllama PASSED: MIGraphX meets tolerance
vicuna-fastchat PASSED: MIGraphX meets tolerance
whisper-tiny-encoder PASSED: MIGraphX meets tolerance
whisper-tiny-decoder PASSED: MIGraphX meets tolerance
distilgpt2_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

@CharlieL7
CharlieL7 marked this pull request as ready for review August 5, 2026 21:49
@CharlieL7
CharlieL7 requested review from a team and causten as code owners August 5, 2026 21:49
@CharlieL7
CharlieL7 requested review from pfultz2 and shivadbhavsar and a lite review from Copilot August 5, 2026 21:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new dyn_slice operator to support compile-time symbolic output shapes while still allowing data-dependent slice bounds at runtime, and extends attribute normalization to optionally operate symbolically via a new use_sym normalize attribute.

Changes:

  • Added dyn_slice(data, starts, ends) op with symbolic bound attributes (vector<dim_like>) and runtime-bound execution.
  • Extended attribute normalization to support symbolic clamping when use_sym is enabled.
  • Updated slice behavior/tests to reject symbolic input shapes and route symbolic slicing use-cases through dyn_slice instead.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/sym.cpp Adds rewrite-rule coverage tests for redundant nested min/max clamping.
test/ref/dyn_slice.cpp New ref backend tests validating dyn_slice runtime behavior with concrete and symbolic bounds.
test/op_shape_test.cpp Adds shape-inference tests for dyn_slice and updates symbolic-shape expectations for slice.
test/normalize_ops_test.cpp Adds normalization-pass tests for symbolic attribute clamping and use_sym opt-in enforcement.
test/gpu/dyn_slice_lowering.cpp Adds GPU lowering test coverage for dyn_slice metadata-host-copy behavior.
src/targets/gpu/lowering.cpp Extends runtime-metadata lowering to apply to both slice and dyn_slice.
src/sym.cpp Adds rewrite rules to fold away redundant nested min/max clamps.
src/normalize_attributes.cpp Implements symbolic attribute normalization path (use_sym) and refactors normalization helpers.
src/include/migraphx/operators.hpp Registers the new dyn_slice operator header in the operator include set.
src/include/migraphx/op/slice.hpp Rejects symbolic input shapes for slice (directing users to dyn_slice).
src/include/migraphx/op/normalize_attribute.hpp Adds use_sym normalize attribute and documents symbolic normalization semantics.
src/include/migraphx/op/dyn_slice.hpp New dyn_slice operator implementation and normalization attributes.
src/include/migraphx/dim_like.hpp Adds helpers for converting dim_like vectors to concrete ints or symbolic expressions.
src/CMakeLists.txt Registers dyn_slice for op build/registration.
CHANGELOG.md Documents dyn_slice, use_sym, and slice symbolic-shape rejection behavior.

Comment thread test/ref/dyn_slice.cpp
Comment on lines +25 to +34
#include <migraphx/instruction.hpp>
#include <migraphx/literal.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/sym.hpp>
#include <migraphx/verify.hpp>

#include <test.hpp>
Comment thread src/include/migraphx/op/dyn_slice.hpp
Comment on lines +146 to +158
const auto& input = args.front();
auto input_shape = input.get_shape();
auto read = [](const argument& arg) {
std::vector<int64_t> result;
arg.visit([&](auto values) { result = values.template to_vector<int64_t>(); });
return result;
};
auto axes_attrs = this->attributes().at("normalize_axes");
// Only use the starts_input and ends_input for the output slice. Not the attributes.
auto norm_starts = normalize_indices(
read(args[1]), axes, input_shape, axes_attrs.at("starts"), "DYN_SLICE: starts input");
auto norm_ends = normalize_indices(
read(args[2]), axes, input_shape, axes_attrs.at("ends"), "DYN_SLICE: ends input");
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.32710% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/normalize_attributes.cpp 95.00% 6 Missing ⚠️
src/include/migraphx/dim_like.hpp 77.78% 2 Missing ⚠️
src/include/migraphx/op/dyn_slice.hpp 97.06% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5112      +/-   ##
===========================================
+ Coverage    93.25%   93.27%   +0.01%     
===========================================
  Files          623      624       +1     
  Lines        33002    33232     +230     
===========================================
+ Hits         30776    30994     +218     
- Misses        2226     2238      +12     
Files with missing lines Coverage Δ
src/include/migraphx/op/slice.hpp 95.56% <100.00%> (-0.10%) ⬇️
src/include/migraphx/sym.hpp 97.87% <ø> (ø)
src/sym.cpp 96.79% <100.00%> (+0.04%) ⬆️
src/include/migraphx/dim_like.hpp 86.67% <77.78%> (-13.33%) ⬇️
src/include/migraphx/op/dyn_slice.hpp 97.06% <97.06%> (ø)
src/normalize_attributes.cpp 95.80% <95.00%> (-1.04%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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