Skip to content

[FlagGems Operator Development Competition] Add roll operator - #2597

Merged
douxetpur merged 10 commits into
flagos-ai:masterfrom
HyosungSink:roll-migration
Apr 27, 2026
Merged

[FlagGems Operator Development Competition] Add roll operator#2597
douxetpur merged 10 commits into
flagos-ai:masterfrom
HyosungSink:roll-migration

Conversation

@HyosungSink

Copy link
Copy Markdown
Contributor

Summary

Add roll operator for the FlagGems Operator Development Competition.

This PR adds:

  • torch.roll(input, shifts, dims=None)

Implementation

  • Added optimized Triton implementation in src/flag_gems/ops/roll.py
  • Added roll correctness coverage in tests/test_unary_pointwise_ops.py
  • Added benchmark coverage using the FlagGems built-in benchmark framework
  • Added operator-specific benchmark shapes in benchmark/core_shapes.yaml

Implementation details:

  • flatten fast path for dims=None
  • specialized 1D / first-dim / last-dim kernels for hot single-dimension cases
  • fused gather kernel for contiguous hot multi-dimension cases
  • PyTorch-compatible argument validation, repeated-dim semantics, and empty-tensor out-of-range dims handling
  • unsupported fast-path dtypes and layouts fall back safely to PyTorch behavior

Accuracy Validation

Correctness tests cover:

  • dims=None flatten behavior
  • single-dimension and multi-dimension roll
  • positive / negative shifts and dims
  • repeated dims behavior aligned with PyTorch
  • scalar tensors and empty tensors
  • bool tensors and float64 fallback
  • non-contiguous input
  • invalid shift/dim combinations and out-of-range dims

All outputs are compared against PyTorch reference behavior.

Note: the upstream roll test report contains 51 skipped cases. These are expected parameterized skips for invalid shape/dim combinations in the shared POINTWISE_SHAPES set, not hidden failures.

Benchmark

Validation results:

  • pre-commit: passed
  • ARCH=7 python -m pytest tests/test_unary_pointwise_ops.py -m roll -q: 257 passed, 51 skipped, 3397 deselected
  • official roll benchmark harness: passed

Official benchmark harness

DType Minimum Speedup
float32 1.080x
float16 1.250x

Representative benchmark cases

DType Case Speedup
float32 flat_1d_small 1.097x
float32 flat_3d_medium 2.419x
float32 single_dim_2d_last 1.814x
float32 single_dim_3d_first 2.931x
float32 single_dim_3d_last_large 2.402x
float32 multi_dim_3d 4.105x
float32 multi_dim_4d 4.886x
float16 flat_1d_small 1.103x
float16 flat_3d_medium 2.709x
float16 single_dim_2d_last 1.691x
float16 single_dim_3d_first 5.599x
float16 single_dim_3d_last_large 2.316x
float16 multi_dim_3d 4.502x
float16 multi_dim_4d 4.691x

Test Coverage Checklist

  • API branches: torch.roll(input, shifts, dims=None)
  • Input dims: flatten / single-dim / multi-dim
  • Input scales: small / representative / hot large cases
  • Tensor layout: contiguous and non-contiguous
  • Tensor shapes: scalar, empty, regular multi-dim tensors
  • DTypes: float16, float32, bool, float64 fallback
  • Error behavior: invalid shift/dim combinations and out-of-range dims

@CLAassistant

CLAassistant commented Apr 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added benchmark ops/aten tests size/Large competition This PR is related to gems competition. labels Apr 22, 2026
@HyosungSink
HyosungSink force-pushed the roll-migration branch 2 times, most recently from ad17615 to e3fda26 Compare April 22, 2026 04:03
@HyosungSink

Copy link
Copy Markdown
Contributor Author

Hi @douxetpur, the branch has been updated to the latest master and merge conflicts are resolved. Could you please help approve the pending workflows when convenient? Thanks!

@HyosungSink

Copy link
Copy Markdown
Contributor Author

Hi @douxetpur, I have fixed the issues from the previous failed checks and verified the formatting fix by passing code-style in my fork-side precheck PR. Could you please help trigger a fresh round of CI/checks for this PR when convenient? Thank you!

@HyosungSink

Copy link
Copy Markdown
Contributor Author

Hi @douxetpur, the latest python-op failure seems to be caused by a transient runner issue during actions/checkout@v6 (Failed to connect to github.com port 443: Connection timed out), before the actual test script started.

Could you please help rerun the CI when convenient? Thank you very much.

@HyosungSink

Copy link
Copy Markdown
Contributor Author

All required checks are passing now, and the branch is up to date with the latest fixes. Could a code owner please review when convenient? Thank you very much.

@douxetpur douxetpur left a comment

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.

LGTM

@douxetpur
douxetpur merged commit a727779 into flagos-ai:master Apr 27, 2026
18 checks passed
solid-shuwen pushed a commit to solid-shuwen/FlagGems that referenced this pull request Apr 27, 2026
…-ai#2597)

* [FlagGems Operator Development Competition] Optimize roll

* Fix roll empty tensor dim handling

* Avoid pytest option conflicts in mixed test runs
@HyosungSink

Copy link
Copy Markdown
Contributor Author

Hi maintainers, thank you very much for your time and effort in reviewing and merging this PR.

My name is Zhiyuan Chen (陈致远). If any further follow-up or coordination is needed regarding the competition submission, I will respond promptly and cooperate actively.

Thank you again for your support.

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

Labels

competition This PR is related to gems competition. ops/aten size/Large tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants