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

[AutoTVM] Tuning fails for an NHWC network on Arm CPU #4542

Closed
mbaret opened this issue Dec 18, 2019 · 8 comments
Closed

[AutoTVM] Tuning fails for an NHWC network on Arm CPU #4542

mbaret opened this issue Dec 18, 2019 · 8 comments

Comments

@mbaret
Copy link
Contributor

mbaret commented Dec 18, 2019

I'm trying to tune NHWC networks produced by the tflite frontend, but they fail with the error AssertionError: only support NCHW/HWCN currently. This suggests to me the AlterOpLayout pass is not happening during task extraction. I can force the AlterOpLayout pass to happen using the following patch:

--- a/python/tvm/autotvm/task/relay_integration.py
+++ b/python/tvm/autotvm/task/relay_integration.py
@@ -49,7 +49,9 @@ def _lower(func,
                 grc = graph_runtime_codegen.GraphRuntimeCodegen(None, target)
                 return grc.codegen(mod["main"])
     # default case
-    mod, _ = relay.optimize(func, target, params)
+    with relay.build_config(opt_level=3):
+        mod, _ = relay.optimize(func, target, params)
+
     grc = graph_runtime_codegen.GraphRuntimeCodegen(None, target)
     return grc.codegen(mod["main"])

which does fix this issue. Am I doing something wrong in AutoTVM or is this patch necessary?

@jwfromm
Copy link
Contributor

jwfromm commented Dec 18, 2019

You're not doing anything wrong. Not supporting NHWC layouts on Arm CPUs is a known issue and something we should have patched in soon.

@mbaret
Copy link
Contributor Author

mbaret commented Dec 18, 2019

I think even if NHWC isn't supported, the auto-tuning shouldn't fail as a result. We can still compile networks that are initially in NHWC format as AlterOpLayout converts them to NCHW. I think AutoTVM should also do this instead of just failing.

@comaniac
Copy link
Contributor

AutoTVM does not compile the model but just tune the ops extracted from the model. Accordingly, failing when the ops are not supported for tuning is reasonable.

Also please open such discussion topics in discuss.

@mbaret
Copy link
Contributor Author

mbaret commented Dec 18, 2019

It doesn't compile, but it does run optimize which should invoke the appropriate passes to transform the graph. Is it a design choice for AutoTVM not to apply this pass? If so I'm happy to open a discuss post, as this is quite unintuitive behaviour.

@comaniac
Copy link
Contributor

Not sure if that workaround works for all cases, but you are welcome to open an RFC to collect opinions from others.

@FrozenGene
Copy link
Member

Please keep an eye of PR #3859 , which could solve TFLite NHWC auto tune on ARM CPU problem.

@anijain2305
Copy link
Contributor

anijain2305 commented Dec 26, 2019

I agree that AlterOpLayout and AutoTVM do not have the most intuitive design/user experience yet.

For now, you can choose either of the 3 options

  1. Use the [TOPI][AutoTVM] NHWC conv2d templates for ARM #3859 to use NHWC schedule. However, it might not give you the best performance because for now NCHW perf is somewhat better than NHWC.
  2. Call AlterOpLayout pass the way you did before extracting tasks.
  3. In general, use the [Relay] ConvertLayout pass. #4335 ConvertLayout to convert the whole graph to NCHW and then call AutoTVM extraction. Similarly, after AutoTVM is done, before calling the relay.build, call ConvertLayout.

@tqchen
Copy link
Member

tqchen commented May 11, 2020

close for now due to inactive status, and there are related #3859 feel free to open new thread on the discuss forum

@tqchen tqchen closed this as completed May 11, 2020
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

No branches or pull requests

6 participants