Repository navigation
Architecture WebSocket Protocol
The WebSocket Protocol defines the communication stream used during Live Inference. It streams a real greedy generation from the backend to the frontend token-by-token.
REST APIs are synchronous and block until the entire generation is finished. For a visual debugger, we need to see the generation happen in real-time. WebSockets allow the backend to push data to the frontend the exact millisecond a token is computed.
The endpoint is WS /ws/generate.
TokenPrint utilizes a highly optimized JSON framing protocol over this socket.
-
Meta Frame (Sent Once): Contains model metadata and the massive
op_catalog(a list of all 240+ operations in the forward pass). -
Token Frames (Sent N times): Contains the newly generated token, the
topkarray, the KV cachephase, and a smalllayer_statsarray. - Done Frame: Signals the end of generation.
Optimization: By sending the op_catalog only once, the subsequent Token frames remain tiny (a few kilobytes). The frontend references the operations by their index, avoiding massive JSON payloads and maintaining 60fps.
sequenceDiagram
participant FE as Frontend
participant BE as Backend
FE->>BE: Connect WS {prompt: "Hello", max_tokens: 5, trace: true}
Note over BE: Startup
BE-->>FE: {type: "meta", op_catalog: [...240 ops]}
Note over BE: Loop
BE-->>FE: {type: "token", step: 0, phase: "prefill", topk: [...]}
BE-->>FE: {type: "token", step: 1, phase: "decode", topk: [...]}
BE-->>FE: {type: "token", step: 2, phase: "decode", topk: [...]}
Note over BE: Finish
BE-->>FE: {type: "done"}
FE->>BE: Close Connection
| Previous | Home | Next |
|---|---|---|
| Backend | Home | Data Pipeline |
TokenPrint Wiki | Home | Getting Started | User Guide | Concepts | Architecture | API | GitHub
TokenPrint is an interactive 3D visualization platform for exploring transformer architectures, tensors, and real-time LLM inference.
- User Guide
- Architecture Explorer
- Live Inference
- Tensor Inspector
- Camera Controls
- HUD
- Timeline
- Scene Navigation
- Transformer Concepts
- Tokenization
- Embeddings
- Positional Encoding
- RoPE
- Multi-Head Attention
- KV Cache
- LayerNorm
- Feed Forward Network
- Residual Connections
- Logits
- Softmax
- Sampling
- Autoregressive Generation
- Visualization System
- Scene Graph
- Geometry
- Materials
- Animation System
- Color Mapping
- Camera System
- Interaction Model
- Architecture
- Overall Architecture
- Frontend
- Backend
- WebSocket Protocol
- Data Pipeline
- Renderer
- Event System