Local-first, VS Code-driven model development…
Project description
On the Fly
A VS Code dashboard and Python API for orchestrating a hard-sample–guided Mixture-of-Experts (MoE) training workflow. From Python, call quickstart(...) to open a session; monitoring and controls live in the dashboard.
Overview
- Start a run from Python; control and inspect it in VS Code.
- Pause/resume safely and snapshot metrics/checkpoints/buffers.
- Fork short-budget specialists from hard samples or slices.
- Merge improvements back using SWA, distillation, Fisher Soup, or adapter fusion.
- Run fully manual or enable an automated planner with safeguards.
[!IMPORTANT] Project status: Beta. APIs, UI flows, and file formats may change without notice before v1.0. Expect rough edges and please report issues and ideas.
Features
- Mid-training analysis: Inspect per-sample loss histograms, slice reports, cluster previews, gate loads, and expert ancestry without waiting for full epochs.
- Fork & merge tools: Create specialists from residual clusters or loss tails; compare experts side-by-side before merging.
- Data export: Download indices or rows for any slice/cluster/high-loss tail to CSV/Parquet/JSON for notebooks, SQL, or BI tools.
- Planner cards: Suggested Fork/Merge actions appear as editable “plan cards” (apply / snooze / ignore) with tunable LR/WD, budgets, and recipes.
Modes
Manual mode (analyst-in-the-loop)
Keep full control with Automode OFF. You can pause runs, inspect evidence, export subsets, then decide when to fork or merge.
What you can do
- Pause/Resume at any time to take a clean snapshot.
- Inspect before acting: loss tails, clusters (auto-k), slices, and routing/gate loads.
- Export subsets for offline analysis.
- Approve or edit plan cards prior to execution.
- Compare experts on target slices.
- Merge on your terms via SWA / Distill / Fisher-Soup / Adapter-Fuse.
Typical manual loop
- Pause when drift or a weak slice appears.
- Inspect loss tails, clusters, and slice deltas.
- Export a subset (e.g.,
region=APAC & volatility>p90) for a quick notebook check. - Fork a short-budget specialist.
- Evaluate on target slices; iterate if needed.
- Merge improvements and resume training.
Automode (automated planner)
With Automode ON, plans execute immediately with built-in safeguards. You can intervene at any time.
Automode monitors the run and proposes/executes plans such as:
- Stabilize on instability: Detect NaNs/Inf, loss/grad spikes, sharpness/GNS alerts; try LR↓, WD↑, gradient clipping, bf16; optional SAM/EMA.
- Mine hard samples: Stream per-sample loss (optionally grad norm, margin, small embeddings) with robust quantiles.
- Cluster residuals (auto-k): Tag high-loss clusters; fall back to top-q loss tails when appropriate.
- Specialize with budgets: Launch short ASHA/Successive-Halving rungs for candidate specialists.
- Route with a gate: Train a small router (
switch_softmaxby default; temperature + load-balance aux). - Explore on plateaus: Trend tests (Theil–Sen + Mann–Kendall; Page–Hinkley aware) trigger small HPO sweeps with early stop.
- Target weak slices: If you report per-slice validation metrics, persistent underperformers trigger slice-focused forks.
- Merge on cadence: Periodically unify via SWA / Distill / Fisher-Soup / Adapter-Fuse; parent remains catch-all.
- Pacing & limits: Adaptive cooldowns; cap parallel children; show lightweight diagnostics in the UI.
Planner card (summary fields)
action: fork | merge
reason: instability_spike | residual_cluster | high_loss_tail | loss_plateau | slice_underperformance
selection: {kind: all | quantile | kmeans | indices, ...}
training_recipe: small set of variants + early stopping
gate_recipe: tiny router (if specializing)
merge_recipe: swa | distill | fisher_soup | adapter_fuse
budget_steps: short (ASHA first rung)
cooldown_steps: adaptive
diagnostics: lightweight numbers for the UI
Selection cheatsheet
all— global stabilize/explorequantile— top-q loss tail (e.g., 0.85–1.0)kmeans— cluster IDs from auto-k residual clusteringindices— exact sample IDs (if provided)
Method (at a glance)
Train a generalist, mine and cluster hard samples into regimes, train specialists, learn a gating network, and export a unified MoE for inference.
- Train a compact generalist on all data.
- Hard-sample mining flags high-loss examples online.
- Clustering groups hard samples into candidate regimes.
- Train per-regime specialists.
- Learn a gating network to mix experts.
- Benchmark fairly against a monolithic baseline with matched compute.
Installation
pip install onthefly-ai
If your published import name differs from the PyPI package, adjust the imports below.
Quickstart (runnable)
import torch, torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
from onthefly import quickstart
# toy dataset
X = torch.randn(4096, 28*28)
y = (X[:, :50].sum(dim=1) > 0).long()
ds = TensorDataset(X, y)
train = DataLoader(ds, batch_size=128, shuffle=True)
val = DataLoader(ds, batch_size=256)
test = DataLoader(ds, batch_size=256)
# tiny model
model = nn.Sequential(nn.Linear(28*28, 64), nn.ReLU(), nn.Linear(64, 2))
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
loss = nn.CrossEntropyLoss()
quickstart(
project="mnist-demo",
run_name="baseline",
model=model,
optimizer=opt,
loss_fn=loss,
train_loader=train,
val_loader=val,
test_loader=test,
max_epochs=1,
do_test_after=True,
)
VS Code dashboard
- Open VS Code → Command Palette (
Ctrl/Cmd + Shift + P). - Run “On the Fly: Show Dashboard.”
- Select your Python interpreter and training script.
- Press ▶ Run to start/monitor training, inspect clusters, and compare experts.
Prefer headless? Use the CLI:
onthefly run --script path/to/train.py --python /path/to/python
# or drive with a config file:
onthefly quickstart --config configs/mnist.yaml
Requirements
- Python ≥ 3.9
- PyTorch ≥ 2.2 (CUDA 12.x optional)
- OS: Linux, macOS, or Windows
- VS Code optional (for the dashboard)
Reproducible examples
Example training scripts are provided in examples/ to illustrate the workflow without hyper-parameter tuning.
Troubleshooting
- No GPU visible: set
CUDA_VISIBLE_DEVICESor install matching CUDA wheels. - VS Code command missing: ensure the extension is enabled; restart VS Code.
License
Citation
If you use this project in research, please cite:
@software{onthefly2025,
title = {On-the-Fly: Hard-Sample–Guided Mixture-of-Experts},
author = {Luke Skertich},
year = {2025},
url = {https://github.com/KSkert/onthefly}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file onthefly-ai-0.0.3.tar.gz.
File metadata
- Download URL: onthefly-ai-0.0.3.tar.gz
- Upload date:
- Size: 61.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca8c869e44feabc57822bea9a8cf4709719be6a6fa693d262ea66945335b041d
|
|
| MD5 |
2e836d71c257072cfa389e92e248597e
|
|
| BLAKE2b-256 |
be4c1227e412abb44f2330d02db2113f34641f7eaaea06404f2b283452262433
|
File details
Details for the file onthefly_ai-0.0.3-py3-none-any.whl.
File metadata
- Download URL: onthefly_ai-0.0.3-py3-none-any.whl
- Upload date:
- Size: 69.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31d76f64e602e222deb5dc9d1501a9cc9eacf88e4dc1a3a2fcd75e3f6aec4f0f
|
|
| MD5 |
a1577bbca7abd6600342903a39b526a2
|
|
| BLAKE2b-256 |
93794bfcfdc880df09609678763cb207b1ce2472a9db3e68fabaf765c22015ee
|