{"record":{"id":"d8bc04aa488be938","repo":"jax-ml/jax","slug":"the-platform-for-the-specified-backend-xb-canonic","errorCode":null,"errorMessage":"the platform for the specified backend {xb.canonicalize_platform(self.backend.platform)} is different from the lowering platform {self.platforms[0]}","messagePattern":"the platform for the specified backend (.+?) is different from the lowering platform (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/interpreters/mlir.py","lineNumber":902,"sourceCode":"    self.aval_to_ir_types_cache = ({} if aval_to_ir_types_cache is None else aval_to_ir_types_cache)\n    self.pallas_lowering_cache = ({} if pallas_lowering_cache is None else pallas_lowering_cache)\n    self.pallas_collective_id_mapping = (CollectiveIdMapping()\n                                         if pallas_collective_id_mapping is None\n                                         else pallas_collective_id_mapping)\n\n  def get_backend(self, optional: bool = False) -> xc.Client | None:\n    if len(self.platforms) > 1:\n      if optional:\n        return None\n      raise NotImplementedError(\n        \"accessing .backend in multi-lowering setting. This can occur when \"\n        \"lowering a primitive that has not been adapted to multi-platform \"\n        \"lowering\")\n    if self.backend is not None:\n      if xb.canonicalize_platform(self.backend.platform) != self.platforms[0]:\n        if optional:\n          return None\n        raise ValueError(\n          \"the platform for the specified backend \"\n          f\"{xb.canonicalize_platform(self.backend.platform)} is different \"\n          f\"from the lowering platform {self.platforms[0]}\")\n      return self.backend\n    return xb.get_backend(self.platforms[0])\n\n  def new_channel(self) -> int:\n    channel = next(self.channel_iterator)\n    # `xla::HostCallback` requires a 16-bit channel ID.\n    if channel >= (1 << 16):\n      raise RuntimeError(\n          \"Host callback lowering created too many channels. PjRt does not\"\n          \" support more than 65535 channels\")\n    return channel\n\n  # Adds an IFRT host callback object to the context. A reference to these\n  # callbacks will be provided to IFRT during compilation so it can do things\n  # like serialize them and keep them alive.","sourceCodeStart":884,"sourceCodeEnd":920,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/interpreters/mlir.py#L884-L920","documentation":"A LoweringRuleContext can carry an explicit backend; if that backend's canonicalized platform differs from the platform the computation is being lowered for, mixing the two would produce invalid code, so JAX raises a ValueError spelling out both platforms.","triggerScenarios":"Constructing or reusing a LoweringRuleContext whose backend was built for platform A (e.g. 'cpu') while lowering targets platform B (e.g. 'gpu'/'tpu'); commonly from manually built contexts, custom primitives reusing a cached ctx, or specifying devices/backends inconsistently across jax.jit(device=...) and lowering contexts.","commonSituations":"Mismatched jax devices in multi-GPU/TPU setups; tests that build a CPU context but lower GPU computations; custom export tooling that pins a backend then switches platforms; version changes in platform canonicalization naming.","solutions":["Ensure the backend passed to the lowering context matches the platform being lowered: xb.get_backend(target_platform)","Rebuild the context rather than reusing one created for a different platform","Canonicalize platform names (xb.canonicalize_platform) when comparing/user input, e.g. 'cuda' vs 'gpu'"],"exampleFix":"# before\nctx = ctx.replace(backend=xb.get_backend('cpu'))\nlower_for(ctx, platforms=['gpu'])  # ValueError\n\n# after\nctx = ctx.replace(backend=xb.get_backend('gpu'))\nlower_for(ctx, platforms=['gpu'])","handlingStrategy":"validation","validationCode":"from jax._src import xla_bridge as xb\n\nassert xb.canonicalize_platform(backend.platform) == ctx.platforms[0], \\\n    f'backend {backend.platform} vs lowering {ctx.platforms[0]}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create LoweringRuleContext backends with xb.get_backend(target_platform) matching platforms","Do not cache/reuse contexts across platforms","Always compare platforms via canonicalize_platform, not raw strings"],"tags":["jax","platform-mismatch","lowering","backend"],"backgroundTag":"platform-backend-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}