Skip to content

EinsumDense returns incorrect symbolic output shape for valid equation/output_shape #22518

@ningxiudg

Description

@ningxiudg

Bug report: EinsumDense symbolic output shape is incorrect

Background

keras.layers.EinsumDense should produce the same output shape for both eager tensors and symbolic keras.Input tensors when configured identically.

Reproduction

import keras
import numpy as np

layer = keras.layers.EinsumDense(
    equation="abc,cd->abd",
    output_shape=[None, 64, 32],
    bias_axes="d",
)

x1 = np.random.random((5, 32, 128))
out1 = layer(x1)

x2 = keras.Input(shape=(32, 128))
out2 = layer(x2)

print(out1.shape)
print(out2.shape)

Expected result

Both outputs should have the same logical shape for the configured equation, e.g.:

  • eager tensor: (5, 32, 64)
  • symbolic tensor: (None, 32, 64)

Actual result

  • eager tensor: (5, 32, 64)
  • symbolic tensor: (None, None, 64, 32)

This indicates EinsumDense builds/infers the symbolic output shape incorrectly for this valid configuration.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions