Skip to content

fix(flex): avoid overflow in boolean select updates - #5629

Merged
laggui merged 1 commit into
tracel-ai:mainfrom
Ultroncn:fix/bool-select-or-overflow
Sep 9, 2026
Merged

laggui merged 1 commit into
tracel-ai:mainfrom
Ultroncn:fix/bool-select-or-overflow

Conversation

@Ultroncn

@Ultroncn Ultroncn commented Sep 9, 2026

Copy link
Copy Markdown

Checklist

  • Confirmed that cargo run-checks has been executed successfully.
  • Checked documentation impact: this restores the existing boolean OR contract; no API or book changes are needed.

Related Issues/PRs

Fixes #5605.

Changes

Flex::bool_select_or accumulated boolean updates in a u8 before clamping to 0/1. With 256 true updates to the same index, debug builds panic on overflow and unchecked arithmetic can wrap the result to false.

Use OR in the existing indexed-update kernel instead. This keeps its shape and index validation, 2D fast paths, and view materialization, while retaining the original boolean dtype on the result. Duplicate updates now remain true regardless of their count; existing true values and unselected elements are preserved.

Add shared backend regressions for 256/512 duplicate indices, duplicate rows, and duplicate columns from transposed inputs.

Testing

All three new regression tests fail on the original implementation:

panicked at crates/burn-flex/src/ops/gather_scatter.rs:819:25:
attempt to add with overflow
test result: FAILED. 0 passed; 3 failed

With the fix, the complete boolean select group passes:

BURN_DEVICE=flex cargo test --locked -p burn-backend-tests --no-default-features --features flex,std tensor::bool::ops::select
16 passed; 0 failed
  • Complete release-mode Flex backend suite: 3,409 passed, 39 ignored, 0 failed.
  • Independent code review: no blockers.

cargo run-checks: passed, including formatting, typos, dependency audit, workspace Clippy, no-std compilation, Flex backend tests, and linear algebra tests (3,604 passed, 43 ignored, 0 failed in total). Its embedded Git downloader could not reach GitHub for RustSec. The current official advisory database (bf25f6575a93a35f30796c65c0ed91bee7fa19fd) was fetched through GitHub's API, and the unchanged audit rules passed against that snapshot. The full validation command uses a temporary local database path with fetching disabled; the repository audit configuration is restored afterward.

AI-assisted development

Codex assisted with investigation, implementation, regression testing, and an independent review of the change. The review checked the OR semantics, input/result dtype, storage ownership, and general/2D indexing paths. The tests above exercise the real backend.

Local toolchain note: the release build emitted a rust-objcopy debug-info stripping warning because its LLVM shared library is missing; compilation and all test commands still exited successfully.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.07%. Comparing base (8b35c75) to head (b2d3418).

❌ Your project check has failed because the head coverage (69.07%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5629      +/-   ##
==========================================
- Coverage   69.08%   69.07%   -0.01%     
==========================================
  Files        1283     1283              
  Lines      201222   201265      +43     
==========================================
+ Hits       139005   139031      +26     
- Misses      62217    62234      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

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.

🟢 Approval recommended

The implementation restores OR semantics without overflow and includes focused regression coverage.

Pull request overview

Fixes boolean select updates overflowing u8 when many duplicate indices target the same element.

Changes:

  • Replaces addition-and-clamping with direct boolean OR updates.
  • Preserves the input boolean dtype.
  • Adds regressions for duplicate indices, rows, columns, and transposed views.
File summaries
File Description
crates/burn-flex/src/ops/gather_scatter.rs Adds the shared OR update kernel.
crates/burn-flex/src/ops/bool.rs Routes boolean select updates through OR.
crates/burn-backend-tests/tests/tensor/bool/ops/select.rs Covers overflow and indexing paths.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@laggui
laggui merged commit 4a0d726 into tracel-ai:main Sep 9, 2026
14 of 18 checks passed
@Ultroncn
Ultroncn deleted the fix/bool-select-or-overflow branch October 28, 2026 16:47
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.

burn-flex: bool_select_or overflows u8 with 256+ duplicate indices

3 participants