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

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии • 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 года назад +25

    good to see this finally working. Thanks Daniel!

  • @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!

  • @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.

  • @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.

  • @shouryabhosale4636
    @shouryabhosale4636 7 месяцев назад

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

  • @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!

  • @jordandavis406
    @jordandavis406 2 года назад

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

  • @fysiki8827
    @fysiki8827 Год назад +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.

  • @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.

  • @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?

  • @paulmcdevitt2038
    @paulmcdevitt2038 2 года назад

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

  • @WhatsAI
    @WhatsAI 2 года назад

    Glad to see you post another video Daniel! :)

  • @Flyforward226
    @Flyforward226 2 года назад

    Glad to see you back!

  • @schuylerblasy2192
    @schuylerblasy2192 2 года назад

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

  • @MyClashes
    @MyClashes Год назад

    first time a youtube tutorial with 0 problems

  • @xinyaoyin2238
    @xinyaoyin2238 7 месяцев назад +2

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

  • @lzdps
    @lzdps 2 года назад +1

    Nice to have these detailed steps!

  • @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?

  • @palahnuk1
    @palahnuk1 Год назад

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

  • @duiliosotelo1005
    @duiliosotelo1005 Год назад

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

  • @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'

  • @Andrew_J123
    @Andrew_J123 2 года назад

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

  • @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.

  • @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?

  • @yonikremer4135
    @yonikremer4135 2 года назад

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

  • @Alex-uc8co
    @Alex-uc8co 2 года назад

    Can you run some speed comparisons? M1 vs Google Colab

  • @ScarletRender
    @ScarletRender Год назад

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

  • @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?

  • @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!

  • @pivotstance
    @pivotstance 9 месяцев назад

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

  • @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?

  • @lukeauslender6494
    @lukeauslender6494 Год назад

    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?

  • @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

  • @muhammadamine6059
    @muhammadamine6059 Год назад

    the only tutorial that worked for me

  • @mahaalabduljalil6596
    @mahaalabduljalil6596 4 месяца назад

    Thaaaaank you ! worked beautifully with my M2 macbook air

  • @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!

  • @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

  • @ikanez
    @ikanez 2 года назад

    Awesome. Thanks for the tutorial Daniel. Works great.

  • @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”

  • @benc7910
    @benc7910 9 месяцев назад +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 ?

    • @icebergov
      @icebergov 8 месяцев назад

      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 5 месяцев назад

      @@icebergov thqnk you sir for your service

  • @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:(

  • @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 ?

  • @dragonlord1225
    @dragonlord1225 Год назад

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

  • @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

  • @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

  • @xabelh.h2772
    @xabelh.h2772 2 года назад

    annaconda support m1 natively

  • @mikahoy
    @mikahoy 2 года назад

    is it applicable also in mac M2?

  • @JaskoonerSingh
    @JaskoonerSingh 2 года назад

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

  • @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

  • @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?

  • @eluz7903
    @eluz7903 Год назад

    Thank you very much for this very clear tutorial.

  • @xinyaoyin2238
    @xinyaoyin2238 Год назад

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

    • @mrdbourke
      @mrdbourke  Год назад +1

      Thank you Xinyao! Welcome to the channel!

  • @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.

  • @iamrsps
    @iamrsps Год назад

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

  • @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 9 месяцев назад

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

  • @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)

  • @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"

  • @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?

  • @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

  • @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

  • @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

  • @_The_Leader_
    @_The_Leader_ Год назад

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

  • @tolga_x
    @tolga_x 10 месяцев назад

    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.

  • @jhy3480
    @jhy3480 2 года назад

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

  • @aleksaggor
    @aleksaggor 2 года назад

    Thank you for the video, just what I needed!

    • @mrdbourke
      @mrdbourke  2 года назад

      You're welcome Aleksander, enjoy!

  • @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

  • @masterbobp
    @masterbobp 2 года назад

    Worked, Thank you very much

  • @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.

  • @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

  • @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)

  • @jonathangreene682
    @jonathangreene682 2 года назад

    SUPER HELPFUL! Thank you.

    • @mrdbourke
      @mrdbourke  2 года назад

      You’re welcome Jonathan :)

  • @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

  • @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.

  • @i_like_it5339
    @i_like_it5339 2 года назад +1

    Not all heroes wear capes

  • @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 ...

  • @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/

  • @smoochie3331
    @smoochie3331 2 года назад

    Jeez, have u heard docker?

  • @Mr.AIFella
    @Mr.AIFella Год назад

    Thanks alot. V. Helpful

  • @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

  • @AstroPinoy
    @AstroPinoy Год назад

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

  • @satyajeetpatil8177
    @satyajeetpatil8177 9 месяцев назад

    You're a legend

  • @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

  • @lifeisbeautifu1
    @lifeisbeautifu1 Год назад

    Thank you!

  • @ketchupparty9997
    @ketchupparty9997 Год назад

    It worked thanks

  • @ShivanS
    @ShivanS 2 года назад

    also congrats on the house purchase too.

    • @mrdbourke
      @mrdbourke  2 года назад +1

      Thank you! I appreciate it legend

  • @oyilenaanblessed-sayah7235
    @oyilenaanblessed-sayah7235 Год назад

    It works!!!!

  • @rissalatahmed6719
    @rissalatahmed6719 Год назад

    Thank you!

  • @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/

  • @ammaransari2073
    @ammaransari2073 2 года назад

    Thx

  • @egyptianluvr9223
    @egyptianluvr9223 2 года назад

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

  • @airstrike5062
    @airstrike5062 Год назад

    I'd rather not have to use conda tbh

  • @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.

  • @smoochie3331
    @smoochie3331 2 года назад

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

  • @csalgo5671
    @csalgo5671 2 года назад

    Thanks man you are awesome