{"record":{"id":"166f77d26611dde5","repo":"jax-ml/jax","slug":"can-t-instantiate-self-with-arguments","errorCode":null,"errorMessage":"Can't instantiate {self} with arguments.","messagePattern":"Can't instantiate (.+?) with arguments\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/core.py","lineNumber":1825,"sourceCode":"    return ReducedLayout(self, axes)\n\n  def to_mgpu(self, *args, **kwargs) -> mgpu.FragmentedLayout:\n    raise NotImplementedError\n\n\n@dataclasses.dataclass(frozen=True)\nclass ParameterizedLayout(SomeLayout):\n  layout_cls: Layout | TMEMLayout\n  args: Sequence[Any]\n  kwargs: Any\n\n  def __post_init__(self):\n    object.__setattr__(self, \"args\", tuple(self.args))\n    object.__setattr__(self, \"kwargs\", frozen_dict.FrozenDict(self.kwargs))\n\n  def to_mgpu(self, *args, **kwargs) -> mgpu.FragmentedLayout:\n    if args or kwargs:\n      raise ValueError(f\"Can't instantiate {self} with arguments.\")\n    return self.layout_cls.to_mgpu(*self.args, **self.kwargs)\n\n\n@dataclasses.dataclass(frozen=True)\nclass ReducedLayout(SomeLayout):\n  layout: SomeLayout\n  axes: Sequence[int]\n\n  def to_mgpu(self, *args, **kwargs) -> mgpu.FragmentedLayout:\n    if args or kwargs:\n      raise ValueError(f\"Can't instantiate {self} with arguments.\")\n    layout = self.layout.to_mgpu()\n    if not isinstance(layout, mgpu.TiledLayout):\n      raise ValueError(\"Only TiledLayout supports reductions.\")\n    return layout.reduce(self.axes)\n\n\nclass Layout(SomeLayout, enum.Enum):","sourceCodeStart":1807,"sourceCodeEnd":1843,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/core.py#L1807-L1843","documentation":"Raised by Layout.to_mgpu() on a plain (already concrete) Layout wrapper: no construction arguments are accepted because the layout needs no parameters. Passing any positional or keyword args to to_mgpu for a parameterless layout is a usage error.","triggerScenarios":"Calling `layout.to_mgpu(shape)` or `layout.to_mgpu(bits=128)` on a SomeLayout instance that wraps a concrete layout_cls taking no init arguments.","commonSituations":"Generic code that forwards user kwargs to to_mgpu for all layouts, including parameterless ones; refactoring from ParameterizedLayout (which does take args) to a fixed Layout without removing the call-site arguments.","solutions":["Drop the arguments: call layout.to_mgpu()","If parameters are genuinely needed, use a ParameterizedLayout created via the __call__ operator instead of a plain layout"],"exampleFix":"// before\nlayout.to_mgpu(128)\n\n// after\nlayout.to_mgpu()","handlingStrategy":"type-guard","validationCode":"if args or kwargs:\n    raise TypeError('concrete layouts take no to_mgpu arguments')\nlayout.to_mgpu()","typeGuard":"def call_to_mgpu(layout, *args, **kwargs):\n    from jax._src.pallas.mosaic_gpu.core import ParameterizedLayout\n    if not isinstance(layout, ParameterizedLayout) and (args or kwargs):\n        raise TypeError('parameterless layout: call to_mgpu() with no args')\n    return layout.to_mgpu(*args, **kwargs)","tryCatchPattern":"try:\n    mgpu_layout = layout.to_mgpu(*args, **kwargs)\nexcept ValueError:\n    mgpu_layout = layout.to_mgpu()","preventionTips":["Only pass args to ParameterizedLayout.to_mgpu","Branch on isinstance(layout, ParameterizedLayout) before forwarding kwargs"],"tags":["jax","pallas","mosaic-gpu","layout","api-misuse","validation"],"backgroundTag":"invalid-constructor-arguments","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}