linear_operator - Structured Linear Algebra in PyTorchLinear Operator at PyTorch Conference 2022

PyTorch · Beginner ·🔢 Mathematical Foundations ·3y ago

Key Takeaways

The linear_operator library provides structured linear algebra in PyTorch, allowing for efficient computations with specialized linear algebra routines and automatic usage of optimized methods. It can be used as a drop-in replacement for standard tensors in existing PyTorch code, enabling speedups and memory efficiency.

Full Transcript

hey I'm Max um and I'll be telling you about linear operator today a library for structured linear algebra built on Pi torch lots of other folks have contributed to linear operator our main brains here are Jeff and Jake who've worked on this for a while um what is linear operator it is a pytouch library for structural and algebra it's got a number of features that make working with structured tensors easy fast and efficient first linear operator abstracts tensor structure and encodes it in the linear operator object which allows it to automatically use specialized linear algebra routines under the hood without the user needing to reason about them um linear operators compose so potentially complex structured tensors are automatically generated from Primitives and the library implements both specialized exact linear algebra methods for structured tensors as well as fast approximate iterative methods and we'll choose the right one depending on what's needed great so how do you use it um it's easy linear operators look and largely behave like pytorch tensors in this example we create a linear operator a of size A Million by a million that is the sum of a low rank tensor and a diagonal tensor importantly the one by one million by one million Matrix is never actually instantiated yet we can do a bunch of interesting stuff with it namely we can use the standard torch apis on those linearator objects so we can sum across columns add a scalar perform Matrix Vector multiplication or use similar algebra methods such as eye gauge which means that we can use these objects just like we would any other tensors if we have existing code written in pi torch and so what enables us under the hood is that we register the operator's specialized methods to the standard torch namespace functions and then you know since the operator carries around its structure with it we can know what kind of simplifications we can do on the computational side so that allows us to perform computations much more efficiently both in terms of time and memory complexity for instance here in our example a from the previous slide if we call solve on this with some right hand side B then it would automatically use the Woodbury Matrix identity under the hood to compute the solvent o of n time rather than o of n cubed and for n equal a million here this means massive speed UPS not to mention not having to understand to that Matrix let's look at a couple of other examples the first one is on The Chronic obstructure tensors so if a is M by n and B is n by P then the chronicer product is NM by NP torch implements that but only eagerly so if you call torch cron you would instantiate the full tensor K here linear operatives that creates a chronic or product linear operator for lazy evaluation which comes with a number of efficient implementations for common linear algebra operations so in this example we look at a simple Matrix Vector product and we compute the speedups of the linear operator implementation with the naive approach of first forming the chronicle product and then Computing the NVM which is what you probably do if you are not a linear algebra expert the heat map here on the right shows the speed ups for some fixed m equal 10 for very small nnp we don't really see much of a speed up as expected but as nnp increase we do see speedups of more than an order of magnitude memory consumption improves similarly the second example I have here is so-called Monarch matrices these are matrices that are parameterized as the product of two block diagonal matrices plus some permutations they were proposed recently there's an icml paper from this year to make neural network training inference more efficient and so with linear operator implementing such algorithms here is just a few lines of code which illustrates how we can utilize this package to quickly and simply Implement new research ideas simply by composing the so finally let me show you how linear operators can serve as a drop in replacement for standard tensors in existing Pi torch code to exploit the structure so my example here is encoding block diagonal structure in the covariance Matrix of the multivariate normal basically we just make a block diagonlinear operator and stick that into the multivariate normal Constructor so now we can use the resulting distribution just as we would use any other one we can draw samples we can compute log props Etc and so here in this example we use a block dangle Matrix with num blocks blocks Each of which is size n by n so under the hood uh the code calls tortelling like colesky on The covariance Matrix which is a linear operator um so that call is dispatch to the specialized implementation for blocked angle matrices which essentially long story short computes a batch of num blocks classic decompositions and reassembles them um vis-a-vis the you know naive method of computing colesky on the full large Matrix so we get a nice quadratic speed up here we end up with o of num blocks rather than o of non-blocks cubed both for sampling and Computing log probes and I want to emphasize here that this is executing unmodified core Pi torch code the torch function dispatch and the structure awareness of linear operator allow us to get those speed ups and you can use that similarly in other existing code bases as a drop in replacement so what's the catch um well there's two main ones currently the first one is that linear operator is written in pure Python and so iFly involved tensors are very small then it may just be faster to use dense torque sensors the second one is that the main focus so far has been on symmetric positive definite matrices um they're used in kernel methods such as scouting processes where you know some of this this package has its Origins there's no real technical reason for this it's just a matter of doing it and it would be great to get some help from the community to do that that's it please check out our poster at the conference if you can I'd love to judge more and you can learn more about linear operator on its GitHub repo thanks

Original Description

Watch Meta AI's Max Balandat present his poster "linear_operator - Structured Linear Algebra in PyTorchLinear Operator Poster" at PyTorch Conference 2022. linear_operator (https://github.com/cornellius-gp/linear_operator) is a library for structured linear algebra built on PyTorch. It provides a LinearOperator class that represents a tensor that is never instantiated but is instead accessed through operations like matrix multiplication, solves, decompositions, and indexing. These objects use custom linear algebra operations that can exploit particular matrix structure (e.g. diagonal, block-diagonal, triangular, Kronecker, etc.) in computations in order to achieve substantial (many orders of magnitude) improvements in time and memory complexity. Moreover, many efficient linear algebra operations (e.g. solves, decompositions, indexing, etc.) can be automatically generated from the LinearOperator's matmul function. This makes it extremely easy to compose or implement custom LinearOperators. The key aspect that makes linear_operator easy to use in PyTorch code is its integration with the `__torch_function__` interface - Common linear algebra operations (such as matrix multiplication, solve, SVD) are mapped to the respective torch functions (`__matmul__`, `torch.linalg.solve`, `torch.linalg.svd`), so that LinearOperator objects can be used as drop-in replacements for dense tensors even in existing code. LinearOperator operations themselves may return LinearOperator objects, automatically keeping track of algebraic structure after each computation. As a result, users never need to reason about what efficient linear algebra routines to use (so long as the input elements defined by the user encode known input structure). Visit our website: https://pytorch.org/ Read our blog: https://pytorch.org/blog/ Follow us on Twitter: https://twitter.com/PyTorch Follow us on LinkedIn: https://www.linkedin.com/company/pyto... Follow us on Facebook: https://www.facebook.com/pytorc
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from PyTorch · PyTorch · 0 of 60

← Previous Next →
1 What is PyTorch?
What is PyTorch?
PyTorch
2 PyTorch Tutorial: A Quick Preview
PyTorch Tutorial: A Quick Preview
PyTorch
3 PyTorch Summer Hackathon 2019
PyTorch Summer Hackathon 2019
PyTorch
4 Tips and Tricks on Hacking with PyTorch: A Quick Tutorial by Brad Heintz
Tips and Tricks on Hacking with PyTorch: A Quick Tutorial by Brad Heintz
PyTorch
5 PyTorch 1.2 and PyTorch Hub: A Quick Introduction by Soumith Chintala and Ailing Zhang
PyTorch 1.2 and PyTorch Hub: A Quick Introduction by Soumith Chintala and Ailing Zhang
PyTorch
6 Torchtext 0.4 with Supervised Learning Datasets: A Quick Introduction by George Zhang
Torchtext 0.4 with Supervised Learning Datasets: A Quick Introduction by George Zhang
PyTorch
7 Torchaudio 0.3 with Kaldi Compatibility, New Transforms: A Quick Introduction by Jason Lian
Torchaudio 0.3 with Kaldi Compatibility, New Transforms: A Quick Introduction by Jason Lian
PyTorch
8 Torchvision 0.4 with Support for Video: A Quick Introduction by Francisco Massa
Torchvision 0.4 with Support for Video: A Quick Introduction by Francisco Massa
PyTorch
9 Introduction to Machine Learning for Developers at F8 2019
Introduction to Machine Learning for Developers at F8 2019
PyTorch
10 Powered by PyTorch at F8 2019
Powered by PyTorch at F8 2019
PyTorch
11 Developing and Scaling AI Experiences at Facebook with PyTorch at F8 2019
Developing and Scaling AI Experiences at Facebook with PyTorch at F8 2019
PyTorch
12 New Approaches to Image and Video Reconstruction Using Deep Learning at Facebook at F8 2019
New Approaches to Image and Video Reconstruction Using Deep Learning at Facebook at F8 2019
PyTorch
13 PyTorch Developer Conference 2018: Recap
PyTorch Developer Conference 2018: Recap
PyTorch
14 PyTorch Developer Conference 2018: Keynote & Deep Dive
PyTorch Developer Conference 2018: Keynote & Deep Dive
PyTorch
15 PyTorch Developer Conference 2018: Production & Research Sessions
PyTorch Developer Conference 2018: Production & Research Sessions
PyTorch
16 PyTorch Developer Conference 2018: Cloud & Academia Sessions
PyTorch Developer Conference 2018: Cloud & Academia Sessions
PyTorch
17 PyTorch Developer Conference 2018: Enterprise, Education, & Future of AI Panel
PyTorch Developer Conference 2018: Enterprise, Education, & Future of AI Panel
PyTorch
18 PyTorch Developer Conference 2019 | Full Livestream
PyTorch Developer Conference 2019 | Full Livestream
PyTorch
19 PyTorch Developer Conference 2019: Recap
PyTorch Developer Conference 2019: Recap
PyTorch
20 PyTorch Developer Conference Keynote - Mike Schroepfer
PyTorch Developer Conference Keynote - Mike Schroepfer
PyTorch
21 What’s new in PyTorch 1.3 - Lin Qiao
What’s new in PyTorch 1.3 - Lin Qiao
PyTorch
22 PyTorch Front-End Features: Named Tensors and Type Promotion - Gregory Chanan
PyTorch Front-End Features: Named Tensors and Type Promotion - Gregory Chanan
PyTorch
23 Research to Production: PyTorch JIT/TorchScript Updates - Michael Suo
Research to Production: PyTorch JIT/TorchScript Updates - Michael Suo
PyTorch
24 Quantization - Dmytro Dzhulgakov
Quantization - Dmytro Dzhulgakov
PyTorch
25 PyTorch ONNX Export Support - Lara Haidar, Microsoft
PyTorch ONNX Export Support - Lara Haidar, Microsoft
PyTorch
26 Apex -  Michael Carilli, NVIDIA
Apex - Michael Carilli, NVIDIA
PyTorch
27 Dataloader Design for PyTorch - Tongzhou Wang, MIT
Dataloader Design for PyTorch - Tongzhou Wang, MIT
PyTorch
28 Linear Algebra in PyTorch - Vishwak Srinivasan, CMU
Linear Algebra in PyTorch - Vishwak Srinivasan, CMU
PyTorch
29 PyTorch Mobile - David Reiss
PyTorch Mobile - David Reiss
PyTorch
30 Model Interpretability with Captum - Narine Kokhilkyan
Model Interpretability with Captum - Narine Kokhilkyan
PyTorch
31 Detectron2 - Next Gen Object Detection Library - Yuxin Wu
Detectron2 - Next Gen Object Detection Library - Yuxin Wu
PyTorch
32 Speech Extensions to Fairseq - Dmytro Okhonko
Speech Extensions to Fairseq - Dmytro Okhonko
PyTorch
33 PyTorch on Google Cloud TPUs - Google, Salesforce, Facebook
PyTorch on Google Cloud TPUs - Google, Salesforce, Facebook
PyTorch
34 PyTorch Summer Hackathon Winners - Joe Spisak, Sebastien Arnold, Tristan Deleu
PyTorch Summer Hackathon Winners - Joe Spisak, Sebastien Arnold, Tristan Deleu
PyTorch
35 PyTorch in Robotics - Yisong Yue, Caltech
PyTorch in Robotics - Yisong Yue, Caltech
PyTorch
36 StanfordNLP - Yuhao Zhang, Stanford
StanfordNLP - Yuhao Zhang, Stanford
PyTorch
37 Sotabench for Reproducible Research - Robert Stojnic, Papers with Code
Sotabench for Reproducible Research - Robert Stojnic, Papers with Code
PyTorch
38 Collaborative Natural Language Inference - Sasha Rush, Cornell
Collaborative Natural Language Inference - Sasha Rush, Cornell
PyTorch
39 Privacy Preserving AI - Andrew Trask, OpenMined
Privacy Preserving AI - Andrew Trask, OpenMined
PyTorch
40 CrypTen - Laurens van der Maaten
CrypTen - Laurens van der Maaten
PyTorch
41 PyTorch at Uber - Sidney Zhang, Uber
PyTorch at Uber - Sidney Zhang, Uber
PyTorch
42 PyTorch at Tesla - Andrej Karpathy, Tesla
PyTorch at Tesla - Andrej Karpathy, Tesla
PyTorch
43 PyTorch at Microsoft - Saurabh Tiwary, Microsoft
PyTorch at Microsoft - Saurabh Tiwary, Microsoft
PyTorch
44 PyTorch at Dolby Labs - Vivek Kumar, Dolby Labs
PyTorch at Dolby Labs - Vivek Kumar, Dolby Labs
PyTorch
45 PyTorch Developer Conference 2019 - Panel Discussion
PyTorch Developer Conference 2019 - Panel Discussion
PyTorch
46 Using deep learning and PyTorch to power next gen aircraft at Caltech
Using deep learning and PyTorch to power next gen aircraft at Caltech
PyTorch
47 Named Tensors, Model Quantization, and the Latest PyTorch Features - Part 1
Named Tensors, Model Quantization, and the Latest PyTorch Features - Part 1
PyTorch
48 TorchScript and PyTorch JIT | Deep Dive
TorchScript and PyTorch JIT | Deep Dive
PyTorch
49 Announcing the PyTorch Global Summer Hackathon 2020
Announcing the PyTorch Global Summer Hackathon 2020
PyTorch
50 Opening Up the Black Box: Model Understanding with Captum and PyTorch
Opening Up the Black Box: Model Understanding with Captum and PyTorch
PyTorch
51 PyTorch Mobile Runtime for Android
PyTorch Mobile Runtime for Android
PyTorch
52 Torchvision in 5 minutes
Torchvision in 5 minutes
PyTorch
53 3D Deep Learning with PyTorch3D
3D Deep Learning with PyTorch3D
PyTorch
54 What is Torchtext?
What is Torchtext?
PyTorch
55 TorchAudio: A Quick Intro
TorchAudio: A Quick Intro
PyTorch
56 PyTorch Mobile Runtime for iOS
PyTorch Mobile Runtime for iOS
PyTorch
57 PySlowFast: Deep learning with Video
PySlowFast: Deep learning with Video
PyTorch
58 PyTorch Pruning | How it's Made by Michela Paganini
PyTorch Pruning | How it's Made by Michela Paganini
PyTorch
59 Measuring Fairness in Machine Learning Systems
Measuring Fairness in Machine Learning Systems
PyTorch
60 PyTorch for Hackathons
PyTorch for Hackathons
PyTorch

The linear_operator library in PyTorch enables efficient computations with structured linear algebra, providing a drop-in replacement for standard tensors in existing code. It automatically uses optimized methods and specialized linear algebra routines, resulting in significant speedups and memory efficiency.

Key Takeaways
  1. Import the linear_operator library in PyTorch
  2. Create a linear operator object with the desired structure
  3. Use standard PyTorch APIs on the linear operator object
  4. Utilize specialized linear algebra routines for efficient computations
  5. Apply the linear operator to existing PyTorch code as a drop-in replacement
💡 The linear_operator library can automatically use optimized methods and specialized linear algebra routines, resulting in significant speedups and memory efficiency without requiring manual implementation.

Related Reads

Up next
Solve Any Math Problem Step by Step — Free (Type or Snap a Photo)
Zariga Tongy
Watch →