Skip to main content
Pre-release

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.cs224n contains implementations and utilities for the CS224N assignments.
  • dnnlpy.cs336 contains implementations and utilities for the CS336 assignments.
  • dnnlpy.models contains higher-level model architectures or model-specific components, such as MiniGPT and other models introduced in the notes.
  • dnnlpy.nn contains general neural network modules, such as attention layers, positional encodings, and other reusable components.
  • dnnlpy.nn.functional contains stateless helper functions, such as functional attention implementations.
  • dnnlpy.optim contains small optimizer implementations for teaching purposes, such as SGD and Adam.
  • dnnlpy.tokenizers contains 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.14 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.gpt as gpt

model = gpt.MiniGPT(
    vocab_size=1000,
    block_size=128,
    embed_dim=256,
    num_layers=4,
    num_heads=4,
    hidden_dim=1024,
)

input_ids = torch.randint(0, 1000, (2, 32))
logits = model(input_ids)

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.nn when a component is reusable across many models.
  • Use dnnlpy.models when the code represents a complete architecture or is tightly coupled to one model family.

License

This project is licensed under the MIT License.

Metadata

Release files for dnnlpy 2026.9.26rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dnnlpy 2026.9.26rc1
File Size Uploaded
dnnlpy-2026.9.26rc1.tar.gz 92.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dnnlpy 2026.9.26rc1
File Interpreter ABI Platform
dnnlpy-2026.9.26rc1-py3-none-any.whl Python 3 none any Details

Total release size: 221.1 kB

Release files / dnnlpy-2026.9.26rc1.tar.gz

Download URL dnnlpy-2026.9.26rc1.tar.gz
Size 92.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6c9db5f5ce957e67f55366be4122bd2ea7e4ad83bfdef42864fc64ab82536bbe
BLAKE2b-256 checksum
How to use checksums
77901cc36648b4bd79948093b77babeb5c5c801f79ad83ec1c1d8baf33872528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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}

Release files / dnnlpy-2026.9.26rc1-py3-none-any.whl

Download URL dnnlpy-2026.9.26rc1-py3-none-any.whl
Size 128.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edcc325194bbc826abc00a780dc9beb7ec059a7f79380ea50062c7dba729bd54
BLAKE2b-256 checksum
How to use checksums
ca0f7fd03ea00a68689803b1c425224309add71781a30ce4587f7cdf2b2efcbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","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}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page