﻿# JAX scatter updates: duplicate accumulation and unique-index promises need separate validation

Preserve JAX repeated-index update semantics and validate sorted or unique-index optimization promises without confusing them with a request to sort or deduplicate.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-jax-scatter-duplicate-index-promises/
Language: en

## Establish whether every contribution should count

A graph-feature calculation sends several neighbor contributions to the same destination. The [JAX array-at reference](https://docs.jax.dev/en/latest/_autosummary/jax.Array.at.html) explains that repeated indexed updates are all applied, while conflicting update order can be implementation-dependent. Choose the intended operator before optimizing it. Adding all neighbor contributions is different from replacing the destination with one neighbor's value, even if unique-index examples happen to produce the same result.

## Choose a CPU reference with matching semantics

The [NumPy ufunc-at reference](https://numpy.org/doc/stable/reference/generated/numpy.ufunc.at.html) distinguishes unbuffered repeated-index accumulation from ordinary buffered indexed updates. Use the operation that expresses the intended algorithm when preparing a reference. A mismatch between JAX and an incorrectly chosen CPU expression is not evidence of a GPU error. Include repeated destinations in the reference dataset so the test can distinguish inclusion of all contributions from accidental single-write behavior.

## Treat optimization flags as assertions

The [scatter_add reference](https://docs.jax.dev/en/latest/_autosummary/jax.lax.scatter_add.html) documents promises about sorted indices and non-overlapping updates, and warns that the uniqueness promise is not checked. These options do not sort the data or remove duplicates. Only enable a promise when the upstream construction guarantees it. Preserve the proof boundary in the wrapper, especially after filtering or reshaping, where a formerly unique source key may map to the same normalized destination as another entry.

## Separate deterministic inclusion from arithmetic order

For floating-point accumulation, including every contribution does not imply identical summation order or bitwise results on all execution paths. Establish an appropriate numerical tolerance and evaluate the consequences for the task. If the operator is replacement rather than accumulation, define how collisions are resolved before using the GPU operation. Nondeterministic choice among conflicting writes is not an acceptable substitute for a business rule that requires a particular record to win.

## Verify promises on adversarial index sets

A pilot should include repeated, unsorted and normalized boundary indices with distinguishable update values. Check invariants before launch and verify the final logical result. The guides on [parallel reduction order](/journal/learn-parallel-reduction-tree/) and [array memory layout](/journal/learn-aos-soa-kernel-layout/) provide related context. An efficient scatter is useful when its input promises are true and its collision policy matches the intended algorithm; a fast launch does not validate either of those conditions by itself.
