PyTorch Mobile - David Reiss
Key Takeaways
PyTorch Mobile is a version of PyTorch built for Android and iOS, supporting an end-to-end workflow from Python to mobile devices, with features like Torch Script and LibTorch C++ API. The framework enables efficient on-device ML, allowing for lower latency and privacy-preserving techniques like federated learning.
Full Transcript
break was canceled in exchange you get me hi everyone I'm David and I am here to talk about the PI torch mobile experimental release so what is PI torch mobile well it's pi torch for mobile I know that sounds a little bit silly but a lot of the questions we get when we talk about pi torch mobile are did you build a brand new framework are you going to have to or are we gonna have to export our model to a new format are we going to have to port a bunch of operators and the answer to all of those is no so no new framework no model conversion no operator porting this is just PI torch built for Android and iOS and we've made a lot of internal changes to make it work better on mobile but it's still the PI torch that you know and love and we believe that having a unified framework is the best way to enable you all to bring your work from research to production now one decision we did make is not to put a full Python runtime into our mobile build that would have been a little bit crazy so that means that eager mode execution is out of the question on mobile but what we do support is any torch script model so you learned about torch script earlier it's a large and growing subset of Python that can run most Pi torch models and that's the technology that PI torch mobile is built on so if your model is compatible with Lib torch using either tracing or scripting then it can run on mobile and that means that we support all of the control flow constructs and data types that are supported in pipe in torch script so oops yes functions yes tuples yes even name tuples also yes so that all sounds great let's talk about how to use it in case you weren't paying attention to Michael's talk this morning this is how you write a model with torch script and if we zoom in on this section down here it's really just these two lines of code that you have to write and that's it that's going to save your model to a file you can hand that off to a mobile engineer now mobile engineers you want to know how to run this so let's talk about that first you need to add a dependency on PI torch that's a one line configuration on both Android and iOS and that's gonna bring in a pre-built binary that's configured for development now you need to write your code to run the model so let's look at that on Android we have a Java wrapper for Lib torch and that means that you won't have to use the Android NDK you don't even need to install the NDK and I know the NDK is a lot easier to use than it used to be but it can still be intimidating for app developers who are used to programming in Java so we've taken care of all of that for you I just write Java code and this is what it looks like you have your feature vector you wrap it in a tensor you pass that to your model and you extract your data from the output so pretty simple alright now on iOS the API that we expose is the Lib torch C++ API and this gives you the maximum of flexibility and functionality but it means that you're going to have to write a small amount of objective C++ code to bridge between your app which is probably written in objective-c or Swift and Lib torch which is written in C++ but we think this isn't too significant of an overhead because it uses the same tool chain and the same build process as the rest of your iOS app so I'll go through the code if you've used Lib torch before it should look very familiar again feature vector wrap it in a tensor run it through your model and collect your output so it's basically the same four lines of code on both platforms to run your model and I want to show you what it looks like for real so we have some demo apps that we're going to be showing in the demo area this evening there's one on Android one on iOS the first model in them is a text model so you type in some text and it tries to predict which section of reddit that text came from the second model is a vision model that's trained on imagenet so it takes the live image feed from your phone camera and it tries to classify what it thinks it's looking at based on the 1000 class is an image net and in terms of model architecture the text model is based on a multi class classifier using an L TM that we've been testing in one of our production apps at Facebook the image model is based on a quantized mobile net B to Architecture and this really emphasizes the benefit of having a unified framework you can design your model train your model test your model with quantization on the server side and then you can use that same model on mobile because we have the exact same quantization framework same interface same semantics so though there are and there are other PI torch features that will be getting the same treatment so for example you heard about the deep type conversions this morning type promotion this morning and that works as well on mobile and there's also a name tensor which is going to be coming to torch script soon and when that's in torch script it will also be available on mobile so the code for both of the demo apps is available on github right now you can check it out you can use it as a starting point for your own integrations and just as a data point the Android app is a hundred percent Java the iOS app is about 85% Swift so just to recap what we're releasing today full torch script support I want to emphasize that it is the real torch script interpreter that's running on the mobile device there are pre-built binary releases already out in J Center and cocoa pods one line of configuration to install the Java bindings are bundled with the Android version and these releases contain all of the forward operators that have CPU implementations so it should be able to run any of your models because it's basically everything in the kitchen sink type of release now some of these models have some of these operators have already been optimized for mobile the one we paid the most attention to is convolution and the float version has some optimizations that we brought over from cafe to go which is our existing production deep learning framework for mobile and the quantized versions are based on Q&N pack which is a library of highly optimized quantized numerical kernels that we released about a year ago now not all the operators have gotten this optimization treatment so that brings us to what's coming up first and foremost we want to make things faster we think we can squeeze a little more water from the stone of these high-value operators but also find some of the operators that haven't got enough attention and make sure they're running up to speed as well we want to make the release smaller so that the current sort of kitchen sink build weighs in at about five megabytes per architecture and the biggest tool that we have for making that smaller is giving you all the ability to build a customized release of Pi torch mobile that is tailored for your own operators so for example if you're releasing an app that has a bunch of vision models you don't want to be bundling a bunch of code that has text operators in it that's just a waste we're experimenting with a wrapper for Objective C and Swift that we think can lower the barrier to entry for iOS developers even further and we've talked about doing a Kotlin wrapper but that I think is gonna be movin more by community demand because the Java wrapper actually does work pretty well either from Colin there are some more long-term projects as well when I add GPU support so if you've ever programmed a mobile GPU you probably know it's not quite the same it's just running some CUDA kernels but most mobile chips do have a powerful GPU and we want to be able to take advantage of this to accelerate your models and then even even further down that spectrum is neural network accelerators which are starting to show up on some of the newer mobile SOC sees and they can provide even a greater level of performance but often what comes with that is an even greater level of challenge when you're trying to program program them and so if we can sort of hide some of that complexity for you and make it easier for you to run your models on on those parts of a chip that would be fantastic so that's a quick look at what we're planning in terms of what you can do today please visit the mobile page it's linked right from the top of pite org try out the code if you're feeling brave you can ship a production app with it this is an experimental release but we do expect it to work but more importantly tell us how you're using it you know come to the PI torch discussion forum under the mobile topic post about your app let us know what's going well for you and even more importantly what you would like to see improved because we have a lot more work to do and your feedback will help guide our designs and also our priorities thank you very much [Applause]
Original Description
Running ML on edge devices is growing in importance as applications continue to demand lower latency. It is also a foundational element for privacy-preserving techniques such as federated learning. To enable more efficient on-device ML, PyTorch 1.3 now supports an end-to-end workflow from Python to deployment on iOS and Android. Learn more about this early, experimental release.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from PyTorch · PyTorch · 29 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
▶
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is PyTorch?
PyTorch
PyTorch Tutorial: A Quick Preview
PyTorch
PyTorch Summer Hackathon 2019
PyTorch
Tips and Tricks on Hacking with PyTorch: A Quick Tutorial by Brad Heintz
PyTorch
PyTorch 1.2 and PyTorch Hub: A Quick Introduction by Soumith Chintala and Ailing Zhang
PyTorch
Torchtext 0.4 with Supervised Learning Datasets: A Quick Introduction by George Zhang
PyTorch
Torchaudio 0.3 with Kaldi Compatibility, New Transforms: A Quick Introduction by Jason Lian
PyTorch
Torchvision 0.4 with Support for Video: A Quick Introduction by Francisco Massa
PyTorch
Introduction to Machine Learning for Developers at F8 2019
PyTorch
Powered by PyTorch at F8 2019
PyTorch
Developing and Scaling AI Experiences at Facebook with PyTorch at F8 2019
PyTorch
New Approaches to Image and Video Reconstruction Using Deep Learning at Facebook at F8 2019
PyTorch
PyTorch Developer Conference 2018: Recap
PyTorch
PyTorch Developer Conference 2018: Keynote & Deep Dive
PyTorch
PyTorch Developer Conference 2018: Production & Research Sessions
PyTorch
PyTorch Developer Conference 2018: Cloud & Academia Sessions
PyTorch
PyTorch Developer Conference 2018: Enterprise, Education, & Future of AI Panel
PyTorch
PyTorch Developer Conference 2019 | Full Livestream
PyTorch
PyTorch Developer Conference 2019: Recap
PyTorch
PyTorch Developer Conference Keynote - Mike Schroepfer
PyTorch
What’s new in PyTorch 1.3 - Lin Qiao
PyTorch
PyTorch Front-End Features: Named Tensors and Type Promotion - Gregory Chanan
PyTorch
Research to Production: PyTorch JIT/TorchScript Updates - Michael Suo
PyTorch
Quantization - Dmytro Dzhulgakov
PyTorch
PyTorch ONNX Export Support - Lara Haidar, Microsoft
PyTorch
Apex - Michael Carilli, NVIDIA
PyTorch
Dataloader Design for PyTorch - Tongzhou Wang, MIT
PyTorch
Linear Algebra in PyTorch - Vishwak Srinivasan, CMU
PyTorch
PyTorch Mobile - David Reiss
PyTorch
Model Interpretability with Captum - Narine Kokhilkyan
PyTorch
Detectron2 - Next Gen Object Detection Library - Yuxin Wu
PyTorch
Speech Extensions to Fairseq - Dmytro Okhonko
PyTorch
PyTorch on Google Cloud TPUs - Google, Salesforce, Facebook
PyTorch
PyTorch Summer Hackathon Winners - Joe Spisak, Sebastien Arnold, Tristan Deleu
PyTorch
PyTorch in Robotics - Yisong Yue, Caltech
PyTorch
StanfordNLP - Yuhao Zhang, Stanford
PyTorch
Sotabench for Reproducible Research - Robert Stojnic, Papers with Code
PyTorch
Collaborative Natural Language Inference - Sasha Rush, Cornell
PyTorch
Privacy Preserving AI - Andrew Trask, OpenMined
PyTorch
CrypTen - Laurens van der Maaten
PyTorch
PyTorch at Uber - Sidney Zhang, Uber
PyTorch
PyTorch at Tesla - Andrej Karpathy, Tesla
PyTorch
PyTorch at Microsoft - Saurabh Tiwary, Microsoft
PyTorch
PyTorch at Dolby Labs - Vivek Kumar, Dolby Labs
PyTorch
PyTorch Developer Conference 2019 - Panel Discussion
PyTorch
Using deep learning and PyTorch to power next gen aircraft at Caltech
PyTorch
Named Tensors, Model Quantization, and the Latest PyTorch Features - Part 1
PyTorch
TorchScript and PyTorch JIT | Deep Dive
PyTorch
Announcing the PyTorch Global Summer Hackathon 2020
PyTorch
Opening Up the Black Box: Model Understanding with Captum and PyTorch
PyTorch
PyTorch Mobile Runtime for Android
PyTorch
Torchvision in 5 minutes
PyTorch
3D Deep Learning with PyTorch3D
PyTorch
What is Torchtext?
PyTorch
TorchAudio: A Quick Intro
PyTorch
PyTorch Mobile Runtime for iOS
PyTorch
PySlowFast: Deep learning with Video
PyTorch
PyTorch Pruning | How it's Made by Michela Paganini
PyTorch
Measuring Fairness in Machine Learning Systems
PyTorch
PyTorch for Hackathons
PyTorch
More on: LLM Engineering
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Medium · Startup
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Medium · ChatGPT
How to prepare for Spain civil service TIC exam using AI in 2026
Dev.to · David García
Going Viral! How I Created AI Kissing Videos Step by Step Easily Using AIAI.com
Medium · AI
🎓
Tutor Explanation
DeepCamp AI