Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use static shape where available in TensorFlow backend #32

Merged
merged 1 commit into from
May 10, 2019

Conversation

stefanwayon
Copy link
Contributor

When running in graph mode, TensorFlow tensors have two types of shapes:

  • a static shape, known when the graph is built
  • a dynamic shape, only known when the graph is run

The static shape is important especially for the channels dimension, since the number of variables needed for a convolution depends on this shape.

In the current implementation, einops uses only the dynamic shape in graph execution mode, which means that static shape information is lost after calling one of the einops functions. I have updated the TensorFlow backend to only use dynamic shape information for dimensions where the static shape is unknown.

When running in graph mode, TensorFlow tensors have two types of shapes:
  - a static shape, known when the graph is built
  - a dynamic shape, only known when the graph is run

The static shape is important especially for the channels dimension, since the number of variables needed for a convolution depends on this shape.

In the current implementation, `einops` uses only the dynamic shape in graph execution mode, which means that static shape information is lost after calling one of the einops functions. I have updated the TensorFlow backend to only use dynamic shape information for dimensions where the static shape is unknown.
@arogozhnikov arogozhnikov merged commit f700314 into arogozhnikov:master May 10, 2019
@arogozhnikov
Copy link
Owner

LGTM, thanks! Does it only help you with interpreting shapes while constructing graph or there are other important cases?

@stefanwayon
Copy link
Contributor Author

Not only. Having unknown shapes for the channel dimension breaks TF Keras layers, since the number of variables becomes unknown and cannot be allocated (e.g. the kernel size in a convolutional layer depends on the number of input channels).

@arogozhnikov
Copy link
Owner

@slimm some minimalistic example for tests would help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants