Skip to main content

A simple deep learning framework built upon numpy only

Project description

Deep Atomic

A simple deep learning framework built upon numpy only. Mainly for practice and learning.

Usage

Installation

pip install deep-atomic

# or using uv
uv add deep-atomic

Import

import deep_atomic as da
import numpy as np   # required for tensor initialization and some operations

Creating a Tensor

# Create a tensor from a NumPy array (requires_grad=True by default)
a = da.Tensor(
    np.array([1, 2, 3], dtype=np.float64),
    requires_grad=True
)

Supported Operations

Most essential deep‑learning operations are implemented. For those that also exist in NumPy, we follow NumPy's API conventions.

a, b = da.Tensor(np.random.rand(3, 4)), da.Tensor(np.random.rand(3, 4))

c = a + b                     # addition
c = a - b                     # subtraction
c = a * b                     # element‑wise multiplication
c = a / b                     # element‑wise division
c = a ** b                    # element‑wise power
c = a @ b                     # matrix multiplication

c = da.exp(a)
c = da.log(a)
c = da.sin(a)
# the same for cos, tan, arcsin, arccos, arctan, sinh, cosh, tanh, arcsinh, arccosh, arctanh

d = a < b                     # element-wise comparison, create a boolean tensor
e = a <= b
c = a > b
c = a >= b
c = a == b
c = a != b
c = da.fmax(a, b)             # IMPORTANT: here da.fmax is identical to da.maximum, for simplicity. same for da.fmin / da.minimum
c = da.maximum(a, b)
c = da.fmin(a, b)
c = da.minimum(a, b)

c = da.logical_and(d, e)                     # element-wise and
c = da.logical_or(d, e)                      # element-wise or
c = da.logical_xor(d, e)                     # element-wise xor
c = da.logical_not(d)                        # element-wise not
c = d.all(axis=-1, keepdims=False)           # reduction of and operation. axis=None, keepdims=False by default
c = d.any(axis=-1, keepdims=False)           # reduction of or operation. axis=None, keepdims=False by default
c = da.where(d, a, b)                        # return elements chosen from a or b depending on condition

c = da.topk(a, 2, axis=-1, largest=True)    # same as pytorch. axis=-1, largest=True by default

c = da.sum(a)                               # shape: (1,)
c = da.sum(a, axis=1)                       # shape: (3,)
c = da.sum(a, axis=1, keepdims=True)        # shape: (3, 1)
# min, max, argmin, argmax follow the same signature
# all reductions set axis=None, keepdims=False by default

c = da.softmax(a, axis=-1, temperature=0.6) # support temperature. temperature=1 by default
c = da.log_softmax(a, axis=-1, temperature=0.6)

c = da.sigmoid(a)
c = da.silu(a)
c = da.relu(a)
c = da.gelu(a) # Deep Atomic uses the tanh approximation for speed and convenience

c = a.reshape(2, 6)
c = a.reshape(1, 12).squeeze(0)               # shape: (12,)
c = da.expand_dims(a, -1)                     # shape: (3, 4, 1)
c = a.expand_dims(-1)                         # method‑style alternative
c = a.repeat(2, axis=1)                       # shape: (3, 8)
c = da.tile(a, (2, 2))                        # shape: (6, 8)
c = a.tile(2, 2)                              # method‑style alternative

Autograd

Autograd is supported via computational graph. Currently only support scalar source points.

x = Tensor(np.random.rand(3, 4)) # requires_grad == True by default
res = ... # some calculation related to x. res is a **scalar** result
res.backward()
print(res.grad) # gradient get!

Todo

  • more basic operations and their autograd
    • topk
    • boolean operations
    • gather or take_along_axis
    • scatter
    • convolution and 2d convolution
    • pooling
    • softmax attention
    • direct masking and indexing via [] syntax
    • einsum
    • normalization
  • support backward with Vector-Jacobian Product like pytorch
  • basic neural network modules
  • optimizers and loss functions
  • dataset pipelines
  • save and load state dict file
  • full training test
  • benchmark with pytorch on CPU
  • full LLM training
  • finer type annotations, comments and documentation

Development

Recommend manage dependencies using uv. We use pre-commit to manage hooks which help to lint and format our code.

uv sync
pre-commit install # install pre-commit git hooks for lint and format

Run tests:

cd tests
pytest

Build wheels:

uv build

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

deep_atomic-0.2.1.tar.gz (65.2 kB view details)

Uploaded Source

Built Distribution

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

deep_atomic-0.2.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file deep_atomic-0.2.1.tar.gz.

File metadata

  • Download URL: deep_atomic-0.2.1.tar.gz
  • Upload date:
  • Size: 65.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deep_atomic-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fd7a2f266780a502db006c2d7cab09c7f4f55b20b9bb5f0946f1a5fac49657e3
MD5 57cfb95e910bbb461f756accd9002e15
BLAKE2b-256 41df2ad305f5313d627e66ee6d356918d053d0d840c581e7b6e02f0b9c6ec397

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_atomic-0.2.1.tar.gz:

Publisher: publish-pypi.yml on elliot-zzh/deep-atomic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deep_atomic-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: deep_atomic-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deep_atomic-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f23a42b3d4942db094d5981e2893b59e995ec862593d37671136cc9fcaa5ad94
MD5 de5b0c4b2cdc7ce148ba153b2e2cfc50
BLAKE2b-256 6319ca1064fd3f7838a3c913e12b0c925d07e47599f42181af07aef064a709c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_atomic-0.2.1-py3-none-any.whl:

Publisher: publish-pypi.yml on elliot-zzh/deep-atomic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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