Setup Mac for Machine Learning with PyTorch in 11 minutes (works for all M1, M2)

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 142

  • @mrdbourke
    @mrdbourke  2 роки тому +25

    *Update 30 June 2022:* PyTorch 1.12.0 is out and in a stable release. You now no longer need to install the nightly versions of PyTorch as done at 7:37, the updated code is:
    pip3 install torch torchvision torchaudio
    The code samples have been updated to include this new line of code.
    See the announcement blog post here: pytorch.org/blog/pytorch-1.12-released/#prototype-introducing-accelerated-pytorch-training-on-mac

    • @oyilenaanblessed-sayah7235
      @oyilenaanblessed-sayah7235 Рік тому

      Please I need help, I installed everything and it works perfectly. The only issue is that I restarted my terminal and I don’t know how to open up jupyter notebook anymore

  • @AZisk
    @AZisk 2 роки тому +24

    good to see this finally working. Thanks Daniel!

  • @SkilledApple
    @SkilledApple 2 роки тому +2

    This is a GOAT video since I just got my new Mac and have been needing to set it up for ML.

  • @matteo4318
    @matteo4318 2 роки тому +5

    Hey Daniel,
    Hope you're doing well.
    Despite no having a Mac, I'm glad you're back with a new video.
    Lately I'm really enjoying reading your blog posts.
    Keep up the good work!

  • @shouryabhosale4636
    @shouryabhosale4636 6 місяців тому

    this is hands down the best video i ever saw, everything worked perfectly fine

  • @mengxuanyan2802
    @mengxuanyan2802 2 роки тому +1

    I have looked over youtube for a tutorial that exactly match my need, and this is the one! I have a Mac M1 the same as yours. I followed the instructions and the whole setup works smoothly. This is a wonderful tutorial. Thank you so much.

  • @daviddjames_
    @daviddjames_ 2 роки тому +1

    Maaaateee this is unreal, just found your channel, instant follow! Keep it up mate glad to see someone so relatable out there!

  • @MyClashes
    @MyClashes Рік тому

    first time a youtube tutorial with 0 problems

  • @jordandavis406
    @jordandavis406 2 роки тому

    Window > Tile Window To Left of Screen > Select another window to tile on the right < total game changer.

  • @paulmcdevitt2038
    @paulmcdevitt2038 Рік тому

    Well, that was fast and painless. Thank you Daniel. Now, can't wait to go through the various ML learning

  • @OtRatsaphong
    @OtRatsaphong 2 роки тому

    Glad to see that you are working on a PyTorch oriented course! But I need to keep working on finishing the TensorFlow course before I think of learning PyTorch.

  • @Flyforward226
    @Flyforward226 2 роки тому

    Glad to see you back!

  • @schuylerblasy2192
    @schuylerblasy2192 2 роки тому

    Thanks for the video man! Glad to see you back dude!

  • @xinyaoyin2238
    @xinyaoyin2238 5 місяців тому +1

    just finished your pytorch 25 hour video, now i am sad it's over

  • @duiliosotelo1005
    @duiliosotelo1005 Рік тому

    Daniel thx for the content, it was so fast, greetings from México

  • @palahnuk1
    @palahnuk1 Рік тому

    Daniel - sincere thanks for sharing your hard won knowledge and skills. You are an open and supportive person. Cheers ! ... Well Done !!

  • @WhatsAI
    @WhatsAI 2 роки тому

    Glad to see you post another video Daniel! :)

  • @mahaalabduljalil6596
    @mahaalabduljalil6596 2 місяці тому

    Thaaaaank you ! worked beautifully with my M2 macbook air

  • @chenzihao6142
    @chenzihao6142 2 роки тому

    ohhh me again!thanks for sharing the pytorch with GPU on mac. I studied how to make virtual environment on Mac through this video and the tensorflow video…they help me to deeply understand the whole ML and programming.

    • @mrdbourke
      @mrdbourke  2 роки тому

      Glad to hear Chen! Happy machine learning!

  • @lzdps
    @lzdps 2 роки тому +1

    Nice to have these detailed steps!

  • @muhammadamine6059
    @muhammadamine6059 Рік тому

    the only tutorial that worked for me

  • @tolga_x
    @tolga_x 8 місяців тому

    if you get the error "the kernel appears to have died." try changing the python version from 3.8 to 3.11. This solution worked for me.

  • @fysiki8827
    @fysiki8827 11 місяців тому +2

    Hey sir, Nice video but my mac m1 giving: Kernel Restarting
    The kernel for Untitled.ipynb appears to have died. It will restart automatically.
    But it work in pycharm.
    Thanks for video.

  • @ikanez
    @ikanez 2 роки тому

    Awesome. Thanks for the tutorial Daniel. Works great.

  • @ScarletRender
    @ScarletRender Рік тому

    I wonder how well this well work on a macbook air m1

  • @anne_marie_bu
    @anne_marie_bu 2 роки тому

    Thank you so much for this tutorial! it is very helpful. But as a newbe I have a dumb question - how do I finish the session and deactivate the environment? Also how to create a new project ? - new folder with a new env?

  • @nikilottes9912
    @nikilottes9912 Рік тому

    Thank you so much, you ar my hero. I hav long time my mac to fit, but with you video. now i can do with AI, thank so much lot

  • @jhy3480
    @jhy3480 2 роки тому

    Thank you so much! I'm a beginner, you saved me :)

  • @satyajeetpatil8177
    @satyajeetpatil8177 7 місяців тому

    You're a legend

  • @eluz7903
    @eluz7903 Рік тому

    Thank you very much for this very clear tutorial.

  • @notionpro
    @notionpro 2 роки тому +2

    I am unable to install torchaudio and fastaudio with this environment. Can you suggest something?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      What command did you run/what issue are you getting?

  • @veerakarthickv4407
    @veerakarthickv4407 2 роки тому

    @Daniel Thanks man...Great video...which one will you suggest for Data science student..apple m1pro or any other heavy gaming stuff

  • @i_like_it5339
    @i_like_it5339 2 роки тому +1

    Not all heroes wear capes

  • @devendradhokare2162
    @devendradhokare2162 2 роки тому +1

    Hi Daniel after restarting the terminal I didn't get the base in front of the name can you help me?

  • @aleksaggor
    @aleksaggor 2 роки тому

    Thank you for the video, just what I needed!

    • @mrdbourke
      @mrdbourke  2 роки тому

      You're welcome Aleksander, enjoy!

  • @xinyaoyin2238
    @xinyaoyin2238 11 місяців тому

    subscribed, i rarely comment on people but you really deserve it!!!

    • @mrdbourke
      @mrdbourke  11 місяців тому +1

      Thank you Xinyao! Welcome to the channel!

  • @makelvin
    @makelvin 2 роки тому

    I find it interesting that the new PyTorch supports the GPU acceleration instead of Apple's build-in Neural Processor Unit which as the name suggested is specifically designed for Neural Processing.

    • @laden6675
      @laden6675 2 роки тому

      The neural engine is for inference, not training.

    • @makelvin
      @makelvin 2 роки тому +1

      @@laden6675 , how exactly is Apple implementing the Neural Engine that it will only allows for feed forward inferencing of the neural network and somehow prevents it from doing the back propagation of the neural network during the training process. Shouldn't they be all fundamentally a lot of tensor calculations whether if it is going forward or backward? The only difference is the iteration it needs for optimization of the weights when doing back propagation during training. But the fundamentals should be the same.

  • @jonathangreene682
    @jonathangreene682 2 роки тому

    SUPER HELPFUL! Thank you.

    • @mrdbourke
      @mrdbourke  2 роки тому

      You’re welcome Jonathan :)

  • @masterbobp
    @masterbobp 2 роки тому

    Worked, Thank you very much

  • @toyinogunlade6934
    @toyinogunlade6934 2 роки тому

    Great video Daniel.. Thanks!!! I followed through with the lessons on my M1 Pro Max but get stuck while trying to launch the Jupyter notebook. Fails with the error "zsh: killed jupyter notebook"... Any thoughts on this, please?

  • @anilkumar-uf9qf
    @anilkumar-uf9qf 2 роки тому +1

    Thank you Daniel....I am unable to import XGBoost in Jupyter notebook....the package gets installed using Conda install but unable to import...ModuleNotFoundError: No module named 'xgboost'

  • @ShivanS
    @ShivanS 2 роки тому

    it's been a while man. hope you have been well

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      been excellent my friend! ramping up for a fun backend of 2022

  • @sportherz
    @sportherz 2 роки тому +2

    Hi Daniel, thanks for the content. Do you see any improvements with the speed on your projects when running the stable release 1.12.0?

  • @AstroPinoy
    @AstroPinoy Рік тому

    thanks I did install this and went fine, however I want to use some script or how to leverage this into like dreambooth where I will give my set of images and set of class images and prompts and inject it to the base model stable diffusion 1.5. Can't seem to find a website for it.

  • @Andrew_J123
    @Andrew_J123 2 роки тому

    Have you checked out bayesian deep learning? Would you be able to make a tensor flow probability tutorial?

  • @iamrsps
    @iamrsps Рік тому

    Super easy to setup. Great video 👍🏼. Thanks Daniel

  • @Alex-uc8co
    @Alex-uc8co 2 роки тому

    Can you run some speed comparisons? M1 vs Google Colab

  • @yonikremer4135
    @yonikremer4135 2 роки тому

    Can you review and give your thoughts on Google cloud ML certificate and/or the coursera specification that comes with it?

  • @ShivanS
    @ShivanS 2 роки тому

    also congrats on the house purchase too.

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      Thank you! I appreciate it legend

  • @oyilenaanblessed-sayah7235
    @oyilenaanblessed-sayah7235 Рік тому

    Please I need help, I installed everything and it works perfectly. The only issue is that I restarted my terminal and I don’t know how to open up jupyter notebook anymore

    • @c.snoeij1330
      @c.snoeij1330 7 місяців тому

      First activate your conda env, then just type: jupyter notebook. Then it will open jupyter in your browser.

  • @pivotstance
    @pivotstance 7 місяців тому

    I am getting "Kernel Restarting
    The kernel for Untitled.ipynb appears to have died. It will restart automatically." how to fix?

  • @_The_Leader_
    @_The_Leader_ Рік тому

    After completing all these steps I am gettng "no module named torch" in jupyter notebook

  • @neelambujchaturvedi6886
    @neelambujchaturvedi6886 2 роки тому

    Great video Daniel. Just wanted to know if you were able to install transformers, Tokenizers in the same pytorch environment?

    • @mrdbourke
      @mrdbourke  2 роки тому +2

      Yes I can confirm I can install Tokenizers and Transformers in the same environment, I built the Tokenizers from source here - huggingface.co/docs/tokenizers/installation#installation-from-sources

    • @neelambujchaturvedi6886
      @neelambujchaturvedi6886 2 роки тому

      ​@@mrdbourke I tried installing it from source, I am getting the following error "No local packages or working download links found for tokenizers==0.12.1.dev0"

  • @brandonwinston
    @brandonwinston 2 роки тому

    Thank you for this. Can you go over what kind of editing we need to do to python code written for CUDA that we now want to work with MPS?

    • @mrdbourke
      @mrdbourke  2 роки тому +2

      You can setup device agnostic code to use CUDA if it’s available or MPS if it’s available
      Eg
      if torch.cuda.is_available():
      device = “cuda”
      elif torch.backends.mps.is_available():
      device = “mps”
      else:
      device = “cpu”

  • @ketchupparty9997
    @ketchupparty9997 Рік тому

    It worked thanks

  • @Mr.AIFella
    @Mr.AIFella Рік тому

    Thanks alot. V. Helpful

  • @mhpt74
    @mhpt74 2 роки тому

    Nice video! Why do you use pip for soem installs and conda for others? Could one not use conda throughout?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      pip is only for the nightly build of PyTorch - there’s no conda option yet (though this should come with a stable release e.g. v0.12.0
      conda environments are compatible with pip/conda installs as well

  • @lukeauslender6494
    @lukeauslender6494 10 місяців тому

    After miniforge3 install I have conda and (base) but no miniforge3 folder in my home and got "source: no such file or directory: /Users/home/miniforge3/bin/activate" at the end of the install?

  • @AVaishnaviDeptofAIML
    @AVaishnaviDeptofAIML Рік тому

    hi, so I had a question, if you already have TensorFlow installed (the first 6 steps for installation are practically same for both packages), do we create a separate env for PyTorch or we create a new one like in the video ?

  • @jakeliujakeliu
    @jakeliujakeliu 2 роки тому

    Can you do a comparison between PC and New MacBook Pro. Does M1 Pro ultra/Max faster or slower than NVIDIA 3080

  • @dragonlord1225
    @dragonlord1225 10 місяців тому

    Does this work with an older mac book with intel GPU?

  • @andrewligeralde5031
    @andrewligeralde5031 2 роки тому

    Can you explain why we use pip to install the nightly build instead of conda? and on top of that, why is it necessary to build the miniforge environment if we're gonna use pip anyways?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      Because it’s a nightly build, pip is the only option - conda should be available when a stable release comes out.
      You could create this with a pip environment, however, I chose miniforge/conda because conda can use pip & conda + my experience with Miniforge is very good on Apple Silicon

    • @andrewligeralde5031
      @andrewligeralde5031 2 роки тому

      @@mrdbourke thanks so much!

  • @garrettosborne4364
    @garrettosborne4364 2 роки тому

    I'm waiting on M2 I would assume this would be similar down the road.

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      It should work for M2 as well, if not, I’ll make another video

  • @oyilenaanblessed-sayah7235
    @oyilenaanblessed-sayah7235 Рік тому

    It works!!!!

  • @holdenwang3246
    @holdenwang3246 2 роки тому

    Hi, Daniel! Can I use miniconda instead of mini forge? It seems that miniconda also supports apple silicon.

    • @mrdbourke
      @mrdbourke  2 роки тому

      Yes if you already have miniconda, you can use that it should work similarly
      As long as you have access to the “conda” command you should be good

  • @lifeisbeautifu1
    @lifeisbeautifu1 Рік тому

    Thank you!

  • @cygnusx1shailu430
    @cygnusx1shailu430 2 роки тому

    Already i hve installed tensorflow on the same base but cant able 2 create for pytorch, its coming :Not a conda environment:(

  • @xabelh.h2772
    @xabelh.h2772 2 роки тому

    annaconda support m1 natively

  • @winglight2008
    @winglight2008 2 роки тому

    May I ask you a favor? I tried to install lightbgm and xgboost this afternoon and failed because other python libraries JUST use them with x86 edition. How to install lightbgm and xgboost on mac m1?

  • @AstroPinoy
    @AstroPinoy Рік тому

    worked until I run the jupyter notebook can creating new, internal server error 500
    Update: nevermined I got it working thanks!!

  • @fanzei
    @fanzei 2 роки тому

    Great video Daniel. I just run the Environment in jupyter notebook, but in Pycharm the Pytorch version is 1.11.0, it means it isn't updated. How can i import the Environment in Pycharm? many Thanks!

    • @mrdbourke
      @mrdbourke  2 роки тому

      Did you make sure to install the nightly version of PyTorch on Mac?

    • @fanzei
      @fanzei 2 роки тому

      ​@@mrdbourke i have imported the conda Environment in Pycharm and it works, thanks for your reply

  • @RaghavDave26
    @RaghavDave26 2 роки тому

    Hi Daniel, thanks for the instructions. Just wonder which spec of M1 Pro 14" did you get? I'm looking to get a mac for data science and wondering if the base M1 pro model is enough?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      The laptop in this video is a baseline M1 Pro
      It would be perfect for getting started
      If you’re going to upgrade anything, potentially the option with more GPU could be more helpful for deep learning experiments
      But this machine is more than capable

    • @AaditMalikayil
      @AaditMalikayil Рік тому

      Hi RaghavDave26, did you purchase a suitable macbook for your use? I am looking to buy one to for data science.

  • @santhoshsrinivas8393
    @santhoshsrinivas8393 2 роки тому

    m using the new Mac m1 air but when I try to run conda install -c apple tensorflow-deps it throws an error saying PackageNotFoundError any help on this one?

  • @peterwjacko
    @peterwjacko 2 роки тому

    Hey Daniel, do you have any experience using Dask for data science? We're just starting to use it at work so I'd be really interested in seeing a 101 from you if you know your way around it

  • @rissalatahmed6719
    @rissalatahmed6719 Рік тому

    Thank you!

  • @wangpeng5537
    @wangpeng5537 2 роки тому

    Hi Daniel, I have a question that is I followed all your instructions and finished all steps. but when I restart the terminal I cannot use the code jupyter notebook directly. do I need to set it up every time?

    • @mrdbourke
      @mrdbourke  2 роки тому

      Hi Wang, make sure you activate your environment with conda each time you come back to use Jupyter
      Eg “conda activate ./env” (whilst in the folder with your environment)

  • @Martin-lv1xw
    @Martin-lv1xw Рік тому

    Hi Daniel, I ran a single hidden layer MLP on FashionMNIST data for 100 epochs. Seems very slow compared to CoLAB free version. It took about 14 minutes. Is it normal??

    • @mrdbourke
      @mrdbourke  Рік тому

      Did you setup MPS as the backend? You can see here: pytorch.org/docs/stable/notes/mps.html Otherwise, a MacBook is typically slower than a dedicated NVIDIA GPU - the GPUs in Google Colab are quite powerful, even the free ones

    • @Martin-lv1xw
      @Martin-lv1xw Рік тому

      @@mrdbourke Thank you for clarification. Problem solved. I re-run the same on CoLaB and Mac, Its actually took took 6 minutes faster in MAC.

  • @JaskoonerSingh
    @JaskoonerSingh 2 роки тому

    Can you run any of the Nvidia AI Containers without the dreaded "Out of memory" error message ?

  • @aadarshkumar2257
    @aadarshkumar2257 2 роки тому

    Hey Daniel , Can you make video for installing and using Tensorflow on Apple's M2 Chip. If anyone else can help then please do.
    I have purchased the MacBook Air M2 10 core Gpu 16gb Ram 512 gb SSD.

    • @mrdbourke
      @mrdbourke  2 роки тому

      Hey Aadarsh, the video on my channel for installing TensorFlow for mac should work for M2 - www.mrdbourke.com/setup-apple-m1-pro-and-m1-max-for-machine-learning-and-data-science/

  • @egyptianluvr9223
    @egyptianluvr9223 2 роки тому

    Wish I’d seen this 5 months ago, glad I don’t have to use Tensorflow anymore 😂

  • @dkadayinthailand3082
    @dkadayinthailand3082 2 роки тому

    Why on earth people would pay so much for a macbook pro instead of saving half of that and just get a notebook of the same specs is beyond fantasy.
    love your videos.

  • @TomMathews
    @TomMathews 2 роки тому

    Hey Daniel, thanks for the instructions. Although on my M1 Pro Macbook Pro, I am getting the following error.
    AttributeError: module 'torch.backends' has no attribute 'mps'
    Can you please help me out on this?

    • @mrdbourke
      @mrdbourke  2 роки тому

      Did you select the nightly version of PyTorch? That may be the error
      I can confirm this works across my Macs

  • @mikahoy
    @mikahoy Рік тому

    is it applicable also in mac M2?

  • @dsclips900
    @dsclips900 2 роки тому

    Thanks for the tutorial. I followed every step, but when I launched the Jupyter notebook (worked just fine on the first try) and quitted it, and opened the terminal again and typed jupyter notebook, I got the following error: zsh: command not found: jupyter
    I went to the env inside pytorch-test, and typed jupyter notebook again, the same problem, any idea?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      Make sure your environment is activated when you run the command
      Eg
      cd PyTorch-test
      conda activate ./env
      jupyter notebook

  • @dhruvilshah7770
    @dhruvilshah7770 2 роки тому

    Hey! in the video setting m1 pro MacBook Pro for machine learning video if the base terminal changes due to some circumstances how can I get back to base terminal ?

    • @mrdbourke
      @mrdbourke  2 роки тому

      Hey there, I’m not sure what you mean by base terminal? As in you changed your path or environment activated? Or you changed your Terminal app?

  • @chenathy_5293
    @chenathy_5293 2 роки тому

    is there a way to set up everything without Conda ?

    • @mrdbourke
      @mrdbourke  2 роки тому +1

      You can try venv but in my experience conda/miniforge are very stable for Apple Silicon

  • @zistiqb1815
    @zistiqb1815 2 роки тому

    hello sir!
    im facing issue in importing scikit-learn in jupyter notebook but its already installed ...... issue ( ModuleNotFoundError: No module named 'sklearn' ) .. im stuck here for two days but i can't fix this .... plz help

    • @mrdbourke
      @mrdbourke  2 роки тому

      You can try running conda install scikit-learn

    • @mrdbourke
      @mrdbourke  2 роки тому

      Or even: pip install -U scikit-learn

    • @zistiqb1815
      @zistiqb1815 2 роки тому

      @@mrdbourke thank you sir ...

  • @Kevin-cy2dr
    @Kevin-cy2dr 2 роки тому

    This works for the old 2021 M1 chips right?

    • @mrdbourke
      @mrdbourke  2 роки тому

      It should work for any Apple Silicon Mac (M1, M1 Pro, M1 Max, M1 Ultra etc)

  • @datable
    @datable 2 роки тому

    Great video. Could you please do one for Windows laptops?

    • @mrdbourke
      @mrdbourke  2 роки тому

      I don’t have a Windows laptop but the PyTorch getting setup docs have a good guide - pytorch.org/get-started/locally/

  • @smoochie3331
    @smoochie3331 2 роки тому

    Jeez, have u heard docker?

  • @ammaransari2073
    @ammaransari2073 2 роки тому

    Thx

  • @astrofolia4515
    @astrofolia4515 2 роки тому

    NameError: name '_C' is not defined
    I get this error when importing torch

    • @astrofolia4515
      @astrofolia4515 2 роки тому

      I solved the problem by uninstalling numpy and sklearn from conda to pip

  • @airstrike5062
    @airstrike5062 Рік тому

    I'd rather not have to use conda tbh

  • @smoochie3331
    @smoochie3331 2 роки тому

    You waste so much time installing those tools. One word > DOCKER

  • @benc7910
    @benc7910 7 місяців тому +1

    when I restarted as shown in @6:10 and reopened my terminal, I don't see (base) next to my username, how to fix this ?

    • @martin__n-i8f
      @martin__n-i8f 6 місяців тому

      add manually miniforge to your shell file with:
      echo "source ~/miniforge3/bin/activate" >> ~/.zshrc
      echo "conda activate" >> ~/.zshrc
      and then activate the conda env with:
      source ~/miniforge3/bin/activate
      hope I helped

    • @BasudevThapa-f6v
      @BasudevThapa-f6v 3 місяці тому

      @@martin__n-i8f thqnk you sir for your service

  • @csalgo5671
    @csalgo5671 2 роки тому

    Thanks man you are awesome