-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[DOC] Add Android Tutorial #2977
Conversation
Jenkins had failed when building a document, so I tried to write minimal code that reproduced the Jenkins build. Command to reproduce
However, When I limited this tutorial to build, it completed successfully. -PYTHONPATH=`pwd`/../python make -C docs html
+PYTHONPATH=`pwd`/../python TVM_TUTORIAL_EXEC_PATTERN=deploy_model_on_android\.py make -C docs html The error is happening at WARNING: /workspace/tutorials/frontend/deploy_model_on_android.py failed to execute correctly: Traceback (most recent call last):
File "/workspace/tutorials/frontend/deploy_model_on_android.py", line 249, in <module>
target_host=target_host, params=params)
File "/workspace/docs/../python/tvm/relay/build_module.py", line 276, in build
func = optimize(func, target, params)
File "/workspace/docs/../python/tvm/relay/build_module.py", line 163, in optimize
func = ir_pass.infer_type(func)
File "/workspace/docs/../python/tvm/relay/ir_pass.py", line 353, in infer_type
return _ir_pass.infer_type(expr, mod)
File "/workspace/docs/../python/tvm/_ffi/_ctypes/function.py", line 190, in __call__
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (8) /workspace/build/libtvm.so(+0x4ac55f) [0x7fd6fda7c55f]
[bt] (7) /workspace/build/libtvm.so(+0x65defd) [0x7fd6fdc2defd]
[bt] (6) /workspace/build/libtvm.so(+0x65ea8d) [0x7fd6fdc2ea8d]
[bt] (5) /workspace/build/libtvm.so(+0x49349a) [0x7fd6fda6349a]
[bt] (4) /workspace/build/libtvm.so(+0x4861c4) [0x7fd6fda561c4]
[bt] (3) /workspace/build/libtvm.so(+0x4a5de3) [0x7fd6fda75de3]
[bt] (2) /workspace/build/libtvm.so(+0x4a5b03) [0x7fd6fda75b03]
[bt] (1) /workspace/build/libtvm.so(+0x4a3017) [0x7fd6fda73017]
[bt] (0) /workspace/build/libtvm.so(+0x151512) [0x7fd6fd721512]
File "/workspace/src/relay/pass/type_infer.cc", line 620
TVMError: Check failed: checked_type.as<IncompleteTypeNode>() == nullptr: Cannot resolve type of Var(input_2) at (nullptr) |
I found by dumping Relay IR that when called independently it would be -%212 = fn (%input_1: Tensor[(1, 3, 224, 224), float32], %v_param_1: Tensor[(16, 3, 3, 3), float32],
+%212 = fn (%input_2, %v_param_1: Tensor[(16, 3, 3, 3), float32], |
I have fixed by inserting the following, to clear the TF session. keras.backend.clear_session() |
@grwlf @eqy please review |
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.
Overall I think this looks good at a high level. The main issue I run into with android is that it is often possible to generate libraries that will cause an application to crash when loaded/run on an actual device.
ctx = remote.cpu(0) | ||
elif test_target == 'opencl': | ||
ctx = remote.cl(0) | ||
elif test_target == 'vulkan': |
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.
Can you confirm if Vulkan works on your device? What device are you targeting?
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.
My device is Xiaomi Mi 5. It has Snapdragon 820 / Adreno 530 and supports Vulkan.
I found the same device report. https://vulkan.gpuinfo.org/displayreport.php?id=3653
shape_dict = {input_name: x.shape} | ||
func, params = relay.frontend.from_keras(keras_mobilenet_v2, shape_dict) | ||
|
||
with relay.build_config(opt_level=1): |
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.
Why do we use opt_level 1 here?
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.
When I was developing, there was a model that could not be built with opt_level = 1
, but with the current sample it also worked with opt_level = 3
So I want to change it. As a result, Vulkan got a little faster.
-with relay.build_config(opt_level=1):
+with relay.build_config(opt_level=3):
# # cpu
# TVM prediction top-1: tiger cat
# Evaluate inference time cost...
-# Mean inference time (std dev): 38.89 ms (6.48 ms)
+# Mean inference time (std dev): 37.92 ms (19.67 ms)
#
# # opencl
# TVM prediction top-1: tiger cat
# Evaluate inference time cost...
-# Mean inference time (std dev): 418.82 ms (3.65 ms)
+# Mean inference time (std dev): 419.83 ms (7.49 ms)
#
# # vulkan
# TVM prediction top-1: tiger cat
# Evaluate inference time cost...
-# Mean inference time (std dev): 511.98 ms (4.53 ms)
+# Mean inference time (std dev): 465.80 ms (4.52 ms)
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.
done -> 1f908a9
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.
It is not an important detail for this PR, but did you do tuning for the GPU configs? It seems strange that the performance would be so far behind CPU.
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.
It is not this model, but I have used auto tuning. But unfortunately I remember that it was not faster than CPU.
Now, setting target = 'opencl'
seems to use a schedule for CUDA. So I think I need a schedule for Adreno, and I'm writing a bit for myself, using this as a reference.
Do you know if there are plans to develop for Adreno at dmlc/tvm or neo-ai/tvm?
thanks @tkat0, this is merged |
* fix APP_STL for latest android ndk * add vulkan sdk for tutorial * add android tutorial * fix of invalid input layer name * update relay build opt_level 1 -> 3
* fix APP_STL for latest android ndk * add vulkan sdk for tutorial * add android tutorial * fix of invalid input layer name * update relay build opt_level 1 -> 3
Hello. I am the author of tkat0/chainer-nnvm-example.
Thank you for referring from the official document.
I wanted to include a tutorial for Android in the official Tutorial, and I sent a PR.
The above repository used NNVM, but I created a tutorial using Relay.
I build a document with the following command and uploaded it here.
I confirmed that the document looks good.
docker/bash.sh tvmai/ci-gpu:v0.51 TVM_TUTORIAL_EXEC_PATTERN=deploy_model_on_android\.py make -C docs html
Thank you.