{"record":{"id":"3750ae6c5f06b31f","repo":"jax-ml/jax","slug":"invalid-memory-space-self","errorCode":null,"errorMessage":"invalid memory space: {self}","messagePattern":"invalid memory space: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/tpu_custom_call.py","lineNumber":140,"sourceCode":"      return 0\n    elif self == MemorySpace.VMEM:\n      return 1\n    elif self == MemorySpace.SEMAPHORE_MEM:\n      return 2\n    elif self == MemorySpace.SC_SCALAR_SEMAPHORE_MEM:\n      return 8\n    elif self == MemorySpace.SC_VECTOR_SEMAPHORE_MEM:\n      return 10\n    elif self == MemorySpace.SMEM:\n      return 4\n    elif self == MemorySpace.HOST:\n      return 5\n    elif self == MemorySpace.SC_SCALAR_SMEM:\n      return 11\n    elif self == MemorySpace.SC_VECTOR_SMEM:\n      return 12\n    else:\n      raise ValueError(\"invalid memory space: \" + str(self))\n\n\nclass CostEstimate(TypedDict):\n  flops: int\n  transcendentals: int\n  bytes_accessed: int\n  remote_bytes_transferred: int\n\n  def to_json(self) -> bytes:  # pyrefly: ignore[bad-class-definition]\n    return (\n        f'{{\"flops\": {self[\"flops\"]}, \"transcendentals\":'\n        f' {self[\"transcendentals\"]}, \"bytes_accessed\":'\n        f' {self[\"bytes_accessed\"]}, \"remote_bytes_transferred\":'\n        f' {self[\"remote_bytes_transferred\"]}}}'\n    ).encode(\"ascii\")\n\n\nclass TpuSideEffectType(enum.Enum):","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/tpu_custom_call.py#L122-L158","documentation":"MemorySpace.to_color raises ValueError when asked to convert a MemorySpace enum member that has no assigned color code — i.e. an invalid or newly-added/unknown memory space value falls through the if/elif chain.","triggerScenarios":"Constructing MemorySpace with an out-of-range int or comparing to an unknown member then calling to_color(); typically reached via serialization of layout/cost-analysis attributes that call this conversion.","commonSituations":"Version mismatch where an enum value exists on one side but not the other; typos in raw integer memory-space codes passed by user code or stale serialized configs.","solutions":["Use only documented MemorySpace enum members (HBM, VMEM, SMEM, ...) instead of raw ints.","Align JAX versions across processes/components that exchange these values.","Catch ValueError and reject/report the unknown space early rather than letting it reach to_color."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"VALID = {MemorySpace.HBM, MemorySpace.VMEM, MemorySpace.SMEM}\nif space not in VALID: raise ValueError(f'unsupported memory space {space!r}')","typeGuard":"def is_valid_memory_space(s) -> bool:\n    return isinstance(s, MemorySpace) and s in VALID_SPACES","tryCatchPattern":"try:\n    color = space.to_color()\nexcept ValueError:\n    raise ValueError(f'unknown MemorySpace {space!r}; update JAX or use a documented member')","preventionTips":["Only use enum members, never raw ints, for memory spaces.","Pin/align JAX versions across components exchanging serialized configs."],"tags":["jax","tpu","memory-space","enum","invalid-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}