Skip to content

Commit

Permalink
Merge branch 'main' into fsd50K_speech_model_finetuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored Aug 14, 2023
2 parents c8f74fc + 89b94ba commit 9794cfc
Show file tree
Hide file tree
Showing 64 changed files with 1,138 additions and 763 deletions.
5 changes: 4 additions & 1 deletion .azure/ipynb-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
COMMIT_HASH: "$(Build.SourceVersion)"
DEVICES: $( python -c 'print("$(Agent.Name)".split("_")[-1])' )

condition: ne(dependencies.check_diff.outputs['mtrx.dirs'], '')
condition: ne(dependencies.sync_pub.outputs['mtrx.dirs'], '')

steps:
- bash: |
Expand Down Expand Up @@ -129,6 +129,8 @@ jobs:
git ls-remote --heads origin ${PUB_BRANCH} | grep ${PUB_BRANCH} >/dev/null
if [ "$?" == "1" ] ; then echo "Branch doesn't exist"; exit; fi
git checkout $(PUB_BRANCH)
git show-ref $(PUB_BRANCH)
git pull
displayName: 'Git check & switch branch'
- bash: |
Expand Down Expand Up @@ -165,5 +167,6 @@ jobs:
- bash: |
git status
git show-ref $(PUB_BRANCH)
git push https://$(PAT_GHOST)@github.com/Lightning-AI/tutorials.git $(PUB_BRANCH)
displayName: 'Finish push'
2 changes: 1 addition & 1 deletion .github/workflows/ci_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ concurrency:
jobs:

check-schema:
uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.5.0
uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.9.0
4 changes: 1 addition & 3 deletions .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ jobs:

- name: Make Documentation
working-directory: ./_docs
run: |
# First run the same pipeline as Read-The-Docs
make html --debug SPHINXOPTS="-W --keep-going" -b linkcheck
run: make html --jobs $(nproc) --debug SPHINXOPTS="-W --keep-going" linkcheck

- name: Upload built docs
uses: actions/upload-artifact@v3
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci_test-acts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ jobs:
- name: Install requirements
run: |
pip --version
pip install -q -r .actions/requires.txt
pip install -q "pytest==6.*" coverage jupytext
pip install -q -r .actions/requires.txt -r _requirements/test.txt
# this is needed to be able to run package version parsing test
pip install -q matplotlib -r _requirements/default.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
pip install -q -r _requirements/default.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
- name: Prepare dummy inputs
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: make html --jobs $(nproc)

- name: Deploy 🚀
uses: JamesIves/[email protected].1
uses: JamesIves/[email protected].3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ dmypy.json
.pyre/

.idea/

# data artifacts
logs/
lightning_logs/
cifar-10-batches-py
*.tar.gz
17 changes: 9 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ repos:
- id: detect-private-key

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.8.0
hooks:
- id: pyupgrade
args: [--py37-plus]
name: Upgrade code

- repo: https://github.com/PyCQA/docformatter
rev: v1.5.1
rev: v1.7.3
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]

- repo: https://github.com/PyCQA/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
name: Format code

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
rev: v1.5.0
hooks:
- id: yesqa

Expand All @@ -60,7 +60,8 @@ repos:
- mdformat-black
- mdformat_frontmatter

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
hooks:
- id: flake8
- id: ruff
args: ["--fix"]
21 changes: 15 additions & 6 deletions _docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# If your documentation needs a minimal Sphinx version, state it here.

needs_sphinx = "4.0"
needs_sphinx = "5.3"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand Down Expand Up @@ -224,8 +224,17 @@
# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
# intersphinx_mapping = {
# "python": ("https://docs.python.org/3", None),
# "torch": ("https://pytorch.org/docs/stable/", None),
# "numpy": ("https://docs.scipy.org/doc/numpy/", None),
# }
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"torch": ("https://pytorch.org/docs/stable/", None),
"numpy": ("https://docs.scipy.org/doc/numpy/", None),
}

# skip false positive linkcheck errors from anchors
linkcheck_anchors = False

# ignore all links in any CHANGELOG file
linkcheck_exclude_documents = []

# ignore the following relative links (false positive errors during linkcheck)
linkcheck_ignore = []
10 changes: 6 additions & 4 deletions _requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
setuptools==65.6.3
ipython[notebook]>=8.0.0, <8.9.0
torch>=1.8.1, <1.14.0
pytorch-lightning>=1.4, <1.9
setuptools==68.0.0
matplotlib>=3.0.0, <3.8.0
ipython[notebook]>=8.0.0, <8.15.0
urllib3 # for ipython
torch>=1.8.1, <2.1.0
pytorch-lightning>=1.4, <2.1.0
torchmetrics>=0.7, <0.12
2 changes: 1 addition & 1 deletion _requirements/devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ virtualenv>=20.10
jupytext>=1.10, <1.15 # converting
pytest>=6.0, <7.0
# testing with own fork with extended cell timeout
https://github.com/Borda/nbval/archive/refs/heads/master.zip
https://github.com/Borda/nbval/archive/refs/heads/timeout-limit.zip
papermill>=2.3.4, <2.5.0 # render
16 changes: 8 additions & 8 deletions _requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sphinx>=4.0, <5.0
myst-parser>=0.15
nbsphinx>=0.8
pandoc>=1.0
docutils>=0.16
sphinx-paramlinks>=0.4.0
ipython[notebook]>=8.0.0, <8.2.0
sphinx >5.0, <6.0
myst-parser >=0.18.1, <3.0.0
nbsphinx >=0.8.5, <=0.8.9
pandoc >=1.0, <=2.3
#docutils >=0.16
sphinx-paramlinks >=0.5.1, <=0.5.4
ipython[notebook] >=8.0.0, <8.2.0

https://github.com/Lightning-AI/lightning_sphinx_theme/archive/master.zip#egg=pt-lightning-sphinx-theme
pt-lightning-sphinx-theme @ https://github.com/Lightning-AI/lightning_sphinx_theme/archive/master.zip

-r ../.actions/requires.txt
5 changes: 5 additions & 0 deletions _requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage>=5.0
codecov>=2.1
pytest>=6.0
pytest-cov
jupytext
3 changes: 2 additions & 1 deletion course_UvA-DL/01-introduction-to-pytorch/.meta.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
title: "Tutorial 1: Introduction to PyTorch"
author: Phillip Lippe
created: 2021-08-27
updated: 2021-11-29
updated: 2023-03-14
license: CC BY-SA
description: |
This tutorial will give a short introduction to PyTorch basics, and get you setup for writing your own neural networks.
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
requirements:
- matplotlib
- lightning>=2.0.0rc0
accelerator:
- CPU
- GPU
23 changes: 11 additions & 12 deletions course_UvA-DL/01-introduction-to-pytorch/Introduction_to_PyTorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
import time

import matplotlib.pyplot as plt

# %matplotlib inline
import matplotlib_inline.backend_inline
import numpy as np
import torch
import torch.nn as nn
import torch.utils.data as data

# %matplotlib inline
from IPython.display import set_matplotlib_formats
from matplotlib.colors import to_rgba
from torch import Tensor
from tqdm.notebook import tqdm # Progress bar

set_matplotlib_formats("svg", "pdf")
matplotlib_inline.backend_inline.set_matplotlib_formats("svg", "pdf") # For export

# %% [markdown]
# ## The Basics of PyTorch
Expand Down Expand Up @@ -185,7 +185,7 @@
print("X2 (after)", x2)

# %% [markdown]
# In-place operations are usually marked with a underscore postfix (e.g. "add_" instead of "add").
# In-place operations are usually marked with a underscore postfix (for example `torch.add_` instead of `torch.add`).
#
# Another common operation aims at changing the shape of a tensor.
# A tensor of size (2,3) can be re-organized to any other shape with the same number of elements (e.g. a tensor of size (6), or (3,2), ...).
Expand Down Expand Up @@ -455,7 +455,7 @@

# Additionally, some operations on a GPU are implemented stochastic for efficiency
# We want to ensure that all operations are deterministic on GPU (if used) for reproducibility
torch.backends.cudnn.determinstic = True
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

# %% [markdown]
Expand Down Expand Up @@ -601,10 +601,11 @@ def forward(self, x):

class XORDataset(data.Dataset):
def __init__(self, size, std=0.1):
"""
Inputs:
size - Number of data points we want to generate
std - Standard deviation of the noise (see generate_continuous_xor function)
"""XORDataset.
Args:
size: Number of data points we want to generate
std: Standard deviation of the noise (see generate_continuous_xor function)
"""
super().__init__()
self.size = size
Expand Down Expand Up @@ -800,7 +801,6 @@ def train_model(model, optimizer, data_loader, loss_module, num_epochs=100):
# Training loop
for epoch in tqdm(range(num_epochs)):
for data_inputs, data_labels in data_loader:

# Step 1: Move input data to device (only strictly necessary if we use GPU)
data_inputs = data_inputs.to(device)
data_labels = data_labels.to(device)
Expand Down Expand Up @@ -897,7 +897,6 @@ def eval_model(model, data_loader):

with torch.no_grad(): # Deactivate gradients for the following code
for data_inputs, data_labels in data_loader:

# Determine prediction of model on dev set
data_inputs, data_labels = data_inputs.to(device), data_labels.to(device)
preds = model(data_inputs)
Expand Down
3 changes: 2 additions & 1 deletion course_UvA-DL/02-activation-functions/.meta.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: "Tutorial 2: Activation Functions"
author: Phillip Lippe
created: 2021-08-27
updated: 2021-08-27
updated: 2023-03-14
license: CC BY-SA
description: |
In this tutorial, we will take a closer look at (popular) activation functions and investigate their effect on optimization properties in neural networks.
Expand All @@ -14,6 +14,7 @@ requirements:
- torchvision
- matplotlib
- seaborn
- lightning>=2.0.0rc0
accelerator:
- CPU
- GPU
19 changes: 12 additions & 7 deletions course_UvA-DL/02-activation-functions/Activation_Functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from urllib.error import HTTPError

import matplotlib.pyplot as plt

# %matplotlib inline
import matplotlib_inline.backend_inline
import numpy as np
import seaborn as sns
import torch
Expand All @@ -19,14 +22,11 @@
import torch.optim as optim
import torch.utils.data as data
import torchvision

# %matplotlib inline
from IPython.display import set_matplotlib_formats
from torchvision import transforms
from torchvision.datasets import FashionMNIST
from tqdm.notebook import tqdm

set_matplotlib_formats("svg", "pdf") # For export
matplotlib_inline.backend_inline.set_matplotlib_formats("svg", "pdf") # For export
sns.set()

# %% [markdown]
Expand Down Expand Up @@ -64,7 +64,7 @@ def set_seed(seed):

# Additionally, some operations on a GPU are implemented stochastic for efficiency
# We want to ensure that all operations are deterministic on GPU (if used) for reproducibility
torch.backends.cudnn.determinstic = True
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

# Fetching the device that will be used throughout this notebook
Expand Down Expand Up @@ -141,6 +141,7 @@ def __init__(self):
# Both the sigmoid and tanh activation can be also found as PyTorch functions (`torch.sigmoid`, `torch.tanh`) or as modules (`nn.Sigmoid`, `nn.Tanh`).
# Here, we implement them by hand:


# %%
class Sigmoid(ActivationFunction):
def forward(self, x):
Expand All @@ -166,6 +167,7 @@ def forward(self, x):
#
# Let's implement the four activation functions below:


# %%
class ReLU(ActivationFunction):
def forward(self, x):
Expand Down Expand Up @@ -213,6 +215,7 @@ def get_grads(act_fn, x):
Args:
act_fn: An object of the class "ActivationFunction" with an implemented forward pass.
x: 1D input tensor.
Returns:
A tensor with the same size of x containing the gradients of act_fn at x.
"""
Expand Down Expand Up @@ -277,7 +280,8 @@ def vis_act_fn(act_fn, ax, x):
# %%
class BaseNetwork(nn.Module):
def __init__(self, act_fn, input_size=784, num_classes=10, hidden_sizes=[512, 256, 256, 128]):
"""
"""Base Network.
Args:
act_fn: Object of the activation function that should be used as non-linearity in the network.
input_size: Size of the input images in pixels
Expand Down Expand Up @@ -429,7 +433,8 @@ def save_model(model, model_path, model_name):

# %%
def visualize_gradients(net, color="C0"):
"""
"""Visualize gradients.
Args:
net: Object of class BaseNetwork
color: Color in which we want to visualize the histogram (for easier separation of activation functions)
Expand Down
Loading

0 comments on commit 9794cfc

Please sign in to comment.