Skip to content

Serialize CPU ScatterND string updates - #32033

Merged
Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/cpu-scatternd-string-race
Aug 13, 2026
Merged

Akshay Sonawane (apsonawane) merged 2 commits into
mainfrom
fix/cpu-scatternd-string-race

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request introduces improvements to the handling and testing of string data in the ScatterND operator. The main changes include a fix to disable parallelization for string data types and the addition of new test cases to verify correct behavior with duplicate indices and string concatenation.

Improvements to string data handling:

  • Disabled parallel execution (tp = nullptr) for std::string data types in the ScatterNDDispatchTarget struct to prevent potential issues with concurrent string operations.

Expanded test coverage:

  • Added ScatterND_string_duplicate_indices test to verify that when duplicate indices are present, the last update value is used for string data.
  • Added ScatterND_string_add_duplicate_indices test to verify that when the reduction attribute is set to "add", updates to the same string index are concatenated in order.

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 improves CPU ScatterND behavior for string tensors by ensuring updates are applied serially (avoiding concurrent std::string mutation) and adds tests that validate deterministic behavior with duplicate indices, including "add" reduction concatenation order.

Changes:

  • Disable TryParallelFor parallelism for std::string in the CPU ScatterND dispatch path by setting tp = nullptr.
  • Add a test that validates β€œlast update wins” for duplicate indices with string data.
  • Add a test that validates "add" reduction concatenates strings in update order for duplicate indices.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/providers/cpu/tensor/scatter_nd.cc Disables parallel execution for string updates in ScatterNDDispatchTarget to avoid unsafe concurrent string operations.
onnxruntime/test/providers/cpu/tensor/scatter_nd_op_test.cc Adds new string-focused tests covering duplicate indices with default reduction and "add" reduction.

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

@apsonawane
Akshay Sonawane (apsonawane) merged commit 36e2f9d into main Aug 13, 2026
112 of 132 checks passed
@apsonawane
Akshay Sonawane (apsonawane) deleted the fix/cpu-scatternd-string-race branch August 13, 2026 23:39
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.

3 participants