PyTorch: An Imperative Style, High-Performance Deep Learning Library
Summary
Deep learning frameworks have usually made users choose. Graph-based tools such as TensorFlow, Caffe, CNTK and Theano gain speed by building a static computation graph before running it. Eager, define-by-run tools like Chainer are easier to write and debug but have been slower. This NeurIPS 2019 paper presents PyTorch, a Python library that runs tensor operations immediately, with automatic differentiation and GPU support. It also explains the design ideas and runtime engineering that let PyTorch match graph-based tools on speed. Models, optimizers and data loaders are all plain Python code, so standard debuggers, print statements and libraries such as NumPy work with them directly. On the speed side, the CPU queues GPU work asynchronously, a caching allocator reuses GPU memory, and heavy computation goes to cuDNN and cuBLAS. In single-machine benchmarks on six common models, PyTorch came within 17% of the fastest framework every time. Its rapid uptake by researchers suggests that ease of use and high performance can coexist.
Key points
- Design principles: be Pythonic, put researchers first, give pragmatic performance (losing about 10% speed for a much simpler interface is acceptable, losing 100% is not) and "worse is better," meaning simple internals are preferred over complex, complete ones.
- Interoperability:
torch.from_numpy()/.numpy()and DLPack share memory with other libraries without copying data. Users can extend the library by subclassingtorch.autograd.Functionortorch.utils.data.Dataset. - Runtime behaviour: in a ResNet-50 trace, the CPU queues work faster than the GPU can run it, so the GPU stays almost fully busy (GPU execution took about 3× as long as CPU scheduling). After the first iteration, the caching allocator removes slow
cudaMalloc/cudaFreecalls. - Benchmarks (FP32 training throughput): comparison against Chainer, CNTK, MXNet, PaddlePaddle and TensorFlow on AlexNet, VGG-19, ResNet-50, MobileNet, GNMTv2 and NCF. PyTorch was fastest on VGG-19 (119 img/s), GNMTv2 (15,512 vs 9,631 tokens/s for TensorFlow) and NCF (5.4e6 vs 4.8e6 samples/s for TensorFlow).
- Adoption: 296 ICLR 2019 submissions mentioned PyTorch. Its share of framework mentions on arXiv rose steadily after the January 2017 release. Planned work includes the PyTorch JIT and better distributed and model-parallel training.
Cited by
- gpt-oss-120b & gpt-oss-20b Model Card
- Dotless Representation of Arabic Text: Analysis and Modeling
- Hybrid Deep Learning and Signal Processing for Arabic Dialect Recognition in Low-Resource Settings
- LLM in a flash: Efficient Large Language Model Inference with Limited Memory
- ArbESC+: Arabic Enhanced Edit Selection System Combination for Grammatical Error Correction Resolving conflict and improving system combination in Arabic GEC
- Investigating Persuasion Techniques in Arabic: An Empirical Study Leveraging Large Language Models
- AraCOVID19-MFH: Arabic COVID-19 Multi-label Fake News and Hate Speech Detection Dataset
- AraCOVID19-SSD: Arabic COVID-19 Sentiment and Sarcasm Detection Dataset
- Open-Domain Question Answering Goes Conversational via Question Rewriting
- Refusal in Language Models Is Mediated by a Single Direction
- Probing Pre-Trained Language Models for Cross-Cultural Differences in Values
- Evidentiality-guided Generation for Knowledge-Intensive NLP Tasks
- QuaRot: Outlier-Free 4-Bit Inference in Rotated LLMs
- Knowledge-Augmented Language Model Prompting for Zero-Shot Knowledge Graph Question Answering
- Can RNNs trained on harder subject-verb agreement instances still perform well on easier ones?
- On the Opportunities and Risks of Foundation Models
- Cross-document Coreference Resolution over Predicted Mentions
- LongLoRA: Efficient Fine-tuning of Long-Context Large Language Models
- Neural End-to-end Coreference Resolution for German in Different Domains
- RobBERT: a Dutch RoBERTa-based Language Model
- ERASER: A Benchmark to Evaluate Rationalized NLP Models
- Few-NERD: A Few-shot Named Entity Recognition Dataset
- OpenPrompt: An Open-source Framework for Prompt-learning
- Word-Level Coreference Resolution
- From Pretraining Data to Language Models to Downstream Tasks: Tracking the Trails of Political Biases Leading to Unfair NLP Models
- SPLADE: Sparse Lexical and Expansion Model for First Stage Ranking
- A Multi-Task Benchmark for Abusive Language Detection in Low-Resource Settings
- Condenser: a Pre-training Architecture for Dense Retrieval
- Unsupervised Corpus Aware Language Model Pre-training for Dense Passage Retrieval
- 大语言模型预训练系统关键技术综述
- RealToxicityPrompts: Evaluating Neural Toxic Degeneration in Language Models
- JABER and SABER: Junior and Senior Arabic BERt
- Revisiting Pre-trained Language Models and their Evaluation for Arabic Natural Language Understanding
- On the importance of Data Scale in Pretraining Arabic Language Models
- Massive Choice, Ample Tasks (MaChAmp): A Toolkit for Multi-task Learning in NLP
- Applying Occam's Razor to Transformer-Based Dependency Parsing: What Works, What Doesn't, and What is Really Necessary
- TriFine: A Large-Scale Dataset of Vision-Audio-Subtitle for Tri-Modal Machine Translation and Benchmark with Fine-Grained Annotated Tags
- HippoRAG: Neurobiologically Inspired Long-Term Memory for Large Language Models
- Coreference for Discourse Parsing: A Neural Approach
- Unleashing the Power of Neural Discourse Parsers - A Context and Structure Aware Approach Using Large Scale Pretraining
- Cross-Domain Label-Adaptive Stance Detection
- Focus on what matters: Applying Discourse Coherence Theory to Cross Document Coreference
- Efficient Attentions for Long Document Summarization
- MLAgentBench: Evaluating Language Agents on Machine Learning Experimentation
- Editing Models with Task Arithmetic
- Adaptive-RAG: Learning to Adapt Retrieval-Augmented Large Language Models through Question Complexity
- MetricX-23: The Google Submission to the WMT 2023 Metrics Shared Task
- MetricX-24: The Google Submission to the WMT 2024 Metrics Shared Task
- Investigating the Performance of Transformer-Based NLI Models on Presuppositional Inferences
- DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines
- The Hateful Memes Challenge: Detecting Hate Speech in Multimodal Memes
- A Simple and Strong Baseline for End-to-End Neural RST-style Discourse Parsing
- Large language models are zero-shot reasoners
- A Context-Dependent Gated Module for Incorporating Symbolic Semantics into Event Coreference Resolution
- PAQ: 65 Million Probably-Asked Questions and What You Can Do With Them
- PyTorch Distributed: Experiences on Accelerating Data Parallel Training
- Contextualized Perturbation for Textual Adversarial Attack
- BLIP: Bootstrapping Language-Image Pre-training for Unified Vision-Language Understanding and Generation
- Distilling Calibrated Knowledge for Stance Detection
- Symbolic Chain-of-Thought Distillation: Small Models Can Also “Think” Step-by-Step
- DataComp-LM: In search of the next generation of training sets for language models
- Multilingual Neural RST Discourse Parsing
- Coreference-Aware Dialogue Summarization
- Improving Multi-Party Dialogue Discourse Parsing via Domain Integration
- Linguistic Rules-Based Corpus Generation for Native Chinese Grammatical Error Correction
- Noisy Channel Language Model Prompting for Few-Shot Text Classification
- An End-to-End OCR Framework for Robust Arabic-Handwriting Recognition using a Novel Transformers-based Model and an Innovative 270 Million-Words Multi-Font Corpus of Classical Arabic with Diacritics
- Learning to Compress Prompts with Gist Tokens
- Generative Representational Instruction Tuning
- Progress measures for grokking via mechanistic interpretability
- A Comprehensive Overview of Large Language Models
- LingMess: Linguistically Informed Multi Expert Scorers for Coreference Resolution
- KernelBench: Can LLMs Write Efficient GPU Kernels?
- Overcoming Data Scarcity in Multi-Dialectal Arabic ASR via Whisper Fine-Tuning
- Med-HALT: Medical Domain Hallucination Test for Large Language Models
- Modeling Intra and Inter-modality Incongruity for Multi-Modal Sarcasm Detection
- True Few-Shot Learning with Language Models
- SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis
- Intermediate-Task Transfer Learning with Pretrained Language Models: When and Why Does It Work?
- Learning Transferable Visual Models From Natural Language Supervision
- Robust Speech Recognition via Large-Scale Weak Supervision
- "You might think about slightly revising the title": Identifying Hedges in Peer-tutoring Interactions
- MTQE.en-he: Machine Translation Quality Estimation for English-Hebrew
- Normalizing without Modernizing: Keeping Historical Wordforms of Middle French while Reducing Spelling Variants
- Improving Passage Retrieval with Zero-Shot Question Generation
- FlexGen: High-Throughput Generative Inference of Large Language Models with a Single GPU
- HybridFlow: A Flexible and Efficient RLHF Framework
- ViperGPT: Visual Inference via Python Execution for Reasoning
- Bangla Key2Text: Text Generation from Keywords for a Low Resource Language
- The Development of Spectral and Temporal Encodings in Speech Sounds
- Chameleon: Mixed-Modal Early-Fusion Foundation Models
- ID10M: Idiom Identification in 10 Languages
- Memorization Without Overfitting: Analyzing the Training Dynamics of Large Language Models
- Training data-efficient image transformers & distillation through attention
- In-Distribution Steering: Balancing Control and Coherence in Language Model Generation
- Building a Bridge: A Method for Image-Text Sarcasm Detection Without Pretraining on Image-Text Data
- Fairseq S2T: Fast Speech-to-Text Modeling with Fairseq
- Interpretable Preferences via Multi-Objective Reward Modeling and Mixture-of-Experts
- Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution
- ADHD-Lang: A Large-Scale Social Media Dataset for Verbal Behavior and Digital Phenotyping in Adult ADHD
Cite
@misc{paszke2019pytorch,
title = {{PyTorch: An Imperative Style, High-Performance Deep Learning Library}},
author = {Paszke, Adam and Gross, Sam and Massa, Francisco and Lerer, Adam and Bradbury, James and Chanan, Gregory and Killeen, Trevor and Lin, Zeming and Gimelshein, Natalia and Antiga, Luca and Desmaison, Alban and Köpf, Andreas and Yang, Edward and DeVito, Zach and Raison, Martin and Tejani, Alykhan and Chilamkurthy, Sasank and Steiner, Benoit and Fang, Lu and Bai, Junjie and Chintala, Soumith},
year = {2019},
doi = {10.48550/arxiv.1912.01703},
eprint = {1912.01703},
archivePrefix = {arXiv},
url = {https://doi.org/10.48550/arxiv.1912.01703}
}References
- Yangqing "Jia, Evan Shelhamer, Jeff Donahue, Sergey Karayev, Jonathan Long, Ross Girshick, Sergio Guadarrama, and Trevor" Darrell. "caffe: Convolutional architecture for fast feature embedding". "arXiv preprint arXiv:1408.5093", "2014". find our card
- Frank Seide and Amit Agarwal. Cntk: Microsoft’s open-source deep-learning toolkit. In Proceedings of the 22Nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, KDD ’16, pages 2135–2135, New York, NY, USA, 2016. ACM. find
- Martín Abadi, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng Chen, Craig Citro, Greg S. Corrado, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Ian Goodfellow, Andrew Harp, Geoffrey Irving, Michael Isard, Yangqing Jia, Rafal Jozefowicz, Lukasz Kaiser, Manjunath Kudlur, Josh Levenber… find
- Theano Development Team. Theano: A Python framework for fast computation of mathematical expressions. arXiv e-prints, abs/1605.02688, May 2016. find our card
- Seiya Tokui, Kenta Oono, Shohei Hido, and Justin Clayton. Chainer: a next-generation open source framework for deep learning. In Proceedings of Workshop on Machine Learning Systems (LearningSys) in The Twenty-ninth Annual Conference on Neural Information Processing Systems (NIPS), 2015. find
- Ronan Collobert, Samy Bengio, and Johnny Mariéthoz. Torch: a modular machine learning software library. Technical report, Idiap, 2002. find
- G. Neubig, C. Dyer, Y. Goldberg, A. Matthews, W. Ammar, A. Anastasopoulos, M. Ballesteros, D. Chiang, D. Clothiaux, T. Cohn, K. Duh, M. Faruqui, C. Gan, D. Garrette, Y. Ji, L. Kong, A. Kuncoro, G. Kumar, C. Malaviya, P. Michel, Y. Oda, M. Richardson, N. Saphra, S. Swayamdipta, and P. Yin. DyNet: The… find our card
- Philip S. Abrams. An APL Machine. PhD thesis, Stanford University, 1970. find
- The MathWorks, Inc., Natick, Massachusetts, United States. MATLAB and Statistics Toolbox. find
- R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. find
- Jeff Bezanson, Alan Edelman, Stefan Karpinski, and Viral B Shah. Julia: A fresh approach to numerical computing. SIAM review, 59(1):65–98, 2017. find
- Travis Oliphant. NumPy: http://www.numpy.org/. A guide to NumPy. ↗
- Gaël Guennebaud, Benoît Jacob, et al. Eigen v3. http://eigen.tuxfamily.org, 2010. ↗
- Y LeCun and L Bottou. Lush reference manual. http://lush.sourceforge.net, 2002. ↗
- Atilim Gunes Baydin, Barak A. Pearlmutter, Alexey Andreyevich Radul, and Jeffrey Mark Siskind. Automatic differentiation in machine learning: A survey. J. Mach. Learn. Res., 18(1):5595–5637, January 2017. find
- Dougal Maclaurin. Modeling, Inference and Optimization with Composable Differentiable Procedures. PhD thesis, Harvard University, April 2016. find
- Matthew Johnson et. al. Jax. https://github.com/google/jax, 2018. ↗
- Mike Innes et. al. Flux.jl. https://github.com/FluxML/Flux.jl, 2018. ↗
- Eric Jones, Travis Oliphant, Pearu Peterson, et al. SciPy: Open source scientific tools for Python, 2001–. http://www.scipy.org/. ↗
- Wes McKinney. Data structures for statistical computing in python. In Proceedings of the 9th Python in Science Conference, 51-56, 2010. find
- Pierre Sermanet, Koray Kavukcuoglu, and Yann LeCun. Eblearn: Open-source energy-based learning in c++. In 2009 21st IEEE International Conference on Tools with Artificial Intelligence, pages 693–697. IEEE, 2009. USA: Trelgol Publishing, 2006. Technical report, code available at find
- Sharan Chetlur, Cliff Woolley, Philippe Vandermersch, Jonathan D. Cohen, John Tran, Bryan Catanzaro, and Evan Shelhamer. cudnn: Efficient primitives for deep learning. CoRR, abs/1410.0759, 2014. find
- Andrew Lavin. maxdnn: An efficient convolution kernel for deep learning with maxwell gpus, January 2015. find
- Andrew Lavin and Scott Gray. Fast algorithms for convolutional neural networks. 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pages 4013–4021, 2016. find
- Ronan Collobert, Koray Kavukcuoglu, and Clément Farabet. Torch7: A matlab-like environment for machine learning. In NIPS 2011, 2011. find
- Richard Gabriel. The rise of worse is better. http://dreamsongs.com/RiseOfWorseIsBetter.html. ↗
- Yann LeCun and Corinna Cortes. http://yann.lecun.com/exdb/mnist/. ↗
- Oriol Vinyals, Timo Ewalds, Sergey Bartunov, Petko Georgiev, Alexander Sasha Vezhnevets, Michelle Yeo, Alireza Makhzani, Heinrich Küttler, John Agapiou, Julian Schrittwieser, John Quan, Stephen Gaffney, Stig Petersen, Karen Simonyan, Tom Schaul, Hado van Hasselt, David Silver, Timothy P. Lillicrap,… — [arXiv:1708.04782](https://arxiv.org/abs/1708.04782) find
- DMLC. Dlpack: Open in memory tensor structure. https://github.com/dmlc/dlpack. ↗
- Adam Paszke, Sam Gross, Soumith Chintala, Gregory Chanan, Edward Yang, Zachary DeVito, Zeming Lin, Alban Desmaison, Luca Antiga, and Adam Lerer. Automatic differentiation in pytorch. In NIPS Workshop, 2017. find
- Dan Piponi. Automatic differentiation, C++ templates, and photogrammetry. J. Graphics, GPU, & Game Tools, 9(4):41–55, 2004. find
- Holger Leuck and Hans-Hellmut Nagel. Automatic differentiation facilitates of-integration into steering-angle-based road vehicle tracking. In 1999 Conference on Computer Vision and Pattern Recognition (CVPR ’99), 23-25 June 1999, Ft. Collins, CO, USA, pages 2360–2365, 1999. find
- The Python team. The cpython https://wiki.python.org/moin/GlobalInterpreterLock. ↗
- Giovanni Petrantoni and Jörg Wollenschläger. xyz/nimtorch. find
- Austin Huang, Junji Hashimoto, https://github.com/hasktorch/hasktorch. ↗
- G. Synnaeve, Z. Lin, J. Gehring, D. Gant, V. Mella, V. Khalidov, N. Carion, and N. Usunier. Forward modeling for partial observation strategy games - a starcraft defogger. In Advances in Neural Information Processing Systems, pages 10761–10771, 2018. find
- The PyTorch team. Torch Script. https://pytorch.org/docs/stable/jit.html. ↗
- Justin Luitjens. Cuda streams. GPU technology conference, 2014. find
- Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, and Paul R. Wilson. Hoard: A scalable memory allocator for multithreaded applications. In Proceedings of the Ninth International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS IX, pages 117–128, New… find
- J. Evans. A scalable concurrent malloc(3) implementation for freebsd. In In BSDCan — The Technical BSD Conference, May 2006. find
- S. Ghemawat and P. Menage. Tcmalloc: Thread-caching malloc. MNIST handwritten digit database. global interpreter lock. Nimtorch. https://github.com/fragcolor-and Sam Stites. Hasktorch. ↗
- Benjamin Recht, Christopher Ré, Stephen J. Wright, and Feng Niu. Hogwild: A lock-free approach to parallelizing stochastic gradient descent. In Advances in Neural Information Processing Systems 24: 25th Annual Conference on Neural Information Processing Systems 2011. Proceedings of a meeting held 12… find
- Matthew Hertz and Emery D. Berger. Quantifying the performance of garbage collection vs. explicit memory management. In Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-oriented Programming, Systems, Languages, and Applications, OOPSLA ’05, pages 313–326, New York, NY, USA, 2005. ACM. find
- The PyTorch team. Pytorch Autograd Profiler. https://pytorch.org/docs/1.0.1/autograd.html\#profiler. ↗
This page in Markdown → https://md.research.elamur.ai/free/en/papers/paszke-2019-pytorch-imperative-style-high-performance/