Skip to content

Control

Finding the upside

Watch a tiny neural torque controller swing a pendulum upright, then disturb its balance. Trained with synthetic expert-policy distillation in tinygrad.

4,481 parameters · entirely local

Run the experiment

Choose a checkpoint and compute backend. Inference stays on your device.

Ready when you are · no inference until Start

Checked weights · deterministic physics · 20 simulated seconds

01 / The world1 kg · 1 m · torque ±2 N m
Neural torque drives the pendulum. The dotted circle marks the upright target.UPRIGHT TARGETTRAINED / WEBGPUθ 160.4°
A push adds 1.5 rad/s.

02 / Read the controller

Motor torque0.00 N m
−2 / negative+2 / positive
Simulated time
0.00 / 20s
Episode return
0.0
Time upright
0.00s
Angular velocity
0.15 rad/s

03 / A path to balance

angle → · center = still and upright

Try the untrained checkpoint with the same start. Return is better closer to zero; upright means within 0.25 rad of the top and below 1 rad/s.

Learned, not scripted.

tinygrad trained this 3 → 64 → 64 → 1 network on synthetic energy-shaping and balancing expert labels. The expert is used only in training. Every live torque comes from the selected network weights.

Training & source on GitHub ↗

Held-out, not a highlight reel.

128 unseen starting states, 400 steps each. Fixed final checkpoint, no best-episode selection.

Mean return
-2458 → -146
Upright time
0.4% → 92.2%

A teaching world.

Pendulum-v1 dynamics with a fixed 0.05s step; velocity is normalized by 8. Inspired by LeRobot’s explicit state/action normalization. This is distillation, not PPO, and not a validated robot controller. Software WebGPU proves shader correctness, not physical-GPU performance.

JavaScript CPU is an explicit choice using the same checked weights. Simulation may run slower than wall time.