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

[Bugfix][Frontend][Keras]Fix a corner case bug in softmax converter of keras frontend #15337

Merged
merged 3 commits into from
Jul 18, 2023

Conversation

jikechao
Copy link
Contributor

@jikechao jikechao commented Jul 17, 2023

This PR fixes a corner bug in the softmax converter in the Keras frontend.
If the input dimension of softmax is 1, TVM will crash unexpectedly.

StackTrace

Traceback (most recent call last):
  File "test.py", line 25, in <module>
    mod, params = relay.frontend.from_keras(model, shape_dict)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", line 1565, in from_keras
    _convert_layer(keras_layer, etab)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", line 1519, in _convert_layer
    layout,
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", line 1394, in keras_op_to_relay
    outs = _convert_map[op_name](inexpr, keras_layer, etab, data_layout)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", line 134, in _convert_advanced_activation
    dims = len(input_shape)
TypeError: object of type 'NoneType' has no len()

Steps to reproduce

import tvm
import tvm.relay as relay
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers, models

input_shape = (11,)
input_data = np.random.random(size=input_shape)
dtype = 'float32'

x = layers.Input(shape=input_shape[1:], dtype=dtype)

layer = keras.layers.Softmax()
layer.set_weights(layer.get_weights())

y = layer(x)
model = models.Model(x, y)
res_keras = model.predict(input_data)
print(model.summary())

res_keras2 = model(input_data)

shape_dict = {'input_1': input_shape}
mod, params = relay.frontend.from_keras(model, shape_dict)
print(mod)

cc @echuraev @Hzfengsy @leandron

@tvm-bot
Copy link
Collaborator

tvm-bot commented Jul 17, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: bugfix, frontend, keras See #10317 for details

Generated by tvm-bot

@jikechao jikechao changed the title [Bugfix][Frontend][Keras]Fix a corner case in softmax converter [Bugfix][Frontend][Keras]Fix a corner case bug in softmax converter of keras frontend Jul 17, 2023
Copy link
Contributor

@echuraev echuraev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@echuraev echuraev merged commit e2d6511 into apache:main Jul 18, 2023
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 24, 2023
…f keras frontend (apache#15337)

* Fix softmax converter about keras

* add new test cases to capture the bug

* Update keras.py
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 27, 2023
…f keras frontend (apache#15337)

* Fix softmax converter about keras

* add new test cases to capture the bug

* Update keras.py
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jul 30, 2023
…f keras frontend (apache#15337)

* Fix softmax converter about keras

* add new test cases to capture the bug

* Update keras.py
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.

4 participants