{"record":{"id":"f999bed01261d41b","repo":"keras-team/keras","slug":"output-shape-shape-does-not-match-core-dimension","errorCode":null,"errorMessage":"output shape {shape} does not match core dimensions {core_dims}","messagePattern":"output shape (.+?) does not match core dimensions (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/backend_utils.py","lineNumber":497,"sourceCode":"            for arg in re.findall(_ARGUMENT, arg_list)\n        ]\n        for arg_list in signature.split(\"->\")\n    )\n    return args, retvals\n\n\ndef _vectorize_update_dim_sizes(dim_sizes, shape, core_dims, is_input=True):\n    num_core_dims = len(core_dims)\n    if is_input:\n        if len(shape) < num_core_dims:\n            raise ValueError(\n                f\"input with shape {shape} does not \"\n                \"have enough dimensions for all core \"\n                f\"dimensions {core_dims}\"\n            )\n    else:\n        if len(shape) != num_core_dims:\n            raise ValueError(\n                f\"output shape {shape} does not \"\n                f\"match core dimensions {core_dims}\"\n            )\n\n    core_shape = shape[-num_core_dims:] if core_dims else ()\n    for dim, size in zip(core_dims, core_shape):\n        if dim not in dim_sizes:\n            dim_sizes[dim] = size\n        elif size != dim_sizes[dim]:\n            raise ValueError(\n                f\"inconsistent size for core dimension {dim}: \"\n                f\"{size} vs {dim_sizes[dim]}\"\n            )\n\n\ndef _vectorize_parse_input_dimensions(\n    args,\n    input_core_dims,","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/backend_utils.py#L479-L515","documentation":"Guard in _vectorize_update_dim_sizes (output branch): the vectorized function returned a tensor whose rank does not exactly equal the number of core dimensions declared for that output in the gufunc signature — unlike inputs, output core dims must match exactly with no extra leading dimensions.","triggerScenarios":"Thrown at keras/src/backend/common/backend_utils.py:497 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the wrapped function return tensors whose rank equals the declared output core dims (e.g. exactly 1D for '(n)').","Adjust the signature's output part to the actual output rank.","Strip accidental extra axes with a reshape/squeeze inside the wrapped function."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}