How to Install PyTorch 2+ (Apple M1 Included) - PyTorch for Beginners #1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi and welcome to this pie torch for beginners video number one today you'll learn how to install pie torch locally on your system I'll put the emphasis on Apple silicon support in some parts of the video but the installation steps will work for all of the other operating systems so the first step is to find the correct installation command head over to the pytorch website and select the options that match your operating system and python environment for example I want to install the latest stable version of Pi torch on Mac OS and I'm using Anaconda for dependency management there's no cue to support on Mac OS but I'll show you how to work with MPS at the end of the video you can see how the pytorch website automatically gives you the installation command you shouldn't just take it and run it since the best practice is to install pytorch in a virtual environment let me show you how to do that next this portion of the video will explain how to create a new python virtual environment and how to install pytorch and other data science libraries you'll need I'm using Anaconda for dependency management so the environment creation boils down to running a conda create command followed by the environment name and the python version the optional Y flag will accept any prompt for installing additional dependencies the environment is now created and I will activate it with the conda activate command we're now inside a new virtual environment and the next step is to install pytorch I'll just copy the installation command generated by the pi torch website you'll see a bunch of messages during the installation and the whole process might take a while depending on your internet speed okay so Pi torch is installed let's also grab some essential data science libraries I'll install pandas you pider mapletlib and scikit-learn but you should feel free to add any other library to this list so these are now installed which means we have everything needed to make a couple of Pi torch installation checks I'll use you pider lab for this section you can do the same by running it from the terminal and now inside a new pyter lab notebook the first thing I want to do is to check the pi torch version at the time of recording which is May 2023 the latest stable version is 201 so let's see if that's the one I have installed so it looks like Pi torch is installed which means you can stop watching the video here the rest will focus only on MPS acceleration which is only relevant to you if you don't have an Nvidia graphics card Apple silicon machines can't accelerate the neural network training process with Cuda since it's only available on Nvidia gpus since Mac OS version 12.3 you can use MPS to make training faster and if you're wondering MPS stands for metal performance shaders it essentially enables high performance training on GPU for Mac OS devices you can run the following two commands to verify if the MPS back end is available and if your Pi torch version was built with MPS both return true which means we have MPS support but the ultimate installation test is actually going through the learning process to do so I'll borrow one code snippet from this article by Nicos K on medium it will essentially generate some linearly spaced data for the x-axis take the sign of that data for the y-axis randomly initialize weights and simulate learning for 2000 epochs as you can see the code inside the loop simulates the forward pass and neural network and then calculates the loss with sum of squared residuals up next the code snippet calculates the derivative of the loss function itself and for each of the randomly initialized weights and then finally updates the weights by multiplying the derivative or the gradient by the Learning rate in more simple terms this piece of code moves all calculations to the MPS device and if you run it and don't get an error it means you have Pi torch installed with MPS support and it looks like that's the case for me you now have pytorch installed locally on your system if you've liked this video and want to see more pytorch and neural network content make sure to give it a thumbs up and subscribe to the channel also don't miss out on my free ebook with the best resources to learn data science you can get it by clicking on the link in the video description
Info
Channel: Better Data Science
Views: 5,892
Rating: undefined out of 5
Keywords: pytorch, python pytorch, install pytorch, install pytorch mac, machine learning, deep learning, install pytorch mac m1, install pytorch apple silicon
Id: mS2X1QmIUCI
Channel Id: undefined
Length: 3min 37sec (217 seconds)
Published: Sat Jun 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.