{"record":{"id":"7c786c2f6df20f08","repo":"xai-org/x-algorithm","slug":"axis-should-be-an-int-slice-or-iterable-of-ints","errorCode":null,"errorMessage":"`axis` should be an int, slice or iterable of ints.","messagePattern":"`axis` should be an int, slice or iterable of ints\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/normalization.py","lineNumber":79,"sourceCode":"        self,\n        axis: Union[int, Sequence[int], slice],\n        eps: float = 1e-5,\n        scale_init: Optional[hk.initializers.Initializer] = None,\n        name: Optional[str] = None,\n        create_scale: bool = True,\n        pspec: Optional[P] = P(None),\n        lr_multiplier: float = 1.0,\n        weight_decay_mask: float = 0.0,\n    ):\n        super().__init__(name=name)\n        if isinstance(axis, slice):\n            self.axis = axis\n        elif isinstance(axis, int):\n            self.axis = (axis,)\n        elif isinstance(axis, abc.Iterable) and all(isinstance(ax, int) for ax in axis):\n            self.axis = tuple(axis)\n        else:\n            raise ValueError(\"`axis` should be an int, slice or iterable of ints.\")\n\n        self.eps = eps\n        self.create_scale = create_scale\n        self.reparameterize = weight_decay_mask > 0\n        if scale_init is None:\n            scale_init = jnp.zeros if self.reparameterize else jnp.ones\n        if self.reparameterize and scale_init is not jnp.zeros:\n            raise ValueError(\n                \"RMSNorm: when weight_decay_mask > 0 the layer is \"\n                \"re-parameterized as (1 + scale) * x and `scale_init` must be \"\n                f\"jnp.zeros (got {scale_init!r}). Pass scale_init=jnp.zeros or \"\n                \"leave it as None to use the default.\"\n            )\n        self.scale_init = scale_init\n        self.pspec = pspec\n        self.lr_multiplier = lr_multiplier\n        self.weight_decay_mask = weight_decay_mask\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/normalization.py#L61-L97","documentation":"RMSNorm/LayerNorm-style __init__ normalizes the axis argument: it accepts a slice, an int, or an iterable whose elements are all ints, storing it as a tuple. Anything else (a float, a string, a single-element non-int iterable like [1.5] or np.array with float dtype) raises ValueError with the accepted forms.","triggerScenarios":"Constructing the normalization layer with axis=1.0, axis=\"features\", axis=[0, 1.0], or an unhashable/mixed iterable.","commonSituations":"Programmatically computed axis values that arrive as floats or numpy scalars; configs that store axis as a string.","solutions":["Pass axis as int or an iterable of ints, e.g. axis=-1 or axis=(1, 2).","Coerce numpy scalars with int(ax) before constructing.","Validate config-loaded axis values against this contract in your config parser."],"exampleFix":"# before\nnorm = Norm(axis=np.float64(-1.0), ...)\n\n# after\nnorm = Norm(axis=-1, ...)","handlingStrategy":"type-guard","validationCode":"axis = tuple(int(a) for a in axis) if not isinstance(axis, int) else axis","typeGuard":"def is_valid_axis(axis) -> bool:\n    return isinstance(axis, (int, slice)) or (\n        isinstance(axis, abc.Iterable) and all(isinstance(a, int) for a in axis)\n    )","tryCatchPattern":null,"preventionTips":["Coerce numpy scalars to int before passing axis.","Keep axis values as plain ints/tuples of ints in configs."],"tags":["normalization","axis-argument","type-validation","jax"],"backgroundTag":"invalid-argument-type","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}