SlideShare a Scribd company logo
What do I want from my
autodiff compiler
Why is this hard?
float x = ...
// ...
float y = ...
float dydx = d(y)/d(x)
some compile-time magic here
Tzu-Mao Li
Goal
• Efficient
• Need to detect common expressions for multiple
derivatives (special case: reverse mode)
• Constants should fold at compile time
• Parallelism (SIMD friendly)
• Bounded memory usage
• Convenient
• Don’t need to change forward code
• Easily handle Jacobian/higher-order derivatives
• General
• Handle non-differentiability by approximation or warning
Theories are there
Pearlmutter and Siskind, 2008
“Reverse-Mode AD in a Functional Framework:
Lambda the Ultimate Backpropagator”
Villard and Monagan, 1998
“Automatic differentiation: an implementation in Maple”
Constants should fold
t6 = x + 2 * y;
t5 = 2 * x + y;
t4 = t6;
t3 = t5 + t6;
t2 = t5;
t1 = t3 + t4;
t0 = t2 + t3;
z = t0 + t1;
• PyTorch and all dynamic taping approaches fail here
• Saved by the fact that in deep learning
all linear combination follows by a nonlinearity
d(z) / d(x) == constant
d(z) / d(y) == constant
Parallelism
• Basically we want to write CUDA/ispc style code and
differentiate them
• Need to handle heterogenous computation
• Race condition
t6 = x + 2 * y;
t5 = 2 * x + y;
t4 = t6;
t3 = t5 + t6;
t2 = t5;
t1 = t3 + t4;
t0 = t2 + t3;
z = t0 + t1;
Bounded memory usage
while (True) {
if (...) {
break;
}
x = ...
y = ...
z = ...
}
while (True) {
if (...) {
break;
}
x = ...
y = ...
z = ...
stack.push({x, y, z});
}
// Run the while loop backward
x, y, z = stack.pop();
while (True) {
if (...) {
break;
}
dx = ...
dy = ...
dz = ...
x, y, z = stack.pop();
}
• Aka checkpointing in AD literature
• Need to let user explore trade-off
Don’t need to change forward
code
• Need a decent parser
• Or a language with strong meta programming ability e.g. Lisp,
Terra
float x = ...
// ...
float y = ...
float dydx = d(y)/d(x)
ad_float x = ...
// ...
ad_float y = ...
ad_float dydx = d(y)/d(x)
Don’t want this
Gets worse with control flow
Easily handle
Jacobian/higher-order
derivatives
float x = ...
float k = ...
// ...
float y = ...
float dydx = d(y)/d(x)
float d2ydxdk = d(dydx)/d(k)
• Tricky to get optimal performance
• NP-hard for arbitrary Jacobian (good heuristics exist)
• Symmetry of Hessian matrix
• Reverse-on-forward mode
• Efficient Jacobian/Hessian vector product
Handle non-differentiability
• e.g. Piecewise-constant function
• Users may not know that their functions are not
differentiable for certain input ranges
• Either automatically approximate or warn the users
• Numerical issues at boundaries: e.g. d/dx sqrt(x) = -
1/sqrt(x) when x->0
Things begin to happen
• Myia
• Tangent
• Python is inefficient

More Related Content

Similar to What do I want from my automatic differentiation compiler

A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16
Max Kleiner
 
Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)
Oky Firmansyah
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
mspline
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018
Zahari Dichev
 
Matlab
MatlabMatlab
Matlab
sandhya jois
 
Matlab
MatlabMatlab
Matlab
sandhya jois
 
C++ theory
C++ theoryC++ theory
C++ theory
Shyam Khant
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
Matthew Ahrens
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
Wei Lin
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
guest3eed30
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
Satalia
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
S N
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
Guy Korland
 
Vectorization in ATLAS
Vectorization in ATLASVectorization in ATLAS
Vectorization in ATLAS
Roberto Agostino Vitillo
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
YashJain47002
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
Jun Young Park
 
Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr - Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr -
PyData
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
Sri Prasanna
 

Similar to What do I want from my automatic differentiation compiler (20)

A closure ekon16
A closure ekon16A closure ekon16
A closure ekon16
 
Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)Introduction to modern c++ principles(part 1)
Introduction to modern c++ principles(part 1)
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018High Performance Systems Without Tears - Scala Days Berlin 2018
High Performance Systems Without Tears - Scala Days Berlin 2018
 
Matlab
MatlabMatlab
Matlab
 
Matlab
MatlabMatlab
Matlab
 
C++ theory
C++ theoryC++ theory
C++ theory
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
 
Language translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlowLanguage translation with Deep Learning (RNN) with TensorFlow
Language translation with Deep Learning (RNN) with TensorFlow
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
Vectorization in ATLAS
Vectorization in ATLASVectorization in ATLAS
Vectorization in ATLAS
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
 
Introduction to PyTorch
Introduction to PyTorchIntroduction to PyTorch
Introduction to PyTorch
 
Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr - Using CNTK's Python Interface for Deep LearningDave DeBarr -
Using CNTK's Python Interface for Deep LearningDave DeBarr -
 
Threaded Programming
Threaded ProgrammingThreaded Programming
Threaded Programming
 

Recently uploaded

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 

Recently uploaded (20)

E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 

What do I want from my automatic differentiation compiler

  • 1. What do I want from my autodiff compiler Why is this hard? float x = ... // ... float y = ... float dydx = d(y)/d(x) some compile-time magic here Tzu-Mao Li
  • 2. Goal • Efficient • Need to detect common expressions for multiple derivatives (special case: reverse mode) • Constants should fold at compile time • Parallelism (SIMD friendly) • Bounded memory usage • Convenient • Don’t need to change forward code • Easily handle Jacobian/higher-order derivatives • General • Handle non-differentiability by approximation or warning
  • 3. Theories are there Pearlmutter and Siskind, 2008 “Reverse-Mode AD in a Functional Framework: Lambda the Ultimate Backpropagator” Villard and Monagan, 1998 “Automatic differentiation: an implementation in Maple”
  • 4. Constants should fold t6 = x + 2 * y; t5 = 2 * x + y; t4 = t6; t3 = t5 + t6; t2 = t5; t1 = t3 + t4; t0 = t2 + t3; z = t0 + t1; • PyTorch and all dynamic taping approaches fail here • Saved by the fact that in deep learning all linear combination follows by a nonlinearity d(z) / d(x) == constant d(z) / d(y) == constant
  • 5. Parallelism • Basically we want to write CUDA/ispc style code and differentiate them • Need to handle heterogenous computation • Race condition t6 = x + 2 * y; t5 = 2 * x + y; t4 = t6; t3 = t5 + t6; t2 = t5; t1 = t3 + t4; t0 = t2 + t3; z = t0 + t1;
  • 6. Bounded memory usage while (True) { if (...) { break; } x = ... y = ... z = ... } while (True) { if (...) { break; } x = ... y = ... z = ... stack.push({x, y, z}); } // Run the while loop backward x, y, z = stack.pop(); while (True) { if (...) { break; } dx = ... dy = ... dz = ... x, y, z = stack.pop(); } • Aka checkpointing in AD literature • Need to let user explore trade-off
  • 7. Don’t need to change forward code • Need a decent parser • Or a language with strong meta programming ability e.g. Lisp, Terra float x = ... // ... float y = ... float dydx = d(y)/d(x) ad_float x = ... // ... ad_float y = ... ad_float dydx = d(y)/d(x) Don’t want this Gets worse with control flow
  • 8. Easily handle Jacobian/higher-order derivatives float x = ... float k = ... // ... float y = ... float dydx = d(y)/d(x) float d2ydxdk = d(dydx)/d(k) • Tricky to get optimal performance • NP-hard for arbitrary Jacobian (good heuristics exist) • Symmetry of Hessian matrix • Reverse-on-forward mode • Efficient Jacobian/Hessian vector product
  • 9. Handle non-differentiability • e.g. Piecewise-constant function • Users may not know that their functions are not differentiable for certain input ranges • Either automatically approximate or warn the users • Numerical issues at boundaries: e.g. d/dx sqrt(x) = - 1/sqrt(x) when x->0
  • 10. Things begin to happen • Myia • Tangent • Python is inefficient