Skip to content

Repository files navigation

hotcb

hotcb_logo

Live Training Control Plane for PyTorch

hotcb lets you modify training behavior while your run is active β€” no restart, no lost progress. Every change is recorded, exportable, and replayable.

Version 2.0 expands the original live-callback system into a full control plane: you can now swap callbacks, tune optimizer parameters, and adjust loss weights β€” all from another terminal while the model trains.

Now tune hyperparameters in 2 not 2000 runs !!

final_demo_ai_autopilot.mp4

In the video you can see a model distillation run being balanced for classification feature tokens and spatial maps in terms of both direction(cos) and structure(mse+grad). The mutations applied here are taken by ai autonomously via hot b AI-Autopilot mode show thier impact (features vs spatial map) quantitatively(impact analysis) and qualitatively(curve steps).


What you get

ModuleWhat you can change live
cbLoad/unload/enable/disable/reconfigure callbacks
optLearning rate, weight decay, gradient clipping, per-group
lossLoss weights, term toggles, ramp configs
tuneOnline constrained hyperparameter adaptation (optional, hotcb[tune])

Plus:

  • Dashboard (hotcb serve): live metric charts, command panel, recipe editor, autopilot controls
  • Autopilot: rule-based and AI-driven training optimization β€” plateau/divergence/overfitting detection with automatic or LLM-guided intervention
  • AI Autopilot (hotcb[ai]): LLM reads compressed metric trends, analyzes alerts, and proposes/applies hotcb commands β€” with budget caps, safety guards, and multi-run memory
  • Programmatic launch API (hotcb.launch): start training + dashboard + autopilot in one call from notebooks/scripts
  • Applied ledger (hotcb.applied.jsonl): step-indexed, authoritative record of what actually happened
  • Recipe export + replay: export a run's changes as a portable plan, replay in future runs deterministically
  • Freeze modes: production lock, deterministic replay, replay-with-adjustments

Live Mutation Scheduling Recipe editor: recipe_and_mutations_with_scheduling

Mutation tracking: mutations

Mutation impact analysis: mutation_exanpded_impact_log

Rule based Autopilot (AI mode in video above) automated-ai-free-training-intervention

Mutation Recipe impact comparison: comparison_with_mutation_changes

Dynamic metric space manifold update: dynamic_manifold_vis


Installation

pip install hotcb

With YAML config support:

pip install "hotcb[yaml]"

With dashboard:

pip install "hotcb[dashboard]"

With AI autopilot (LLM or Rule driven live optimization - Optionally):

pip install "hotcb[dashboard,ai]"

Full extras (YAML + Lightning + HF + dashboard + AI + tune):

pip install "hotcb[all]"

With online tuning (Bayesian HPO):

pip install "hotcb[tune]"

Quickstart

1. Initialize a run directory

hotcb --dir runs/exp1 init

2. Integrate into training

PyTorch Lightning

fromhotcbimportHotKernelfromhotcb.adapters.lightningimportHotCBLightningkernel=HotKernel(run_dir="runs/exp1", debounce_steps=10)
trainer=pl.Trainer(callbacks=[HotCBLightning(kernel)])
trainer.fit(model, datamodule=dm)
trainer.fit(model, datamodule=dm)

HuggingFace Trainer

fromhotcbimportHotKernelfromhotcb.adapters.hfimportHotCBHFCallbackkernel=HotKernel(run_dir="runs/exp1", debounce_steps=10)
trainer=Trainer(..., callbacks=[HotCBHFCallback(kernel)])
trainer.train()

Bare PyTorch

fromhotcbimportHotKernelkernel=HotKernel(run_dir="runs/exp1", debounce_steps=10)
forstep, batchinenumerate(dl):
# ... forward, backward, optimizer step ...kernel.apply(
env={
"framework": "torch",
"phase": "train",
"step": step,
"optimizer": optimizer,
"mutable_state": model.mutable_state,
"log": print,
},
events=["train_step_end"],
)

3. Control training live (from another terminal)

# Load a diagnostic callback
hotcb --dir runs/exp1 cb load feat_viz \
--file /tmp/feat_viz.py \
--symbol FeatureVizCallback \
--enabled --init every=50
# Change learning rate
hotcb --dir runs/exp1 opt set_params lr=1e-4 weight_decay=0.02
# Change loss weights
hotcb --dir runs/exp1 loss set_params distill_w=0.2 depth_w=1.5
# Toggle a loss term off
hotcb --dir runs/exp1 loss set_params terms.aux_depth=false

Syntactic sugar

# enable/disable default to the cb module
hotcb --dir runs/exp1 enable timing
hotcb --dir runs/exp1 disable timing
# set auto-routes based on key patterns
hotcb --dir runs/exp1 set lr=5e-5 # β†’ opt
hotcb --dir runs/exp1 set distill_w=0.25 # β†’ loss

4. Launch the dashboard

# Dashboard only (attach to existing run)
hotcb serve --dir runs/exp1
# Dashboard + synthetic training demo
hotcb demo
hotcb demo --golden # multi-task demo with rich metrics# Dashboard + autopilot (rule-based or AI-driven)
hotcb demo --autopilot suggest # rule-based, proposals shown in UI
hotcb demo --autopilot ai_suggest # LLM-driven, proposals shown in UI
hotcb demo --autopilot ai_auto # LLM-driven, auto-applies with safety guards

Open http://localhost:8421 to see live charts, send commands, and monitor autopilot decisions.

5. Programmatic launch (notebooks / scripts)

fromhotcb.launchimportlaunchhandle=launch(
train_fn="my_module:train", # or a callableautopilot="ai_suggest",
key_metric="val_loss",
max_steps=1000,
serve=True, # start dashboard
)
handle.wait() # block until donehandle.metrics() # read latest metricshandle.set_param(lr=0.0005) # send live commandshandle.stop() # stop early

6. One-command launch (CLI)

hotcb launch --config multitask --autopilot ai_suggest --key-metric val_loss --max-steps 1000
hotcb launch --config multitask --autopilot ai_suggest --max-time 300 # 5-minute run
hotcb launch --train-fn my_module:train --autopilot ai_auto --ai-budget 2.0

7. Enable online tuning (optional)

# Register actuators in your training script (see docs/modules/hottune.md)# Then enable from another terminal:
hotcb --dir runs/exp1 tune enable --mode active
# Or observe-only (no mutations, just proposals):
hotcb --dir runs/exp1 tune enable --mode observe
# Check tune status:
hotcb --dir runs/exp1 tune status

Run artifacts

FilePurpose
hotcb.commands.jsonlWhat you asked for (incoming commands)
hotcb.applied.jsonlWhat actually happened (step-indexed, authoritative)
hotcb.recipe.jsonlPortable replay plan exported from the ledger
hotcb.sources/Captured callback source files for deterministic replay
hotcb.freeze.jsonCurrent freeze mode state
hotcb.tune.mutations.jsonlTune mutation log (if tune enabled)
hotcb.tune.segments.jsonlTune evaluation segments (if tune enabled)
hotcb.tune.summary.jsonTune run summary (if tune enabled)
hotcb.metrics.jsonlTraining metrics stream (step, metrics dict)
hotcb.features.jsonlActivation capture data (optional)
hotcb.run.jsonRun metadata (config, seed, timestamps)
hotcb.ai.state.jsonAI autopilot state (key metric, run history, learnings)

Freeze modes

ModeBehavior
offNormal β€” all live commands accepted
prodIgnore all external commands (production lock)
replayIgnore external commands, replay recipe deterministically
replay_adjustedReplay recipe with YAML overlay patches
# Lock a production run
hotcb --dir runs/exp1 freeze --mode prod
# Replay a previous run exactly
hotcb --dir runs/exp1 recipe export --out runs/exp1/hotcb.recipe.jsonl
hotcb --dir runs/exp2 freeze --mode replay --recipe runs/exp1/hotcb.recipe.jsonl
# Replay with adjustments
hotcb --dir runs/exp2 freeze --mode replay_adjusted \
--recipe runs/exp1/hotcb.recipe.jsonl \
--adjust runs/exp2/hotcb.adjust.yaml
# Unlock
hotcb --dir runs/exp1 freeze --mode off

Exposing optimizer and loss state

hotcb never monkeypatches the trainer. It mutates only what you pass via env.

Optimizer

Pass env["optimizer"] (or env["resolve_optimizer"] as a callable). The Lightning and HF adapters handle this automatically.

Loss state

Keep a mutable dict on your model:

self.mutable_state= {
"weights": {"distill": 0.2, "depth": 1.5},
"terms": {"aux_depth": True, "aux_heatmap": False},
"ramps": {"depth": {"type": "linear", "warmup_frac": 0.2, "end": 2.0}},
}

Set env["mutable_state"] = self.mutable_state β€” the adapters do this automatically if the attribute exists on your LightningModule or HF model.


Deterministic callback replay

When you load a callback from a Python file, hotcb captures its source:

hotcb --dir runs/exp1 cb load feat_viz \
--file /tmp/feat_viz.py --symbol FeatureVizCallback

hotcb computes SHA-256, copies the file to hotcb.sources/, and records the version in the ledger. Replay mode uses the captured version β€” even if the original file has since changed.


Status and inspection

# Show current freeze mode and recent applied entries
hotcb --dir runs/exp1 status
# Validate a recipe file
hotcb --dir runs/exp1 recipe validate --recipe runs/exp1/hotcb.recipe.jsonl
# Inspect the ledger directly
tail -n 20 runs/exp1/hotcb.applied.jsonl

Included diagnostic callbacks

hotcb ships with ready-to-use callbacks:

CallbackWhat it does
HeartbeatCallbackPeriodic "I'm alive" log signal
TimingCallbackStep timing and throughput
SystemStatsCallbackCPU / RAM / GPU utilization
TensorStatsCallbackTensor mean / std / min / max
GradStatsCallbackGradient norm and stability
AnomalyGuardCallbackNaN/Inf detection with auto-disable
JSONLLoggerCallbackStructured append-only JSONL metrics log
hotcb --dir runs/exp1 cb load heartbeat \
--path hotcb.modules.cb.callbacks.heartbeat \
--symbol HeartbeatCallback \
--enabled --init every=100

Writing a hot callback

Minimal contract β€” no base class required:

classMyCallback:
def__init__(self, id: str, every: int=50):
self.id=idself.every=everydefset_params(self, **kwargs):
if"every"inkwargs:
self.every=int(kwargs["every"])
defhandle(self, event: str, env: dict):
step=env.get("step", 0)
ifstep%self.every==0:
env.get("log", print)(f"[{self.id}] step={step}")

Autopilot

hotcb includes a multi-level autopilot system:

ModeBehavior
offNo autopilot β€” manual control only
suggestRule-based: detects plateau/divergence/overfitting, proposes actions in dashboard
autoRule-based: detects and auto-applies corrective actions
ai_suggestLLM-driven: reads metric trends + alerts, proposes actions for human review
ai_autoLLM-driven: proposes and auto-applies with safety guards

AI autopilot features:

  • Compressed trend context: sends slope/volatility/direction summaries (not raw values) to the LLM for token efficiency
  • Key metric system: primary optimization target, changeable by AI or human mid-run
  • Multi-run memory: carries learnings across 2-3 runs via hotcb.ai.state.json
  • Budget cap: configurable USD limit; falls back to rule-based when exhausted
  • Safety guards: action bounds, cooldown between interventions, noop bias, auto-disable on divergence

Set HOTCB_AI_KEY env var for the LLM API key (any OpenAI-compatible provider).

Safety

  • No training loop mutation β€” hotcb never touches the trainer internals
  • Safe-point updates only β€” changes applied at batch/step boundaries
  • Fail-safe β€” crashing callbacks and modules auto-disable, training continues
  • Full audit trail β€” every mutation written to the applied ledger
  • AI actions bounded β€” hard min/max on all parameter changes, minimum 10-step cooldown

Docs


License

MIT License (see LICENSE file).

About

πŸ”¨ Forge your run - Live tune hyperparameters in 2 not 2000 runs !!

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages