From 3c28f2bce8a79c6556407ed01f105ebdc8034e73 Mon Sep 17 00:00:00 2001 From: Daniel Bourke Date: Tue, 10 May 2022 11:58:56 +1000 Subject: [PATCH] update 05 --- 05_pytorch_going_modular.md | 12 +++++++----- docs/05_pytorch_going_modular.md | 16 +++++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/05_pytorch_going_modular.md b/05_pytorch_going_modular.md index f498035..927b796 100644 --- a/05_pytorch_going_modular.md +++ b/05_pytorch_going_modular.md @@ -2,7 +2,7 @@ This section answers the question, "how do I turn my notebook code into Python scripts?" -To do so, we're going to turn the code cells in notebook 04 into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular). +To do so, we're going to turn the most useful code cells in [notebook 04. PyTorch Custom Datasets](https://www.learnpytorch.io/04_pytorch_custom_datasets/) into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular). ## What is going modular? @@ -43,7 +43,9 @@ But this list sums up a few of the main topics. | **Notebooks** | Easy to experiment/get started | Versioning can be hard | | | Easy to share (e.g. a link to a Google Colab notebook) | Hard to use only specific parts | | | Very visual | Text and graphics can get in the way of code | + | | **Pros** | **Cons** | +| ----- | ----- | ----- | | **Python scripts** | Can package code together (saves rewriting similar code across different notebooks) | Experimenting isn't as visual (usually have to run the whole script rather than one cell) | | | Can use git for versioning | | | | Many open source projects use scripts | | @@ -55,7 +57,7 @@ I usually start machine learning projects in Jupyter/Google Colab notebooks for Then when I've got something working, I move the most useful pieces of code to Python scripts. -one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working. +one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working. *There are many possible workflows for writing machine learning code. Some prefer to start with scripts, others (like me) prefer to start with notebooks and go to scripts later on.* @@ -69,7 +71,7 @@ For example, you might be instructred to run code like the following in a termin python train.py --model MODEL_NAME --batch_size BATCH_SIZE --lr LEARNING_RATE --num_epochs NUM_EPOCHS ``` -command line call for training a PyTorch model with different hyperparameters +command line call for training a PyTorch model with different hyperparameters *Running a PyTorch `train.py` script on the command line with various hyperparameter settings.* @@ -89,7 +91,7 @@ You could setup any number of these argument flags in your `train.py` script to The PyTorch blog post for training state-of-the-art computer vision models uses this style. -PyTorch training script recipe for training state of the art computer vision models +PyTorch training script recipe for training state of the art computer vision models *PyTorch command line training script recipe for training state-of-the-art computer vision models with 8 GPUs. Source: [PyTorch blog](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/#the-training-recipe).* @@ -112,7 +114,7 @@ Because sometimes the best way to learn something is to see how it *differs* fro If you run each notebook side-by-side you'll see how they differ and that's where the key learnings are. -running cell mode notebook vs a script mode notebook +running cell mode notebook vs a script mode notebook *Running the two notebooks for section 05 side-by-side. You'll notice that the **script mode notebook has extra code cells** to turn code from the cell mode notebook into Python scripts.* diff --git a/docs/05_pytorch_going_modular.md b/docs/05_pytorch_going_modular.md index 884f01a..927b796 100644 --- a/docs/05_pytorch_going_modular.md +++ b/docs/05_pytorch_going_modular.md @@ -2,7 +2,7 @@ This section answers the question, "how do I turn my notebook code into Python scripts?" -To do so, we're going to turn the code cells in notebook 04 into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular). +To do so, we're going to turn the most useful code cells in [notebook 04. PyTorch Custom Datasets](https://www.learnpytorch.io/04_pytorch_custom_datasets/) into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular). ## What is going modular? @@ -43,7 +43,9 @@ But this list sums up a few of the main topics. | **Notebooks** | Easy to experiment/get started | Versioning can be hard | | | Easy to share (e.g. a link to a Google Colab notebook) | Hard to use only specific parts | | | Very visual | Text and graphics can get in the way of code | + | | **Pros** | **Cons** | +| ----- | ----- | ----- | | **Python scripts** | Can package code together (saves rewriting similar code across different notebooks) | Experimenting isn't as visual (usually have to run the whole script rather than one cell) | | | Can use git for versioning | | | | Many open source projects use scripts | | @@ -55,7 +57,7 @@ I usually start machine learning projects in Jupyter/Google Colab notebooks for Then when I've got something working, I move the most useful pieces of code to Python scripts. -one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working. +one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working. *There are many possible workflows for writing machine learning code. Some prefer to start with scripts, others (like me) prefer to start with notebooks and go to scripts later on.* @@ -69,7 +71,7 @@ For example, you might be instructred to run code like the following in a termin python train.py --model MODEL_NAME --batch_size BATCH_SIZE --lr LEARNING_RATE --num_epochs NUM_EPOCHS ``` -command line call for training a PyTorch model with different hyperparameters +command line call for training a PyTorch model with different hyperparameters *Running a PyTorch `train.py` script on the command line with various hyperparameter settings.* @@ -89,7 +91,7 @@ You could setup any number of these argument flags in your `train.py` script to The PyTorch blog post for training state-of-the-art computer vision models uses this style. -PyTorch training script recipe for training state of the art computer vision models +PyTorch training script recipe for training state of the art computer vision models *PyTorch command line training script recipe for training state-of-the-art computer vision models with 8 GPUs. Source: [PyTorch blog](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/#the-training-recipe).* @@ -104,15 +106,15 @@ There are two notebooks for this section: 1. [**05. Going Modular: Part 1 (cell mode)**](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/05_pytorch_going_modular_cell_mode.ipynb) - this notebook is run as a traditional Jupyter Notebook/Google Colab notebook and is a condensed version of [notebook 04](https://www.learnpytorch.io/04_pytorch_custom_datasets/). 2. [**05. Going Modular: Part 2 (script mode)**](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/05_pytorch_going_modular_script_mode.ipynb) - this notebook is the same as number 1 but with added functionality to turn each of the major sections into Python scripts, such as, `data_setup.py` and `train.py`. +The text in this document focuses on the code cells 05. Going Modular: Part 2 (script mode), the ones with `%%writefile ...` at the top. + ### Why two parts? Because sometimes the best way to learn something is to see how it *differs* from something else. If you run each notebook side-by-side you'll see how they differ and that's where the key learnings are. -The text in this document focuses on 05. Going Modular: Part 2 (script mode). - -running cell mode notebook vs a script mode notebook +running cell mode notebook vs a script mode notebook *Running the two notebooks for section 05 side-by-side. You'll notice that the **script mode notebook has extra code cells** to turn code from the cell mode notebook into Python scripts.*