🏠 Home ⚡ Features 📚 API Reference 💡 Examples đŸ“Ļ Installation 📋 Changelog
đŸ“Ļ Installation Guide

Get LowMind Running Fast

Install in seconds with pip, from source, or on your Raspberry Pi. Just two dependencies required.

🐍

Python 3.7+

Any modern Python version works. Tested on 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.

đŸ“Ļ

numpy â‰Ĩ 1.19.0

The only computation dependency. Available on every platform including Raspberry Pi OS.

đŸ–Ĩī¸

psutil â‰Ĩ 5.8.0

Used for system monitoring (CPU, RAM, temperature). Optional for basic training tasks.

Choose Your Platform

Recommended
pip install lowmind
✓ Recommended

Installs from PyPI. Gets the latest stable release automatically.

From Source
# Clone the repository
git clone https://github.com/
    dhaval-vedra/lowmind.git
cd lowmind

# Install in editable mode
pip install -e .
â„šī¸ Development Mode

Editable install. Changes to source take effect immediately.

🍓 Raspberry Pi OS
# System packages first
sudo apt update
sudo apt install \
  python3-pip \
  python3-numpy \
  python3-psutil

# Then install LowMind
pip3 install lowmind
🍓 Pi Tip

Using system numpy avoids compilation time on ARM.

Verify Installation

python
import lowmind as lm
print(lm.__version__)   # → '2.1.0'

# Quick smoke test
t = lm.Tensor([1.0, 2.0, 3.0], requires_grad=True)
loss = (t ** 2).sum()
loss.backward()
print(t.grad)   # → [2., 4., 6.]
print("✓ LowMind installed correctly!")

First Model in Minutes

Import LowMind

Import the framework. The convention is import lowmind as lm.

python
import lowmind as lm
import numpy as np

Define Your Model

Use Sequential to stack layers, or subclass Module for custom architectures.

python
model = lm.Sequential(
    lm.Linear(784, 128),
    lm.ReLU(),
    lm.Dropout(0.3),
    lm.Linear(128, 10),
)
print(model)
print(f"Parameters: {model.num_parameters():,}")

Prepare Data

Wrap your numpy arrays in TensorDataset and iterate with DataLoader.

python
# Synthetic data (replace with real data)
X = np.random.randn(1000, 784).astype(np.float32)
y = np.random.randint(0, 10, 1000)

X_train, X_val, y_train, y_val = lm.train_test_split(
    X, y, test_size=0.2, seed=42
)

train_loader = lm.DataLoader(
    lm.TensorDataset(X_train, y_train),
    batch_size=64, shuffle=True
)

Train with Trainer (High-Level)

Use the built-in Trainer to skip the boilerplate — or write your own loop for full control.

python
trainer = lm.Trainer(
    model=model,
    optimizer=lm.Adam(model.parameters(), lr=1e-3),
    loss_fn=lm.cross_entropy_loss,
    callbacks=[
        lm.EarlyStopping(patience=10),
        lm.ModelCheckpoint('/tmp/best.lmz'),
    ],
    verbose=1,
)
history = trainer.fit(train_loader, val_loader, epochs=50)

Save & Load

Save your trained model with gzip compression. Load it back with one line.

python
# Save (gzip compressed)
model.save('/path/to/model.lmz')

# Load later
model.load('/path/to/model.lmz')

# Inference
model.eval()
predictions = trainer.predict(X_test)

Optimizing for Constrained Devices

âš™ī¸

Configure Memory Limit

Set a memory cap appropriate for your Pi model to prevent OOM crashes.

python
# For Pi 3 (1GB RAM), use 256MB
lm.configure_memory(max_mb=256)

# For Pi Zero (512MB RAM)
lm.configure_memory(max_mb=128)
📡

Monitor System Health

Check CPU temp, RAM usage, and health score before and during training.

python
monitor = lm.SystemMonitor()
monitor.print_status()

# Health score 0-100
score = monitor.health_score()
if score < 50:
    print("Warning: system under stress")
🔍

Trace Memory Usage

Use context manager to find which operations consume the most memory.

python
with lm.memory_trace("Forward Pass"):
    out = model(X_batch)

# Optimize for inference only
lm.memory_manager.optimize_for_inference()
🚀

Use Gradient Accumulation

Simulate large batch sizes on Pi without running out of memory.

python
# Accumulate 4 small batches
# = effective batch size × 4
trainer = lm.Trainer(
    model=model,
    optimizer=optimizer,
    loss_fn=loss_fn,
    grad_accum_steps=4,
)
Pro Tips for Raspberry Pi:
  • Use model.eval() during inference to disable Dropout and save memory
  • Set requires_grad=False for all parameters during inference
  • Use TinyResNet with base_filters=8 for very tight memory budgets
  • Call lm.memory_manager.free_unused() periodically during long training runs
  • Use the ModelProfiler to estimate FLOPs before deploying to understand compute cost