This release is a pre-release and may not be stable for production use.
dnnlpy
dnnlpy is the companion Python package for Deep Learning Notes. It provides code examples, helper functions, and small utilities used throughout the tutorial, similar in spirit to the d2l package for Dive into Deep Learning.
The package structure is similar to PyTorch, but keeps a clear boundary between reusable neural network building blocks and complete model implementations:
dnnlpy.nncontains general neural network modules, such as attention layers, positional encodings, and other reusable components.dnnlpy.nn.functionalcontains stateless helper functions, such as functional attention implementations.dnnlpy.optimcontains small optimizer implementations for teaching purposes, such as SGD and Adam.dnnlpy.modelscontains higher-level model architectures or model-specific components, such as ViT, DDPM, or other models introduced in the notes.dnnlpy.cs336contains implementations and utilities for the CS336 assignments.dnnlpy.tokenizerscontains small tokenizer implementations for teaching purposes, such as a simple BPE tokenizer.
The APIs are designed to feel close to their PyTorch counterparts where practical, while still keeping the code lightweight and easy to read for tutorial purposes.
This package is intended as a lightweight code supplement rather than a general-purpose deep learning framework. Its goal is to make the examples in the notes easier to run, reuse, and extend.
What is this package for?
The dnnlpy package is designed to support the code in the Deep Learning Notes tutorial.
It can be used to:
- Organize example code from the notes
- Provide reusable utility functions
- Reduce repeated boilerplate in notebooks and scripts
- Make tutorial examples easier to reproduce
In short, this package serves as the code companion to the tutorial.
Requirements
- Python 3.12 or newer
- PyTorch 2.13 or newer
Installation
Install the published package from PyPI with:
uv pip install dnnlpy
To install the latest version directly from this repository, use:
uv pip install "git+https://github.com/jshn9515/deep-learning-notes.git#subdirectory=dnnlpy"
This project uses uv for local package development.
git clone https://github.com/jshn9515/deep-learning-notes.git
cd dnnlpy
uv pip install .
If you want to modify the package while working through the notes, editable installation is recommended:
uv pip install -e .
This way, changes to the source code take effect immediately without reinstalling the package each time.
Examples
After installation, you can import reusable neural network modules from dnnlpy.nn:
import dnnlpy.nn as dnn
import torch
attn = dnn.MultiheadAttention(embed_dim=16, num_heads=4)
query = torch.randn(2, 8, 16)
key = torch.randn(2, 8, 16)
value = torch.randn(2, 8, 16)
output = attn(query, key, value)
You can also import stateless functions from dnnlpy.nn.functional:
import dnnlpy.nn.functional as dF
import torch
query = torch.randn(2, 4, 8, 16)
key = torch.randn(2, 4, 8, 16)
value = torch.randn(2, 4, 8, 16)
output, weights = dF.scaled_dot_product_attention(
query,
key,
value,
need_weights=True,
)
Higher-level model architectures live under dnnlpy.models:
import torch
import dnnlpy.models.vit as vit
model = vit.ViTForImageClassification(
image_size=224,
patch_size=16,
in_channels=3,
num_classes=1000,
embed_dim=768,
num_heads=12,
num_layers=12,
)
images = torch.randn(2, 3, 224, 224)
logits = model(images)
The dnnlpy.models.mlp package contains small NumPy modules for teaching manual
forward and backward passes:
import dnnlpy.models.mlp as mlp
import numpy as np
model = mlp.MLP(input_dim=4, hidden_dim=8, num_classes=3)
loss_fn = mlp.CrossEntropyLoss()
optimizer = mlp.SGD(model.parameters(), lr=0.1)
x = np.random.randn(2, 4)
targets = np.array([0, 2])
logits = model(x)
loss = loss_fn(logits, targets)
model.backward(loss_fn.backward())
optimizer.step()
optimizer.zero_grad()
A simple rule of thumb is:
- Use
dnnlpy.nnwhen a component is reusable across many models. - Use
dnnlpy.modelswhen the code represents a complete architecture or is tightly coupled to one model family.
License
This project is licensed under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dnnlpy-2026.8.20rc1.tar.gz.
File metadata
- Download URL: dnnlpy-2026.8.20rc1.tar.gz
- Upload date:
- Size: 91.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c11621c00d6cc9839c0b56f9e8abf89e6a0d39e6640cfe75ba872f12d5c29c3
|
|
| MD5 |
d8d10fcf2e4d1a709166c55e392ba7cd
|
|
| BLAKE2b-256 |
e78bf91890b016561f6f2d2695e18c94765457f5188d875846077d075a08f2b8
|
File details
Details for the file dnnlpy-2026.8.20rc1-py3-none-any.whl.
File metadata
- Download URL: dnnlpy-2026.8.20rc1-py3-none-any.whl
- Upload date:
- Size: 129.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba1df93d3e0746df6c319b80ac1cb49602d309c8719a6524dcab6b8eea75652
|
|
| MD5 |
d3a2bac9f4da0627ffa01c87eb0587c5
|
|
| BLAKE2b-256 |
924559537542a483740d5dde5e1d4a85b70f2f03c81c3bae9f908962c71457fe
|