Skip to main content

Lightweight ML framework for Apple Silicon and CPU — no CUDA required

Project description

🌫️ Kiri

Lightweight ML for everyone. No CUDA required.

Kiri is a Python deep learning framework that runs natively on Apple Silicon (M1/M2/M3/M4) and falls back gracefully to CPU on any machine. Built for students and developers who want to train real models without a $3000 gaming PC.


The problem

You're in an ML course. The assignment asks you to train a CNN on MNIST. Your classmates with gaming rigs are done in 5 minutes. You have a MacBook Air or a budget laptop. You either wait 3 hours, crash out of memory, or cry into your coffee.

Kiri fixes this.


How it works

import kiri

That's it. Kiri auto-detects your hardware on import:

╭─ Kiri 🌫️ ─────────────────────────────╮
│  Backend  : Apple Silicon (MLX)        │
│  Chip     : arm64                      │
│  Memory   : 16GB unified memory        │
│  Status   : ✓ Metal GPU + CPU active   │
╰────────────────────────────────────────╯
  Kiri v0.1.0 ready — backend: mlx
  • Apple Silicon (M1/M2/M3/M4) → uses MLX under the hood. Metal GPU acceleration, unified memory (no VRAM limit), fast.
  • Everything else (Intel Mac, Windows, Linux) → runs on NumPy with a built-in autograd engine. Slower, but it works.

Install

# For Apple Silicon (recommended)
pip install kiri[apple]

# For CPU-only
pip install kiri

Quick start

import numpy as np
import kiri
import kiri.nn as nn

# Define a model
class MyCNN(kiri.Model):
    def __init__(self):
        self.conv    = nn.Conv2d(1, 16, kernel_size=3, padding=1)
        self.relu    = nn.ReLU()
        self.flatten = nn.Flatten()
        self.fc      = nn.Linear(16 * 28 * 28, 10)

    def forward(self, x):
        x = self.relu(self.conv(x))
        x = self.flatten(x)
        return self.fc(x)

# Train it
model = MyCNN()
history = model.fit(X_train, y_train, epochs=10, lr=1e-3, batch_size=32)

# Evaluate
acc = model.accuracy(X_test, y_test)
print(f"Accuracy: {acc*100:.1f}%")

What's supported (v0.1)

Layers

Layer Notes
nn.Linear(in, out) Fully connected
nn.Conv2d(in, out, k) 2D convolution
nn.BatchNorm1d(n) Batch normalization
nn.Dropout(p) Dropout
nn.Flatten() Reshape to (N, -1)
nn.Sequential(*layers) Stack layers

Activations

nn.ReLU · nn.LeakyReLU · nn.Sigmoid · nn.Tanh · nn.Softmax · nn.GELU

Losses

nn.cross_entropy · nn.mse_loss · nn.binary_cross_entropy

Optimizers

optim.SGD · optim.Adam · optim.AdamW

Model API

model.fit(X, y, epochs, lr, batch_size, val_data, verbose)
model.predict(X)
model.predict_classes(X)
model.accuracy(X, y)
model.save("weights.npz")
model.load("weights.npz")

Examples

python examples/mlp_classification.py   # Iris, tabular data
python examples/mnist_cnn.py            # MNIST CNN

Architecture

kiri/
├── __init__.py          # auto-detects hardware, prints report
├── tensor.py            # Tensor class (MLX or NumPy+autograd)
├── model.py             # Model base class (.fit, .predict, .save)
├── nn/
│   ├── layers.py        # Linear, Conv2d, BatchNorm, Dropout, Sequential
│   ├── activations.py   # ReLU, Sigmoid, Softmax, GELU, ...
│   └── loss.py          # cross_entropy, mse_loss, bce
├── optim/
│   └── optimizers.py    # SGD, Adam, AdamW
└── backend/
    ├── detect.py        # hardware detection logic
    └── cpu_conv.py      # im2col Conv2d for CPU backend

The key design decision: Kiri wraps MLX on Apple Silicon rather than reinventing the wheel. MLX already handles Metal GPU dispatch, unified memory, and lazy evaluation. Kiri's job is to give it a familiar, friendly API and make the CPU fallback seamless.


Roadmap

  • MaxPool2d, AvgPool2d
  • RNN, LSTM
  • DataLoader utility
  • Learning rate schedulers
  • Mixed precision training
  • Direct Apple Neural Engine dispatch (experimental)
  • ONNX export

License

MIT

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

kiri_ml-0.1.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

kiri_ml-0.1.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for kiri_ml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 60cbe406541e73bc6f6e090b6d6b634e4dcdd00aec30049d1cddbc06f499e9b1
MD5 6b62e1bd4d5870b7f4867a9f63c50d47
BLAKE2b-256 04408f2bf8c0e671bb92f7a01d8e0f3b51bd599c1b405a36c3fcae1e5c0e3d44

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for kiri_ml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1dee2a394099670a6ab9e296c32947258a1b3ddb87886acb29456581054f0b26
MD5 87347d3c5ae7f9e9e6d12c2ce03a89c3
BLAKE2b-256 c6a1951ba73fadbae8a6fd39e81d409b24ed41a6aa33976abc470be51baab15c

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