jax-ml/jax · error · ValueError
Attempting to swap into allocation with `key` {key} that is
Error message
Attempting to swap into allocation with `key` {key} that is not a `Buffer`. What it means
swap_buffer_content (used by semaphore-style swap ops) looked up a memory key whose stored object is not a Buffer. The atomic-swap emulation needs Buffer shape/dtype metadata.
Source
Thrown at jax/_src/pallas/mosaic/interpret/shared_memory.py:659
increment_clock: Whether to increment the given thread's vector clock.
thread: The thread that's writing into the buffer.
logging_info: Information about the source of the swap.
Returns:
- The contents of the range of the buffer (prior to the swap), or None if
accessing buffer contents bounds.
- The shape and dtype of the full content array of the buffer.
- The incremented vector clock for the given thread.
None if race detection is not enabled or if `increment_clock` is False.
"""
clock = None
with self.lock:
if self.detect_races and increment_clock:
clock = self.incr_clock(thread, take_lock=False)
buff = self.mem[key]
if not isinstance(buff, Buffer):
raise ValueError(
f"Attempting to swap into allocation with `key` {key} that is not a"
" `Buffer`."
)
shape_and_dtype = ShapeAndDtype(buff.logical_shape, buff.dtype)
assert buff.dtype == value.dtype # TODO(jburnim): Catch this statically.
# TODO(jburnim): Better error message if this raises?
try:
result = buff[rnge].copy()
except IndexError:
# `buf` was accessed with `rnge` entirely out of bounds.
result = None
if result is not None:
in_bounds_shape = result.shape
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Verify the key is a Buffer allocation before swapping
- Fix key allocation so semaphores and buffers use disjoint key spaces
- Swap against the correct MemKey returned by allocate_buffer
Defensive patterns
Strategy: type-guard
Type guard
def is_buffer_key(mgr, key):
with mgr.lock:
return isinstance(mgr.mem.get(key), Buffer) Try / catch
try:
out = mgr.swap(key, value, ...)
except ValueError as e:
if 'not a `Buffer`' in str(e):
raise KeyError(f'{key} is not a buffer allocation') from e
raise Prevention
- Swap only against buffer keys; use semaphore APIs for semaphores
- Avoid ID spaces where semaphore keys and buffer keys can collide
When it happens
Trigger: Calling SharedMemManager.swap or _swap with a key registered to a semaphore or other non-Buffer allocation.
Common situations: Key collisions between semaphores and buffers; misuse of swap semantics on non-buffer allocations in custom interpret-mode primitives.
Related errors
- Attempting to deallocate allocation with key `{key}` that is
- Attempting to get contents of allocation with key `{key}` th
- Attempting to store into allocation with key `{key}` that is
- Logical shape {self.logical_shape} cannot be bigger than con
- Acc ref must be at least 2D, got shape {shape}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/9f59011991f4735d.
Report an issue: GitHub.