Skip to content

Fix fill operators crash on non-contiguous tensors (stride != 1) in hopper backend - #2560

Merged
huangyiqun merged 4 commits into
flagos-ai:masterfrom
wuhulalala:fix/benchmark-bugs
Apr 28, 2026
Merged

Fix fill operators crash on non-contiguous tensors (stride != 1) in hopper backend#2560
huangyiqun merged 4 commits into
flagos-ai:masterfrom
wuhulalala:fix/benchmark-bugs

Conversation

@wuhulalala

Copy link
Copy Markdown
Collaborator

PR Category

Operator

Type of Change

Bug fix

Description

The hopper fill implementation uses flat offsets to index into tensor memory, which assumes stride=1 (contiguous layout). When the
tensor has non-unit strides — e.g. from slicing like x[:, ::2] — the kernel writes to wrong memory locations, producing results
inconsistent with PyTorch's native fill_ behavior.

The fix detects non-contiguous tensors, copies them to a contiguous buffer before running the fill kernel, then copies the result back
via copy_() which respects the original stride layout

Issue

#2347

Progress

  • Change is properly reviewed (1 reviewer required, 2 recommended).
  • Change is responded to an issue.
  • Change is fully covered by a UT.

Performance

@tengqm tengqm 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.

Great that this passes on Hopper for real!
Huge thank you for quickly adapt the test cases.

Please note that we don't have a fill operator at the moment (see https://github.com/flagos-ai/FlagGems/blob/master/conf/operators.yaml#L1763-L1832). We have several variants for fill, each for a different scenario.

We are now marking operator tests stricter than before. Please use accurate and concise pytest mark for your test cases.

huangyiqun
huangyiqun previously approved these changes Apr 24, 2026
Comment thread tests/test_fill.py Outdated
Comment thread tests/test_fill.py Outdated
huangyiqun
huangyiqun previously approved these changes Apr 24, 2026
@tengqm
tengqm dismissed huangyiqun’s stale review April 24, 2026 10:03

This PR is still not ready.

Comment thread src/flag_gems/runtime/backend/_nvidia/hopper/ops/fill.py
@huangyiqun
huangyiqun merged commit beb5ae9 into flagos-ai:master Apr 28, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants