jax-ml/jax · error · ValueError
Invalid memory space: {memory_space!r}
Error message
Invalid memory space: {memory_space!r} What it means
The same mapping function validates that the memory space is one of the recognized types: an AccMemorySpace, a TPU MemorySpace, or pass-through ANY/Host spaces. Anything else (unknown enum, string, None) raises ValueError with the repr of the offending value.
Source
Thrown at jax/_src/pallas/mosaic/core.py:519
return memory_space
case (
pallas_core.MemorySpace.ERROR
| pallas_core.MemorySpace.INDEX
| pallas_core.MemorySpace.KEY
):
return MemorySpace.SMEM
case pallas_core.CoreMemorySpace():
return (
memory_space.memory_space
if memory_space.mesh.core_type is core_type
else memory_space
)
case acc if isinstance(acc, AccMemorySpace):
return acc
case MemorySpace():
return memory_space
case _:
raise ValueError(f"Invalid memory space: {memory_space!r}")
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use TPU memory space objects (e.g., pltpu.VMEM / MemorySpace enum members or AccMemorySpace), never strings
- Check imports: GPU-specific spaces (GMEM, SMEM from pl.gpu) are invalid on TPU
- Align JAX/Mosaic versions so enum members match the mapping function
Example fix
// before ref = pltpu.make_block_ref(..., memory_space='vmem') // after from jax.experimental.pallas import tpu as pltpu ref = pltpu.make_block_ref(..., memory_space=pltpu.VMEM)
Defensive patterns
Strategy: type-guard
Validate before calling
from jax._src.pallas import pallas_core
from jax._src import core as jax_core
def is_valid_space(ms):
return isinstance(ms, (pallas_core.MemorySpace, jax_core.MemorySpace)) or hasattr(ms, 'tpu_memory_space') Prevention
- Always pass memory-space enum objects, never strings
- Keep GPU and TPU space imports strictly separated per backend
When it happens
Trigger: Passing a raw string like 'vmem', a pallas_core memory-space constant not known to the TPU backend, or None as memory_space during kernel lowering or ref attribute construction.
Common situations: Using pl.gpu_memory_space constants in a TPU kernel; passing memory_space names as strings from config; API changes renaming enum members between versions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Memory space {self.memory_space} is not supported by mesh {s
- Unsupported core type: {core_type}
- The Pallas TPU lowering currently supports in memory space A
- Loads are only allowed on VMEM and SMEM references.
- Loads and stores are only allowed on VMEM and SMEM reference
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/90f8dde21141941e.
Report an issue: GitHub.