Learning PyTorch 2.0: Experiment deep learning from basics to complex models using every potential capability of Pythonic PyTorch
()
About this ebook
This book is a comprehensive guide to understanding and utilizing PyTorch 2.0 for deep learning applications. It starts with an introduction to PyTorch, its various advantages over other deep learning frameworks, and its blend with CUDA for GPU acceleration. We delve into the heart of PyTorch - tensors, learning their different type
Read more from Matthew Rosch
Learning PyTorch 2.0, Second Edition: Utilize PyTorch 2.3 and CUDA 12 to experiment neural networks and deep learning models Rating: 0 out of 5 stars0 ratingsLearning Pandas 2.0: A Comprehensive Guide to Data Manipulation and Analysis for Data Scientists and Machine Learning Professionals Rating: 0 out of 5 stars0 ratingsPyTorch Cookbook: 100+ Solutions across RNNs, CNNs, python tools, distributed training and graph networks Rating: 0 out of 5 stars0 ratings
Related to Learning PyTorch 2.0
Related ebooks
Google JAX Essentials: A quick practical learning of blazing-fast library for machine learning and deep learning projects Rating: 0 out of 5 stars0 ratingsPyTorch Cookbook Rating: 0 out of 5 stars0 ratingsApplied Deep Learning: Design and implement your own Neural Networks to solve real-world problems (English Edition) Rating: 0 out of 5 stars0 ratingsA Greater Foundation for Machine Learning Engineering: The Hallmarks of the Great Beyond in Pytorch, R, Tensorflow, and Python Rating: 0 out of 5 stars0 ratingsNeural Networks with Python Rating: 0 out of 5 stars0 ratingsMastering TensorFlow 2.x: Implement Powerful Neural Nets across Structured, Unstructured datasets and Time Series Data Rating: 0 out of 5 stars0 ratingsDeep Learning for Data Architects: Unleash the power of Python's deep learning algorithms (English Edition) Rating: 0 out of 5 stars0 ratingsPython for Machine Learning: From Fundamentals to Real-World Applications Rating: 0 out of 5 stars0 ratingsMachine Learning in the AWS Cloud: Add Intelligence to Applications with Amazon SageMaker and Amazon Rekognition Rating: 0 out of 5 stars0 ratingsObject Oriented Programming Inheritance: Fundamentals and Applications Rating: 0 out of 5 stars0 ratingsBeagleBone Robotic Projects Rating: 5 out of 5 stars5/5Galaxy’s Edge Magazine: Issue 16, September 2015 Rating: 0 out of 5 stars0 ratingsTensorflow Machine Learning Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsMachine Learning for Beginners - 2nd Edition: Build and deploy Machine Learning systems using Python (English Edition) Rating: 0 out of 5 stars0 ratingsOpenGL Foundations: Taking Your First Steps in Graphics Programming Rating: 0 out of 5 stars0 ratingsLearn Python Generative AI: Journey from autoencoders to transformers to large language models (English Edition) Rating: 0 out of 5 stars0 ratingsReinforcement Learning Algorithms with Python: Learn, understand, and develop smart algorithms for addressing AI challenges Rating: 0 out of 5 stars0 ratingsGROKKING ALGORITHMS: Tips and Tricks of Grokking Functional Programming Rating: 0 out of 5 stars0 ratingsIntroduction to TinyML Rating: 5 out of 5 stars5/5New Learning of Python by Practical Innovation and Technology Rating: 0 out of 5 stars0 ratings
Intelligence (AI) & Semantics For You
Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 4 out of 5 stars4/5ChatGPT Millionaire: Work From Home and Make Money Online, Tons of Business Models to Choose from Rating: 5 out of 5 stars5/5Writing AI Prompts For Dummies Rating: 0 out of 5 stars0 ratingsArtificial Intelligence: A Guide for Thinking Humans Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/580 Ways to Use ChatGPT in the Classroom Rating: 5 out of 5 stars5/5The Secrets of ChatGPT Prompt Engineering for Non-Developers Rating: 5 out of 5 stars5/5Midjourney Mastery - The Ultimate Handbook of Prompts Rating: 5 out of 5 stars5/53550+ Most Effective ChatGPT Prompts Rating: 0 out of 5 stars0 ratings100M Offers Made Easy: Create Your Own Irresistible Offers by Turning ChatGPT into Alex Hormozi Rating: 0 out of 5 stars0 ratingsGenerative AI For Dummies Rating: 2 out of 5 stars2/5AI for Educators: AI for Educators Rating: 3 out of 5 stars3/5AI Money Machine: Unlock the Secrets to Making Money Online with AI Rating: 5 out of 5 stars5/5THE CHATGPT MILLIONAIRE'S HANDBOOK: UNLOCKING WEALTH THROUGH AI AUTOMATION Rating: 5 out of 5 stars5/5The ChatGPT Revolution: How to Simplify Your Work and Life Admin with AI Rating: 0 out of 5 stars0 ratingsThe AI-Driven Leader: Harnessing AI to Make Faster, Smarter Decisions Rating: 4 out of 5 stars4/5Artificial Intelligence For Dummies Rating: 3 out of 5 stars3/51200+ AI Prompts for Everyone.: Artificial Intelligence Prompt Library. Rating: 0 out of 5 stars0 ratingsEnterprise AI For Dummies Rating: 3 out of 5 stars3/5Demystifying Prompt Engineering: AI Prompts at Your Fingertips (A Step-By-Step Guide) Rating: 4 out of 5 stars4/5A Quickstart Guide To Becoming A ChatGPT Millionaire: The ChatGPT Book For Beginners (Lazy Money Series®) Rating: 4 out of 5 stars4/5The Roadmap to AI Mastery: A Guide to Building and Scaling Projects Rating: 3 out of 5 stars3/5AI Investing For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Learning PyTorch 2.0
0 ratings0 reviews
Book preview
Learning PyTorch 2.0 - Matthew Rosch
Preface
This book is a comprehensive guide to understanding and utilizing PyTorch 2.0 for deep learning applications. It starts with an introduction to PyTorch, its various advantages over other deep learning frameworks, and its blend with CUDA for GPU acceleration. We delve into the heart of PyTorch – tensors, learning their different types, properties, and operations. Through step-by-step examples, the reader learns to perform basic arithmetic operations on tensors, manipulate them, and understand errors related to tensor shapes.
A substantial portion of the book is dedicated to illustrating how to build simple PyTorch models. This includes uploading and preparing datasets, defining the architecture, training, and predicting. It provides hands-on exercises with a real-world dataset. The book then segues into exploring PyTorch's nn module and gives a detailed comparison of different types of networks like Feedforward, RNN, GRU, CNN, and their combination.
Further, the book delves into understanding the training process and PyTorch's optim module. It explores the overview of optimization algorithms like Gradient Descent, SGD, Mini-batch Gradient Descent, Momentum, Adagrad, and Adam. A separate chapter focuses on advanced concepts in PyTorch 2.0, like model serialization, optimization, distributed training, and PyTorch Quantization API.
In the final chapters, the book discusses the differences between TensorFlow 2.0 and PyTorch 2.0 and the step-by-step process of migrating a TensorFlow model to PyTorch 2.0 using ONNX. It provides an overview of common issues encountered during this process and how to resolve them.
In this book you will learn:
A comprehensive introduction to PyTorch and CUDA for deep learning.
Detailed understanding and operations on PyTorch tensors.
Step-by-step guide to building simple PyTorch models.
Insight into PyTorch's nn module and comparison of various network types.
Overview of the training process and exploration of PyTorch's optim module.
Understanding advanced concepts in PyTorch like model serialization and optimization.
Knowledge on distributed training in PyTorch.
Practical guide to using PyTorch's Quantization API.
Differences between TensorFlow 2.0 and PyTorch 2.0.
Guidance on migrating TensorFlow models to PyTorch using ONNX.
The book equips the reader with comprehensive knowledge of PyTorch 2.0 and provides practical examples to apply this knowledge, making it an ideal read for aspiring network administrators.
Prologue
Dear reader, we are excited to take you on an exciting adventure into the fascinating world of PyTorch 2.0. This book has been painstakingly developed as a thorough reference, with the intention of illuminating the complex terrain of deep learning. Its goal is to change you from a curious enthusiast into a proficient practitioner by providing you with the theoretical understanding as well as the practical expertise necessary to properly use PyTorch. While we embark on this journey of discovery, we want you to participate completely by testing the validity of your previously held beliefs and broadening your perspective on the fascinating field of deep learning.
The first part of the book lays a strong basis in the fundamental principles that underpin PyTorch. Tensors, the fundamental building elements of PyTorch, are the subject of substantial discussion in the first few chapters. These first few chapters will walk you through the steps of comprehending tensors, as well as the process of building and manipulating them. This book will ensure that you have a solid foundation in the fundamentals before going on to more advanced ideas by gradually increasing the difficulty of the topics as you progress through it.
As we continue to delve further into the workings of PyTorch, the book begins to introduce the development of basic as well as more complex models. We break down the many parts that make up these models with the help of some examples to illustrate our points. You will gain knowledge on how to create and train a variety of neural networks, including feed-forward and recurrent neural networks, as well as GRUs and CNNs, which are more advanced models. You will be able to apply what you learn in the book to real-world situations since it combines theoretical explanations with real-world examples, which helps to drive home the many concepts and methods that are covered.
The knowledge of the training process comes next in the book, after an initial look at neural networks. Unraveling optimization algorithms, sometimes known as the engines that drive learning in neural networks,
is one of the most important aspects of this endeavor. The book explains each algorithm in a manner that is both comprehensive and easy to understand, beginning with the fundamental Gradient Descent and progressing all the way up to the more complex Adaptive Moment Estimation. You will now have the ability to construct and train robust models using PyTorch thanks to the knowledge and the activities you have completed.
In the latter chapters of this book, we delve into the more sophisticated principles of the PyTorch programming language. You will acquire knowledge regarding the serialization and optimization of models, as well as the use of distributed training and the Quantization API provided by PyTorch. In addition, we investigate the connection between TensorFlow 2.0 and PyTorch 2.0, comparing and contrasting the advantages and disadvantages of both programs. In doing so, the book arms you with the knowledge necessary to select the framework that caters to your requirements in the most optimal manner.
As we embark on this adventure, we want to urge you to approach each chapter with an open heart and a mind that is full of curiosity. This book offers something to offer everyone, from someone who is just beginning out in deep learning to someone who is an experienced professional looking to develop their skills. We have high hopes that by the time you finish reading this book, you will not only have a comprehensive understanding of PyTorch 2.0 but also the self-assurance to put what you have learned into practice in the real world. Let's not waste any more time and go right into this thrilling adventure together, shall we? PyTorch 2.0 is where you want to be, so welcome!
Learning PyTorch 2.0
Experiment deep learning from basics to complex models using every potential capability of Pythonic PyTorch
Matthew Rosch
Copyright © 2023 by GitforGits.
All rights reserved. This book is protected under copyright laws and no part of it may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without the prior written permission of the publisher. Any unauthorized reproduction, distribution, or transmission of this work may result in civil and criminal penalties and will be dealt with in the respective jurisdiction at anywhere in India, in accordance with the applicable copyright laws.
Published by: GitforGits
Publisher: Sonal Dhandre
www.gitforgits.com
Printed in India
First Printing: July 2023
ISBN: 978-8196288372
Cover Design by: Kitten Publishing
For permission to use material from this book, please contact GitforGits at [email protected].
Content
Preface
Chapter 1: Introduction To PyTorch 2.0 and CUDA 11.8
Essentials of Neural Networks
Anatomy of a Neural Network
Learning in a Neural Network
Neural Network and Deep Learning
Introduction to PyTorch
PyTorch Overview
How PyTorch supports Deep Learning
PyTorch 2.0 and CUDA 11.8
PyTorch 2.0 Key Features
Enhanced TorchScript
Model Deployment and Serving
Improved Mobile Support
Enhanced Quantization Support
Named Tensors
Extended Ecosystem
Expanded ONNX Support
CUDA for Accelerated Deep Learning
A Primer on CUDA
Why is CUDA Necessary for Deep Learning?
Blend of CUDA and PyTorch
Setting up PyTorch 2.0 and CUDA 11.8 on Linux
Update Your System
Install Necessary Dependencies
Verify CUDA-capable GPU
Download and Install CUDA 11.8
Setup Environment Variables
Verify the Installation
Install PyTorch 2.0
Verify PyTorch and CUDA Integration
Summary
Chapter 2: Getting Started with Tensors
Diving into Tensors
Understanding Tensors
Different Tensors
Tensor Terminologies and Concepts
Scalar
Vector
Matrix
Tensor Operations
Broadcasting
Device
Sample Program to Create Tensors
Tensor Data Types
Standard Arithmetic Operations
Addition
Subtraction
Multiplication
Division
Tensor Manipulation
Reshaping Tensors
Slicing Tensors
Joining Tensors
Matrix Multiplication
Manage Tensor Shape Errors
Matrix Multiplication
Element-wise Operations
Reshaping Tensors
Aggregation Operations
Sum
Mean
Max
Min
Summary
Chapter 3: Advanced Tensor Operations
Advanced Tensor Operations Overview
Reshaping
Viewing
Stacking
Changing Shape of Tensor
Viewing Tensor Dimensions
Stacking Sequence of Tensors
Squeezing a Tensor
Un-squeezing a Tensor
Permuting a Tensor
Indexing and Selecting Data from Tensors
Indexing a Tensor
Slicing a Tensor
Selecting Specific Indices
Switching Access Between GPU and CPU
Necessity of Access of Choice
Summary
Chapter 4: Building Neural Networks with PyTorch 2.0
PyTorch NN Module Overview
Understanding Feedforward Networks
Overview
Advantages of Feedforward Networks
Build Multi-layer Perceptron using PyTorch
Understanding Recurrent Neural Networks
Overview
Creating RNNs in PyTorch
Exploring Gated Recurrent Units (GRUs)
Overview
Advantages of GRUs
Creating Gated Recurrent Units (GRUs)
Understanding Convolutional Neural Networks
Overview
Advantages of CNNs
Creating Convolutional Neural Networks (CNNs)
Combining RNN and CNN Together
Need of Designing Custom Layers
Design Custom Layers
Summary
Chapter 5. Training Neural Networks in PyTorch 2.0
Neural Network Training - Overview
PyTorch optim Module
Using Optimizer
Optimization Algorithms
Gradient Descent
Using Gradient Descent
Stochastic Gradient Descent
Using Stochastic Gradient Descent
Mini-batch Gradient Descent
Using Mini-batch Gradient Descent
Momentum
Using Momentum with SGD
Adaptive Gradient Algorithm
Using Adagrad Algorithm
Adaptive Moment Estimation
Summary
Chapter 6: PyTorch 2.0 Advanced
Overview
Model Serialization
Model Optimization
Perform Model Serialization
Serialize Models
Optimize Models
Distributed Training of Deep Learning
Methods of Distributed Training
Distributed Training in PyTorch
Using DataParallel