How saurav-34/lepong works
Purpose and Entry Points
lepong is a pixel-only JEPA world-model project centered on Pong: it predicts latent future state from screenshots and actions, decodes game state, and drives a paddle controller. Primary entry points are offline training in model/jepa_pool.py, state-head fitting in scripts/train_statehead.py, and browser-serving inference in server/infer.py.
World Simulation and Dataset Production
The native Pong environment produces labeled screenshots, actions, and state trajectories for supervised state decoding and self-supervised predictive training. model/pong_world.py is the canonical generator; scripts/collect_pong.py and the broader collectors in scripts/collect_data.py extend collection workflows to other game sources. Stored datasets form the boundary between simulation/data capture and model training.
JEPA Representation and Dynamics Model
model/jepa_pool.py defines and trains the core 13M-parameter architecture: CNN pixel encoder, action encoder, causal AdaLN-conditioned transformer predictor, projection head, and SIGReg objective. The principal flow is 128×128 PNG frame → 192-dimensional embedding, combined with a 2-D action conditioning signal → predicted future embedding. Checkpoints from this stage initialize later state-head training.
State Decoding and Control
scripts/train_statehead.py freezes the learned encoder/predictor and trains the lightweight linear state head to recover ten physical state quantities, including ball and paddle positions/velocities. Controller evaluation and rollout behavior are implemented in scripts/eval_controller.py; robustness and representation quality boundaries are tested through scripts/eval_ood.py and scripts/eval_occlusion.py.
Serving and Real-Time Game Loops
server/infer.py loads a checkpoint and exposes real-time model inference for browser clients. Game-specific runtime loops bridge inference outputs to playable environments: server/pong_core.py with server/play_pong.py, plus parallel boxing and tennis implementations in server/boxing_core.py and server/tennis_core.py. This is the operational boundary between neural prediction/control and game mechanics.
Browser Client and Transport
Static browser experiences live under client/, with the Pong play surface at client/pong_play.html and training/demo client logic in client/train.js and client/train_worker.js. Clients capture canvas pixels, optionally apply visual occlusion, send frames to the inference service, and use returned paddle targets to update play. The runtime stack uses Python, PyTorch, FastAPI/Uvicorn, and WebSockets; model checkpoints are externally distributed through HuggingFace.
Multi-Game and Federation Extensions
The repository contains early generalization paths beyond Pong: game collection configurations in scripts/configs/, combat/arcade data capture scripts such as scripts/collect_kaz.py, and server-side federation support in server/federation_client.py and server/data_tap.py. These appear to support collecting or routing observations from multiple interactive game environments while retaining the same model-serving boundary.
Main entry points: infer.py Inference service · jepa_pool.py JEPA trainer · train_statehead.py State-head fitting · pong_play.html Pong browser client
Components 19
Data Production
- Pong world generator · Generates labeled frames, actions, and state trajectories.
model/pong_world.py - Pong collector
scripts/collect_pong.py - General collectors
scripts/collect_data.py - Stored datasets · Boundary between capture and model fitting.
JEPA Training
- JEPA trainer · Trains the 13M pixel world model.
model/jepa_pool.py - CNN pixel encoder · Maps 128×128 frames to 192-D embeddings.
model/jepa_pool.py - Action-conditioned predictor · Causal AdaLN transformer predicts future embeddings from actions.
model/jepa_pool.py - Projection and SIGReg
model/jepa_pool.py - Model checkpoints · Distributed externally through HuggingFace.
State and Control
- State-head fitting · Freezes JEPA features and fits a linear 10-value decoder.
scripts/train_statehead.py - Controller rollout
scripts/eval_controller.py - Representation robustness · Evaluates OOD and occlusion behavior.
scripts/eval_ood.py
Serving and Game Loops
- Inference service · Loads checkpoints and returns real-time predictions.
server/infer.py - Pong game runtime · Game mechanics and playable Pong loop.
server/play_pong.py - Pong mechanics
server/pong_core.py
Browser Clients
- Pong browser client · Captures canvas pixels and applies returned paddle targets.
client/pong_play.html - Training demo client
client/train.js
Multi-Game Extensions
- Multi-game collection configs
- Federation data routing · Routes observations from interactive game environments.
server/federation_client.py
Connections 21
- Pong world generator → Pong collector: produces episodes
- Pong collector → Stored datasets: stores frames and labels
- General collectors → Stored datasets: stores captured data
- Multi-game collection configs → General collectors: configures games
- Stored datasets → JEPA trainer: predictive training data
- JEPA trainer → CNN pixel encoder: trains
- CNN pixel encoder → Action-conditioned predictor: frame embeddings
- Action-conditioned predictor → Projection and SIGReg: future embeddings
- Projection and SIGReg → JEPA trainer: optimization signal
- JEPA trainer → Model checkpoints: writes
- Stored datasets → State-head fitting: state labels
- Model checkpoints → State-head fitting: initializes frozen JEPA
- State-head fitting → Controller rollout: state decoder
- State-head fitting → Representation robustness: decoded representations
- Model checkpoints → Inference service: loads model
- Pong browser client → Inference service: frames via WebSocket
- Inference service → Pong browser client: paddle targets
- Pong browser client → Pong game runtime: drives play
- Pong game runtime → Pong mechanics: uses mechanics
- Federation data routing → Inference service: routes observations
- Training demo client → Inference service: demo inference