-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add NNAPI tutorial #1229
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
Add NNAPI tutorial #1229
Conversation
Deploy preview for pytorch-tutorials-preview ready! Built with commit f8791e5 https://deploy-preview-1229--pytorch-tutorials-preview.netlify.app |
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.
Half way thru the PR and got errors when running the script. The right torch and torchvision versions and setup info would be helpful. Thanks
NNAPI provides access to powerful and efficient computational cores | ||
on many modern Android devices. | ||
|
||
PyTorch's NNAPI is currently in the "prototype" phase and only supports |
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.
Should a developer who wants to try this prototype feature go to the PyTorch master branch?
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.
Updating to reference the specific version that is known to work.
First, we must prepare our model to execute with NNAPI. | ||
This step runs on your training server or laptop. | ||
The key conversion function to call is | ||
``torch.backends._nnapi.prepare.convert_model_to_nnapi``, |
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.
Is there a link to the convert_model_to_nnapi
documentation?
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.
No. This still needs to be written.
but some extra steps are required to ensure that | ||
the model is properly structured. | ||
Most notably, quantizing the model is required | ||
in order to run the model on certain hardware backends. |
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 we be more specific on the hardware backends that can run a quantized model? Is quantization required to run on certain hardware backends but:
a. not required on others, or
b. on some other hardware backends, even quantizing a model won't make the model run?
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.
Clarified that this refers to accelerators.
# - "none": Fully floating-point model. | ||
# - "core": Quantize the core of the model, but wrap it a | ||
# quantizer/dequantizer pair, so the interface uses floating point. | ||
# - "full": Quantize the model, and use quantize tensors |
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.
quantize tensors => quantized tensors
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.
Thanks.
import torch | ||
import torch.utils.bundled_inputs | ||
import torch.utils.mobile_optimizer | ||
import torch.backends._nnapi.prepare |
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.
Which PyTorch and torchvision versions are required to run this? I built and installed PyTorch from the master branch on Oct 22, got an error "ModuleNotFoundError: No module named 'torch.backends._nnapi'". Then I built from the latest pytorch master branch, and got a new error when running the script:
Exception: Unsupported node kind ('aten::size') in node %13 : int = aten::size(%input.88, %32) # /Users/jeffxtang/opt/anaconda3/lib/python3.8/site-packages/torchvision/models/mobilenet.py:166:0
I then installed torchvision from the latest source but the script still picks the older 0.7...
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.
Updated instructions to reference the specific known-working version.
|
||
Because these models have bundled inputs, we can run the benchmark as follows: | ||
|
||
.. code:: shell |
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.
The code below doesn't show in the preview, maybe due to some format issue. code => code-block?
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.
Corrected.
|
||
Now that the models are ready, we can benchmark them on our Android devices. | ||
See `our performance recipe <https://pytorch.org/tutorials/recipes/mobile_perf.html#android-benchmarking-setup>`_ for details. | ||
The best-performing models are likely to be the "fully-quantized" models: |
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'd be great to show benchmark data here.. maybe in a future update.
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.
Yeah. I'll add this after the blog post goes live.
4ea1ee0
to
f8791e5
Compare
No description provided.