{"record":{"id":"92ad9f67ae8b78c8","repo":"xai-org/x-algorithm","slug":"input-must-not-be-scalar","errorCode":null,"errorMessage":"Input must not be scalar.","messagePattern":"Input must not be scalar\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/linear_layer.py","lineNumber":56,"sourceCode":"        self.input_size = None\n        self.output_size = output_size\n        self.with_bias = with_bias\n        self.w_init = w_init\n        self.b_init = b_init or jnp.zeros\n\n        self.config = config\n        self.rms_clip_axes = rms_clip_axes\n\n        self.sharding_context = sharding_context\n        self.pspec = pspec\n\n    def __call__(\n        self,\n        inputs: jax.Array,\n    ) -> jax.Array:\n        fprop_dtype = inputs.dtype\n        if not inputs.shape:\n            raise ValueError(\"Input must not be scalar.\")\n\n        input_size = self.input_size = inputs.shape[-1]\n        output_size = self.output_size\n\n        w_init = self.w_init\n        if w_init is None:\n            stddev = self.config.init_scale / math.sqrt(self.input_size)\n            w_init = hk.initializers.TruncatedNormal(stddev=stddev)\n\n        w = get_parameter(\n            \"w\",\n            [input_size, output_size],\n            jnp.float32,\n            init=w_init,\n            pspec=self.pspec,\n            lr_multiplier=self.config.lr_multiplier,\n            rms_clip_axes=self.rms_clip_axes,\n        )","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/linear_layer.py#L38-L74","documentation":"Linear.__call__ requires inputs to have at least one dimension because it reads inputs.shape[-1] to infer input_size. A scalar (shape ()) has no last axis, so the call is rejected with ValueError before any weights are created.","triggerScenarios":"Passing a JAX scalar (e.g. jnp.float32(1.0), the output of .sum() or .mean() without keepdims) into a Haiku Linear layer.","commonSituations":"Reduced tensors losing their dims in feature pipelines; indexing that yields 0-d arrays; feeding per-scalar summaries into a projection layer.","solutions":["Reshape the scalar to at least 1D before the layer: x[None] or jnp.atleast_1d(x).","Keep dims during reductions: x.sum(axis=-1, keepdims=True).","Batch per-example scalars into a [B, 1] tensor upstream."],"exampleFix":"# before\ny = linear(jnp.float32(0.5))\n\n# after\ny = linear(jnp.atleast_1d(jnp.float32(0.5)))","handlingStrategy":"type-guard","validationCode":"import jax.numpy as jnp\nx = jnp.atleast_1d(x) if getattr(x, \"ndim\", 1) == 0 else x","typeGuard":"def is_non_scalar(x) -> bool:\n    return hasattr(x, \"shape\") and len(x.shape) > 0","tryCatchPattern":null,"preventionTips":["Use keepdims=True in reductions feeding linear layers.","Wrap model inputs with jnp.atleast_2d at the batch boundary."],"tags":["linear-layer","scalar-input","shape-validation","jax"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}