{"record":{"id":"f04de46606abf1bc","repo":"jax-ml/jax","slug":"delta-orthogonal-initializer-requires-a-3d-4d-or","errorCode":null,"errorMessage":"Delta orthogonal initializer requires a 3D, 4D or 5D shape.","messagePattern":"Delta orthogonal initializer requires a 3D, 4D or 5D shape\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/nn/initializers.py","lineNumber":690,"sourceCode":"          [ 0.9120717 ,  0.04322892,  0.40774566],\n          [-0.30085585, -0.6050892 ,  0.73712474]],\n  <BLANKLINE>\n         [[ 0.        ,  0.        ,  0.        ],\n          [ 0.        ,  0.        ,  0.        ],\n          [ 0.        ,  0.        ,  0.        ]]], dtype=float32)\n\n\n  .. _delta orthogonal initializer: https://arxiv.org/abs/1806.05393\n  \"\"\"\n  def init(key: Array,\n           shape: core.Shape,\n           dtype: DTypeLikeInexact | None = dtype,\n           out_sharding: OutShardingType = None) -> Array:\n    if out_sharding is not None:\n      raise NotImplementedError\n    dtype = dtypes.default_float_dtype() if dtype is None else dtype\n    if len(shape) not in [3, 4, 5]:\n      raise ValueError(\"Delta orthogonal initializer requires a 3D, 4D or 5D \"\n                       \"shape.\")\n    if shape[-1] < shape[-2]:\n      raise ValueError(\"`fan_in` must be less or equal than `fan_out`. \")\n    ortho_init = orthogonal(scale=scale, column_axis=column_axis, dtype=dtype)\n    ortho_matrix = ortho_init(key, shape[-2:])\n    W = jnp.zeros(shape, dtype=dtype)\n    if len(shape) == 3:\n      k = shape[0]\n      return W.at[(k-1)//2, ...].set(ortho_matrix)\n    elif len(shape) == 4:\n      k1, k2 = shape[:2]\n      return W.at[(k1-1)//2, (k2-1)//2, ...].set(ortho_matrix)\n    else:\n      k1, k2, k3 = shape[:3]\n      return W.at[(k1-1)//2, (k2-1)//2, (k3-1)//2, ...].set(ortho_matrix)\n  return init\n","sourceCodeStart":672,"sourceCodeEnd":707,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/nn/initializers.py#L672-L707","documentation":"jax.nn.initializers.delta_orthogonal() requires the weight shape to describe a convolutional kernel: 3D (k, fan_in, fan_out), 4D, or 5D. It works by inserting an orthogonal matrix into the center slice of a zero kernel, which only makes sense for conv-style shapes.","triggerScenarios":"Calling delta_orthogonal()(key, shape) with len(shape) not in {3,4,5}, e.g. a 2D matrix shape like (8, 8) or a 6D shape.","commonSituations":"Using delta_orthogonal where plain orthogonal() was intended (2D dense weights), or passing a flattened/reshaped parameter vector instead of the conv kernel shape.","solutions":["If you want a dense orthogonal matrix, use jax.nn.initializers.orthogonal() instead","For conv kernels, pass the full kernel shape, e.g. (kh, kw, fan_in, fan_out) for conv2d","Check that the shape passed is the actual parameter shape, not a flattened size"],"exampleFix":"// before\nw = jax.nn.initializers.delta_orthogonal()(key, (8, 8))\n// after\nw = jax.nn.initializers.orthogonal()(key, (8, 8))","handlingStrategy":"validation","validationCode":"def delta_ortho_or_dense(init, key, shape):\n    assert len(shape) in (3, 4, 5), f'delta_orthogonal needs 3-5D shape, got {shape}'\n    return init(key, shape)","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use orthogonal() for 2D dense kernels","Reserve delta_orthogonal for conv kernels"],"tags":["jax","initializer","shape-validation"],"backgroundTag":"invalid-shape-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}