-
Notifications
You must be signed in to change notification settings - Fork 328
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
Update group_normalization.py #1035
Conversation
[/usr/local/lib/python3.7/dist-packages/keras_cv/models/generative/stable_diffusion/__internal__/layers/group_normalization.py](https://localhost:8080/#) in _create_broadcast_shape(self, input_shape) 85 86 def _create_broadcast_shape(self, input_shape): ---> 87 broadcast_shape = [1] * len(input_shape) 88 broadcast_shape[self.axis] = input_shape[self.axis] // self.groups TypeError: Exception encountered when calling layer 'group_normalization_60' (type GroupNormalization). len is not well defined for a symbolic Tensor (Shape:0). Please call `x.shape` rather than `len(x)` for shape information. Call arguments received by layer 'group_normalization_60' (type GroupNormalization): • args=('tf.Tensor(shape=(None, 64, 64, 320), dtype=float32)',) • kwargs=<class 'inspect._empty'>
@LukeWood @ianstenbit Why this was not already catched by our |
Thanks @charbull! I'd like to eventually update our SD implementation to use Keras GroupNorm instead of our own, but that'll add a 2.11 dependency which I don't think we want to do just yet. I am going to manually test this change against some SD workflows (too large to run on GitHub tests). If they look good, I will merge this. @bhack - I suspect we didn't encounter this because this seems to be TFLite specific? |
/gcbrun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM -- thank you!
My test workflows all look good with this change, and it seems like a low-risk improvement
[/usr/local/lib/python3.7/dist-packages/keras_cv/models/generative/stable_diffusion/__internal__/layers/group_normalization.py](https://localhost:8080/#) in _create_broadcast_shape(self, input_shape) 85 86 def _create_broadcast_shape(self, input_shape): ---> 87 broadcast_shape = [1] * len(input_shape) 88 broadcast_shape[self.axis] = input_shape[self.axis] // self.groups TypeError: Exception encountered when calling layer 'group_normalization_60' (type GroupNormalization). len is not well defined for a symbolic Tensor (Shape:0). Please call `x.shape` rather than `len(x)` for shape information. Call arguments received by layer 'group_normalization_60' (type GroupNormalization): • args=('tf.Tensor(shape=(None, 64, 64, 320), dtype=float32)',) • kwargs=<class 'inspect._empty'>
opening a pull request to fix the len while saving the model as suggested by @freedomtan
reference context: #1033
specific issue: #1034
/usr/local/lib/python3.7/dist-packages/keras_cv/models/generative/stable_diffusion/internal/layers/group_normalization.py in _create_broadcast_shape(self, input_shape)
85
86 def _create_broadcast_shape(self, input_shape):
---> 87 broadcast_shape = [1] * len(input_shape)
88 broadcast_shape[self.axis] = input_shape[self.axis] // self.groups
TypeError: Exception encountered when calling layer 'group_normalization_60' (type GroupNormalization).
len is not well defined for a symbolic Tensor (Shape:0). Please call
x.shape
rather thanlen(x)
for shape information.Call arguments received by layer 'group_normalization_60' (type GroupNormalization):
• args=('tf.Tensor(shape=(None, 64, 64, 320), dtype=float32)',)
• kwargs=<class 'inspect._empty'>
What does this PR do?
changes from len(input) to input.shape.rank
Fixes # (issue)
#1034
Before submitting
Pull Request section?
to it if that's the case.
The issue discussed with @LukeWood. This is just a minor patch.