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
Installs from PyPI. Gets the latest stable release automatically.
Editable install. Changes to source take effect immediately.
Using system numpy avoids compilation time on ARM.
Verify Installation
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.
import lowmind as lm import numpy as np
Define Your Model
Use Sequential to stack layers, or subclass Module for custom architectures.
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.
# 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.
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.
# 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.
# 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.
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.
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.
# Accumulate 4 small batches # = effective batch size à 4 trainer = lm.Trainer( model=model, optimizer=optimizer, loss_fn=loss_fn, grad_accum_steps=4, )
- Use
model.eval()during inference to disable Dropout and save memory - Set
requires_grad=Falsefor all parameters during inference - Use
TinyResNetwithbase_filters=8for very tight memory budgets - Call
lm.memory_manager.free_unused()periodically during long training runs - Use the
ModelProfilerto estimate FLOPs before deploying to understand compute cost