Skip to main content

A utility library for deep learning notes, providing common functions and tools to support the main content of the deep learning notes collection.

Project description

dnnlpy

dnnlpy is the companion Python package for Deep Learning Notes Library.

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.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.models contains higher-level model architectures or model-specific components, such as ViT, DDPM, or other models introduced in the notes.

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 Library 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.14 or newer
  • PyTorch 3.10 or newer

Installation

This project uses uv for package management.

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 torch
import dnnlpy.nn as dnn

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 torch
import dnnlpy.nn.functional as dF

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
from dnnlpy.models.vit import ViTForImageClassification

model = 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.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dnnlpy-2026.6.11.tar.gz (33.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dnnlpy-2026.6.11-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file dnnlpy-2026.6.11.tar.gz.

File metadata

  • Download URL: dnnlpy-2026.6.11.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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

Hashes for dnnlpy-2026.6.11.tar.gz
Algorithm Hash digest
SHA256 4399aa6c17eb7ca05052754381adf5075da9759fbd2b34027a72eb94d5dc0428
MD5 4fd3773253a5d857370a3cf865bbffdd
BLAKE2b-256 bf4f8db1bb5e020e04493daafe088e4564652ca67b05ff22c6abab9880d51260

See more details on using hashes here.

File details

Details for the file dnnlpy-2026.6.11-py3-none-any.whl.

File metadata

  • Download URL: dnnlpy-2026.6.11-py3-none-any.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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

Hashes for dnnlpy-2026.6.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c8816a011a62e0df4121d3db138f65399839ac68b9c6e796403987e6ceacc7ee
MD5 64b12e0e0aa7dd787f2ab3a8b5e4a332
BLAKE2b-256 1fdd4e6b9f9cf427d37af94a5ed5bf8c591448147ac91f9a2cae3e0798dafd24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page