Skip to main content

PyOpenCL-based deep learning playground with autograd, kernels, and high-level APIs.

Project description

netcl – PyOpenCL Deep Learning Playground

netcl ist ein experimentelles Deep-Learning-Framework auf Basis von PyOpenCL. Es kombiniert low-level Kernel (Conv/Matmul/Elementwise) mit einer einfachen Autograd-Engine und einer High-Level API (Module, Trainer, Serializer), ohne Abhängigkeiten zu anderen DL-Frameworks.

Installation

pip install .

Voraussetzungen: Python ≥ 3.10, NumPy, PyOpenCL und ein verfügbares OpenCL-Gerät.

Schnelles Beispiel (MNIST-Mini-MLP)

import numpy as np
from netcl.core.device import manager
from netcl.nn.layers import Sequential, Flatten, Linear, ReLU
from netcl import autograd as ag
from netcl.optim import Adam
from netcl.core.tensor import Tensor

dev = manager.default()
q = dev.queue

model = Sequential(
    Flatten(),
    Linear(q, in_features=28*28, out_features=128),
    ReLU(),
    Linear(q, in_features=128, out_features=10),
)
opt = Adam(model.parameters(), lr=5e-3)

def one_hot(y, n=10):
    oh = np.zeros((y.shape[0], n), dtype=np.float32)
    oh[np.arange(y.shape[0]), y] = 1
    return oh

xb = np.random.randn(32, 1, 28, 28).astype(np.float32)
yb = one_hot(np.random.randint(0, 10, size=(32,)))

tape = ag.Tape()
ag.set_current_tape(tape)
x = ag.tensor(Tensor.from_host(q, xb))
y = ag.tensor(Tensor.from_host(q, yb))
logits = model(x)
loss = ag.cross_entropy(logits, y)
tape.backward(loss)
opt.step(); opt.zero_grad()
ag.set_current_tape(None)

Kernfeatures

  • Autograd: Tape-basiert, elementare Ops (Matmul, Conv2d, Pooling, Elementwise) mit Backward.
  • Module/High-Level API: Linear, Conv2d, BatchNorm2d, Sequential, @model-Dekorator, Trainer.
  • Optimierungen: Conv-Algo-Heuristik/Autotuning, optional Mixed Precision, Buffer-Pool.
  • Serialization: Speichert Sequential-Modelle als JSON (Architektur) + NPZ (Gewichte) via netcl.io.serialization.

Speichern & Laden eines Modells

from netcl.io.serialization import save_model, load_model
save_model(model, "checkpoints/mnist_mlp")
model2 = load_model("checkpoints/mnist_mlp")  # queue auto="default"

Hinweise

  • Tests werden nicht mitinstalliert. Für lokale Entwicklung: python -m pytest.
  • Für Performance: Batch-Größe erhöhen, Augment minimieren, optional Mixed Precision (Trainer(..., mixed_precision=True)).
  • Conv-Algorithmen wählen automatisch optimierte Pfade; env-Flags wie NETCL_CONV_AUTOTUNE=1 aktivieren Tuning.

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

netcl-0.1.0.tar.gz (66.3 kB view details)

Uploaded Source

Built Distribution

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

netcl-0.1.0-py3-none-any.whl (87.2 kB view details)

Uploaded Python 3

File details

Details for the file netcl-0.1.0.tar.gz.

File metadata

  • Download URL: netcl-0.1.0.tar.gz
  • Upload date:
  • Size: 66.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for netcl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 47cf8077c76b178340a9dd3f6eca665eacc3adb1f03d40334e269bc37924fcf4
MD5 db1ed5fd49c45ac6d495a3b07d257e05
BLAKE2b-256 03bc59e9ad9cdfde56245134ac7e7f25bf520240e3526995caedecbd99459533

See more details on using hashes here.

File details

Details for the file netcl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: netcl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 87.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for netcl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c1ff39f0b7124cd87b939a68e6e4f25d9cdf95efe4155956da8e8012ab2ec57
MD5 1f964f38fcc08f228fb351d4047435da
BLAKE2b-256 bc7c2775b2e5b05d1e26f98b9f7b77cb51654edfda2ccd2bbe496bf1d2449211

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