{"record":{"id":"62d85d3769c00b2b","repo":"keras-team/keras","slug":"input-should-have-its-last-dimension-fully-defined","errorCode":null,"errorMessage":"Input should have its last dimension fully-defined. Received: input.shape = {real.shape}","messagePattern":"Input should have its last dimension fully-defined\\. Received: input\\.shape = (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/math.py","lineNumber":526,"sourceCode":"        if real.shape != imag.shape:\n            raise ValueError(\n                \"Input `x` should be a tuple of two tensors - real and \"\n                \"imaginary. Both the real and imaginary parts should have the \"\n                f\"same shape. Received: x[0].shape = {real.shape}, \"\n                f\"x[1].shape = {imag.shape}\"\n            )\n\n        # We are calculating 1D FFT. Hence, rank >= 1.\n        if len(real.shape) < 1:\n            raise ValueError(\n                f\"Input should have rank >= 1. \"\n                f\"Received: input.shape = {real.shape}\"\n            )\n\n        # The axis along which we are calculating FFT should be fully-defined.\n        m = real.shape[-1]\n        if m is None:\n            raise ValueError(\n                f\"Input should have its last dimension fully-defined. \"\n                f\"Received: input.shape = {real.shape}\"\n            )\n\n        return (\n            KerasTensor(shape=real.shape, dtype=real.dtype),\n            KerasTensor(shape=imag.shape, dtype=imag.dtype),\n        )\n\n    def call(self, x):\n        return backend.math.fft(x)\n\n\n@keras_export(\"keras.ops.fft\")\ndef fft(x):\n    \"\"\"Computes the Fast Fourier Transform along last axis of input.\n\n    Args:","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/math.py#L508-L544","documentation":"The 1D FFT needs the FFT length known at symbolic-inference time, so the last dimension of the input must be fully defined (not None). Keras raises when real.shape[-1] is None during functional-model construction or with dynamic shapes.","triggerScenarios":"Using a keras.Input(shape=(None,)) (dynamic sequence length) and calling keras.ops.fft inside a functional model; JAX/TF traces with an undefined last dim.","commonSituations":"Variable-length audio/text pipelines with dynamic timesteps feeding an FFT layer; migrating from eager execution to a functional/Layer workflow where shapes become symbolic.","solutions":["Give the input a fixed last dimension: keras.Input(shape=(fft_len,))","Pad/ragged-to-dense to a fixed length before the FFT","If lengths vary, bucket inputs to a few fixed sizes or compute the FFT eagerly outside the symbolic graph","Rebuild with concrete tensors so the last dim is known"],"exampleFix":"# before\ninputs = keras.Input(shape=(None,))  # dynamic length\nout = keras.ops.fft((inputs, inputs))\n# after\ninputs = keras.Input(shape=(256,))  # fixed fft length\nout = keras.ops.fft((inputs, inputs))","handlingStrategy":"validation","validationCode":"assert real.shape[-1] is not None, 'last dim must be static for fft'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use fixed-length keras.Input for FFT models","Pad variable sequences to a constant length before the graph"],"tags":["keras","fft","dynamic-shape","functional-model"],"backgroundTag":"undefined-tensor-dimension","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}