Skip to content

Add PyTorch track to the lesson - #639

Draft
ashwinvis wants to merge 1 commit into
mainfrom
add-pytorch-track
Draft

Add PyTorch track to the lesson#639
ashwinvis wants to merge 1 commit into
mainfrom
add-pytorch-track

Conversation

@ashwinvis

Copy link
Copy Markdown
Collaborator

Implemented in @mimer-ai/deep-learning-intro by the following authors:

Initial version. More changes required as noted in #631

Implemented in @mimer-ai/deep-learning-intro by the following
authors:

- @ashwinvis Ashwin
- @otaub Oskar
- @ffrancesco94 Francesco
- @marlon-tobaben Marlon
- @lodo1995 Lodovico

Initial version. More changes required as noted in #631
@github-actions

github-actions Bot commented Mar 10, 2026

Copy link
Copy Markdown

Thank you!

Thank you for your pull request 😃

🤖 This automated message can help you check the rendered files in your submission for clarity. If you have any questions, please feel free to open an issue in {sandpaper}.

If you have files that automatically render output (e.g. R Markdown), then you should check for the following:

  • 🎯 correct output
  • 🖼️ correct figures
  • ❓ new warnings
  • ‼️ new errors

Rendered Changes

🔍 Inspect the changes: https://github.com/carpentries-lab/deep-learning-intro/compare/md-outputs..md-outputs-PR-639

The following changes were observed in the rendered markdown documents:

 1-introduction.md                                  |  21 +-
 2-keras.md                                         | 643 +++++++++++++---
 3-monitor-the-model.md                             | 813 ++++++++++++++++++++-
 4-advanced-layer-types.md                          | 576 ++++++++++++++-
 5-transfer-learning.md                             | 466 +++++++++++-
 6-outlook.md                                       |   2 +-
 ...ing_history_transfer_learning_pytorch.png (new) | Bin 0 -> 26609 bytes
 learner-profiles.md                                |   8 +-
 md5sum.txt                                         |  16 +-
 setup.md                                           | 102 ++-
 10 files changed, 2450 insertions(+), 197 deletions(-)
What does this mean?

If you have source files that require output and figures to be generated (e.g. R Markdown), then it is important to make sure the generated figures and output are reproducible.

This output provides a way for you to inspect the output in a diff-friendly manner so that it's easy to see the changes that occur due to new software versions or randomisation.

⏱️ Updated at 2026-03-10 14:48:03 +0000

@ashwinvis
ashwinvis marked this pull request as draft March 10, 2026 14:46
@ashwinvis ashwinvis changed the title Checkout changes with Pytorch Add PyTorch track to the lesson Mar 10, 2026
github-actions Bot pushed a commit that referenced this pull request Mar 10, 2026

@carschno carschno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at some parts of the draft. It looks very good, thanks a lot!
I have added a few minor comments and left suggestions when I spotted typos etc.


![As a result of the optimization process, the different layers of a neural network tend to learn increasingly abstract representations of the input data.
](fig/01_nn_abstraction_layers.png)
](fig/01_nn_abstraction_layers.png){alt='Example of two different neural networks and how each layer process different abstract representations of input data'}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
](fig/01_nn_abstraction_layers.png){alt='Example of two different neural networks and how each layer process different abstract representations of input data'}
](fig/01_nn_abstraction_layers.png){alt='Example of two different neural networks and how each layer processes different abstract representations of the input data'}

Comment thread learners/setup.md

```shell
python3 -m pip install jupyter seaborn scikit-learn pandas tensorflow pydot
python3 -m pip install jupyter seaborn scikit-learn pandas tqdm torchinfo torchmetrics torch torchvision

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure all of these packages need to be installed explicitly, e.g. tqdm and torch should be indirect dependencies. Only pointing it out because it might cause resolution difficulties in the future.

Comment thread episodes/2-keras.md
because the accuracy of a model depends on the data used to train and test it.
:::

### Scale the input features

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to separate the scaling addition for quicker merging.

Comment thread episodes/2-keras.md

<!-- end-tab --><!-- end-tab -->

###### PyTorch

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this would be a good occasion to point out the advantages of Keras? Ie. higher-level abstraction allowing easier usage for standard use cases.

Comment thread episodes/2-keras.md
For this episode it is useful if everyone gets the same results from their training.
Keras uses a random number generator at certain points during its execution.
Therefore we will need to set two random seeds, one for numpy and one for tensorflow:
Keras and PyTorch uses a random number generator at certain points during its execution.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Keras and PyTorch uses a random number generator at certain points during its execution.
Keras and PyTorch use a random number generator at certain points during its execution.

Comment thread episodes/2-keras.md
Comment on lines +519 to +521
In Pytorch, the architecture of a neural network is defined in a class that
inherits from `torch.nn.Module`. The network itself is created by stacking
layers and linking them together. In this episode, we will only use one type of

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps change the perspective: start from the concept (layer/modules) that are implemented as Module classes, along these lines:

Suggested change
In Pytorch, the architecture of a neural network is defined in a class that
inherits from `torch.nn.Module`. The network itself is created by stacking
layers and linking them together. In this episode, we will only use one type of
In Pytorch, a neural network is defined as a set of neural network layer modules thatin a class that are stacked and linked together. These modules are implemented as classes inheriting from `torch.nn.Module`.
In this episode, we will only use one type of

Comment thread episodes/2-keras.md
Comment on lines +530 to +541
class PenguinModel(torch.nn.Module):
def __init__(self, input_shape):
super().__init__()
self.hidden_layer = torch.nn.Linear(input_shape, 10)
self.output_layer = torch.nn.Linear(10, 3)

def forward(self, x):
x = self.hidden_layer(x)
x = torch.nn.functional.relu(x)
x = self.output_layer(x)
x = torch.nn.functional.softmax(x, dim=1)
return x

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example might raise the question why some layers are defined on class level (self.hidden_layer and self.output_layer), while others are defined in the forward() method.
Perhaps briefly indicate the difference (activation layers). I think this is a key difference to Keras which by default abstracts these things away.

Comment thread episodes/2-keras.md

###### PyTorch

To run inference (i.e. make predictions) with Pytorch, we need to set the model in "evaluation mode".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To run inference (i.e. make predictions) with Pytorch, we need to set the model in "evaluation mode".
To run inference (i.e. make predictions) with Pytorch, we need to set the model in "evaluation mode" to avoid that its parameters are changed.

Comment thread learners/setup.md
[Keras can also use either PyTorch or JAX as a backend](https://keras.io/getting_started/#configuring-your-backend).

Note for MacOS users: there is a package `tensorflow-metal` which accelerates the training of machine learning models with TensorFlow on a recent Mac with a Silicon chip (M1/M2/M3).
However, the installation is currently broken in the most recent version (as of January 2025), see the [developer forum](https://developer.apple.com/forums/thread/772147).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This presumably needs to be updated (out of scope for this PR).

Comment thread learners/setup.md
Alternatively you can use [Google colab](https://colab.research.google.com/). If you open a jupyter notebook here, the required packages are already pre-installed. Note that google colab uses jupyter notebook instead of Jupyter Lab.
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/mimer-ai/deep-learning-intro/scaffolds)

If a local installation does not work for you, it is also possible to run this lesson in [Binder Hub](https://mybinder.org/v2/gh/mimer-ai/deep-learning-intro/scaffolds). This should give you an environment with all the required software and data to run this lesson, nothing which is saved will be stored, please copy any files you want to keep. Note that if you are the first person to launch this in the last few days it can take several minutes to startup. The second person who loads it should find it loads in under a minute. Instructors who intend to use this option should start it themselves shortly before the workshop begins.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to extract the cloud solutions section to a separate PR, too, to facilitate quicker merging.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. Will do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants