linear_operator - Structured Linear Algebra in PyTorchLinear Operator at PyTorch Conference 2022
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
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
29
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: ML Maths Basics
View skill →
🎓
Tutor Explanation
DeepCamp AI