You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "jikechao (via GitHub)" <gi...@apache.org> on 2023/04/26 10:12:39 UTC
[GitHub] [tvm] jikechao opened a new pull request, #14724: [bugfix][keras] fix wrong documentation and add layout checking
jikechao opened a new pull request, #14724:
URL: https://github.com/apache/tvm/pull/14724
This pr fixes 2 questions.
1. The wrong documentation about attribute `layout` in `from_keras()`.
By analysis the source code [Here](https://github.com/jikechao/tvm/blob/main_abc/python/tvm/relay/frontend/keras.py#:~:text=assert%20layout%20in,NHWC%20or%20NDHWC%22), we can find that `input_layout` has 4 valid values (e.g, 'NWC', 'NCHW', NHWC and NDHWC"). However, in the [source code comments](https://github.com/jikechao/tvm/blob/main_abc/python/tvm/relay/frontend/keras.py#:~:text=layout%3A%20str,better%20across%20TVM.) and [official documentation](https://tvm.apache.org/docs/reference/api/python/relay/frontend.html?highlight=from_keras#tvm.relay.frontend.from_keras:~:text=layout%20(str)%20%E2%80%93%20One%20of%20%E2%80%98NCHW%E2%80%99%20or%20%E2%80%98NHWC%E2%80%99%2C%20indicates%20how%20data%20should%20be%20arranged%20in%20the%20output%20model.%20Default%20layout%20is%20%E2%80%98NCHW%E2%80%99%20as%20it%20in%20general%20performs%20better%20across%20TVM.) , it says only 'nchw' and 'nhwc' are supported. They are conflicted.
2. Add exception checking to reject the mismatched `layout` and `input_shape` immediately.
For the following script: relay can convert the keras model to RelayIR successful, It crashed when executed the last statements (e.g., `model = model.evaluate()`) in the script and throw: "Check failed: (!axes.defined() || static_cast<int>(axes.size()) == ndim) is false: Dimension mismatch: axes has 4 elements, but data.ndim = 3". This exception checking is too late, and the crash message will increase the difficulty of debugging. Thus, I added an exception checking in keras importer and give a clear exception message.
```
import tvm
import tvm.relay as relay
import numpy as np
from tensorflow import keras
from tensorflow.keras import layers, models
input_shape = (1, 2, 3)
input_data = np.random.random(input_shape)
x = layers.Input(shape=input_shape[1:], dtype='float32')
layer = keras.layers.Flatten()
layer.set_weights(layer.get_weights())
y = layer(x)
model = models.Model(x, y)
shape_dict = {'input_1': input_shape}
mod, params = relay.frontend.from_keras(model, shape_dict) # convert to RelayIR successfully.
print(mod)
with tvm.transform.PassContext(opt_level=3):
model = relay.build_module.create_executor("vm", mod, tvm.cpu(0), 'llvm', params)
model = model.evaluate() # crash here!!!
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] jikechao commented on pull request #14724: [bugfix][keras] fix wrong documentation and add layout checking
Posted by "jikechao (via GitHub)" <gi...@apache.org>.
jikechao commented on PR #14724:
URL: https://github.com/apache/tvm/pull/14724#issuecomment-1527776596
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tvm-bot commented on pull request #14724: [bugfix][keras] fix wrong documentation and add layout checking
Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #14724:
URL: https://github.com/apache/tvm/pull/14724#issuecomment-1523166026
<!---bot-comment-->
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](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
<!--bot-comment-ccs-start-->
* No users to tag found in teams: `bugfix`, `keras` <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
<sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [bugfix][Relay] fix wrong documentation and add layout checking in keras frontend [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed pull request #14724: [bugfix][Relay] fix wrong documentation and add layout checking in keras frontend
URL: https://github.com/apache/tvm/pull/14724
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] jikechao commented on pull request #14724: [bugfix][keras] fix wrong documentation and add layout checking
Posted by "jikechao (via GitHub)" <gi...@apache.org>.
jikechao commented on PR #14724:
URL: https://github.com/apache/tvm/pull/14724#issuecomment-1524861301
This PR led to many test cases crashing. Thus, I'm confused if this fix is valid. Wish for your comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] jikechao closed pull request #14724: [bugfix][keras] fix wrong documentation and add layout checking
Posted by "jikechao (via GitHub)" <gi...@apache.org>.
jikechao closed pull request #14724: [bugfix][keras] fix wrong documentation and add layout checking
URL: https://github.com/apache/tvm/pull/14724
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org