PongRL Pro
An open-source Deep Reinforcement Learning research workspace that turns raw Atari 2600 pixel streams into an autonomous, playable Pong agent with live telemetry and empirical training analytics.

Introduction
PongRL Pro is an open-source Deep Reinforcement Learning (DRL) workspace built around a simple idea: learn directly from pixels, then inspect and play against the policy in real time. Instead of relying on hardcoded game coordinates or internal emulator memory, the agent observes raw ALE/Pong-v5 video frames, extracts motion dynamics, and learns competitive paddle control through trial and error.
The platform brings the PyTorch reinforcement learning pipeline and an interactive research interface together—combining a 60 FPS in-browser match court, Gymnasium simulation stepping, 6,001-episode convergence analytics, and architectural documentation in one place.
Why I built it
Most reinforcement learning projects stop at a training script in a Jupyter notebook and a static reward plot. I wanted to explore what comes after that: modular multi-algorithm architectures, memory-efficient experience replay, reproducible YAML configurations, real-time human-vs-AI gameplay, and a clean web interface that evaluators can actually use and inspect.
Building PongRL Pro bridged low-level RL systems engineering with a full-stack web experience. A useful research project needs more than a saved checkpoint—it needs transparent metrics, honest benchmarks, interactive evaluation, and clear documentation of every architectural decision.
Core features
- Zero-heuristic visual perception: Learns paddle control strictly from raw 210×160 RGB Atari frames via a 5-stage computer vision preprocessing pipeline.
- Three native PyTorch algorithms: Modular implementations of REINFORCE (Karpathy Policy Gradient MLP), Deep Q-Networks (DQN), and Proximal Policy Optimization (PPO) using the Nature CNN.
- Temporal frame differencing (
Δs_t): ComputesΔs_t = s_t - s_{t-1}on binarized 80×80 frames to encode ball and paddle velocity vectors without multi-frame stacking overhead for the policy MLP. - 93.75% replay memory compression: Uses a quantized
uint8circular replay buffer instead offloat32, cutting 100k-transition host RAM usage from 22.5 GB down to 1.41 GB. - 60 FPS Human vs. AI arena: Play directly against the agent in an HTML5 Canvas court using mouse or keyboard (
W/Sor Arrow keys) with a liveP(UP)action probability gauge and latency tracker. - Live Gymnasium stepping & GIF archive: Step through headless
ALE/Pong-v5episodes via FastAPI or inspect recorded policy evolution from Episode 1 through Episode 6,000. - Empirical training analytics: Interactive Recharts visualizations of the full 6,001-episode training run (converging from
-20.0baseline to-1.47peak moving reward), including 50-ep and 100-ep moving averages and quartile distributions. - Model & checkpoint comparison: Side-by-side benchmarks comparing REINFORCE, DQN, and PPO across parameter count, asymptotic reward, sample efficiency, and inference latency, plus a checkpoint inventory.
- Architecture, YAML hyperparameters & docs: Interactive layer-by-layer breakdowns, searchable YAML hyperparameter explorer with copy/download, a 3-column
/docsportal, and a Viva Voce defense Q&A dossier.
How it works
- Emulate the environment: Farama Gymnasium (
ALE/Pong-v5viaale-py) runs the cycle-accurate Stella Atari 2600 emulator at 60 FPS, emitting 210×160 RGB frames and sparse rewards (+1on score,-1on concede). - Preprocess & extract motion: The 5-stage wrapper crops the arena, downsamples and binarizes to 80×80, and computes temporal frame differences
Δs_t(or stacks 4 84×84 grayscale frames for the Nature CNN). - Infer action probabilities: The PyTorch policy network (Karpathy MLP
6,400 → 200 → 1or Nature CNN) outputs action probabilitiesP(UP)or discrete Q-values across{UP, DOWN, IDLE}. - Optimize the policy: Transitions are buffered in
uint8memory, returns are discounted (γ = 0.99) and standardized, and weights are updated via Policy Gradient (REINFORCE), Bellman MSE (DQN), or clipped surrogate loss (PPO). - Serve & visualize: FastAPI exposes REST endpoints (
/api/summary,/api/metrics/training,/api/game/action,/api/game/session/step) that connect to the Next.js frontend viaNEXT_PUBLIC_API_URL, with built-in empirical fallback data when deployed standalone on Vercel.
Use cases
Academic capstone & viva demonstrations
Present live Human vs. AI gameplay, empirical convergence curves, mathematical formulations, and defense Q&A from a single web dashboard.
Studying reinforcement learning trade-offs
Compare on-policy Monte Carlo policy gradients (REINFORCE), off-policy value approximation (DQN), and trust-region actor-critic methods (PPO) on the same benchmark environment.
Human-in-the-loop agent testing
Test how well a trained Atari agent generalizes and reacts to human play styles in real time at 60 FPS.
Reference for full-stack ML deployment
Demonstrate how heavy PyTorch + Gymnasium simulation backends can be decoupled from a lightweight, serverless Next.js frontend on Vercel.
Tech stack
- Next.js 16, React 19 & TypeScript: App Router frontend application, static prerendering, and interactive research pages.
- Tailwind CSS v4 & Lucide Icons: Minimal, light-mode research laboratory UI with a floating pill navigation bar.
- Recharts & HTML5 Canvas: Declarative SVG training curves, benchmark charts, and a 60 FPS retro Atari court.
- Python 3.10+, FastAPI, Uvicorn & Pydantic: RESTful backend API, CORS configuration, YAML config management, and live inference endpoints.
- PyTorch 2.x & NumPy: Neural network architectures (Nature CNN and Karpathy Policy MLP), autograd training loops, and serialized
.pth/.pcheckpoints. - Gymnasium (
ALE/Pong-v5) &ale-py: Atari 2600 emulation, frame wrappers, and headless evaluation sessions. - PyYAML, Pandas & Pillow: Hyperparameter serialization, log parsing, and frame processing.
- Vercel & Render: Serverless frontend deployment on Vercel (
frontend/) with optional Python backend hosting viaProcfile/render.yaml. - pytest & Next.js Build: Automated backend unit/integration test suite (
tests/) and production TypeScript/static build verification.
Engineering challenges
Inferring velocity from static frames
A single Pong frame cannot show which direction the ball is moving. Using temporal frame differencing (Δs_t = s_t - s_{t-1}) gives the policy network explicit velocity vectors while keeping input size at a flat 6,400-element vector.
Preventing host out-of-memory crashes
Storing 100,000 stacked 4×84×84 observations in float32 requires ~22.5 GB of RAM, crashing standard 16 GB machines. Switching the replay buffer to uint8 storage with lazy normalization on batch sampling reduced RAM usage by 93.75% to 1.41 GB.
Serverless deployment constraints on Vercel
Vercel serverless functions cannot sustain persistent 24/7 Gymnasium simulations or large PyTorch binary bundles. Decoupling the architecture into a standalone Next.js frontend (with pre-bundled empirical data, evolution GIFs, and client-side canvas play) plus an optional FastAPI inference backend ensures Vercel works cleanly out of the box.
Maintaining empirical honesty
Rather than fabricating missing metrics or claiming inflated scores, the dashboard strictly surfaces real logged data from the 6,001-episode run (where -1.47 peak moving reward represents near-parity 19–21 / 20–21 games against the built-in Atari CPU).
Performance and evaluation
Empirical convergence
Over 6,001 logged episodes, the REINFORCE agent progressed from a -20.0 initial baseline (-11.20 inflection around Episode 3,000) to a peak running reward of -1.47 (-1.59 final), winning ~48.8% of individual points in sustained 18+ return rallies against the Atari heuristic CPU.
Inference & memory benchmarks
The Karpathy MLP achieves 1.42 ms inference latency with 48 MB memory usage (1,280,201 parameters), compared against 3.85 ms / 1,410 MB for DQN (1,687,206 parameters) and 4.12 ms / 180 MB for PPO (1,690,285 parameters).
Tradeoffs
Policy gradient methods like REINFORCE offer fast inference and tiny memory footprints but suffer from higher variance in Monte Carlo returns; DQN and PPO improve sample efficiency and stability at the cost of larger CNN parameter counts and replay/rollout memory.
Improvements I want to make
- Live browser-side ONNX/WebGPU inference: Export the PyTorch
.pthmodels to ONNX Runtime Web so users on Vercel can run genuine neural network forward passes directly in the browser without needing a separate Python server. - Full multi-thousand-episode DQN and PPO runs: Train the Nature CNN DQN and PPO agents to full 6,000-episode parity to overlay live multi-algorithm reward curves directly in the Analytics tab.
- Interactive hyperparameter training trigger: Stream real-time training loss and reward updates via WebSockets or Server-Sent Events when connected to a local GPU backend.
- Difficulty & opponent customization: Add selectable ball speeds, paddle sizes, and AI checkpoint switching (e.g., Ep 1,000 vs. Ep 6,000) directly inside the Play Arena.
What I learned
Building an end-to-end Deep Reinforcement Learning system is a chain of tightly coupled engineering decisions: how raw pixels are cropped and differenced, how transitions are quantized in RAM, how rewards are discounted and normalized, and how inference is served without latency bottlenecks. Tuning the neural network alone leaves half the problem unsolved—PongRL Pro brought together computer vision preprocessing, memory-conscious systems engineering, PyTorch optimization, and full-stack web deployment into one cohesive project.