Repository navigation
API Reference Tensor Format
PyTorch operates on multi-dimensional tensors (e.g., shape [24, 14, 5, 5]). JSON only understands nested arrays. TokenPrint requires a specific serialization strategy to move massive mathematical structures over the network without melting the browser.
The most complex tensor sent over the wire is the Attention probabilities.
A typical shape is [num_layers, num_heads, sequence_length, sequence_length].
For a 24-layer model with 14 heads and a 10-token prompt, this is
In backend/app/schemas.py, TokenPrint applies aggressive formatting to this specific tensor before JSON serialization:
-
Truncation: Every float is rounded to 3 decimal places (
0.145623$\rightarrow$ 0.146). -
Sparsity Enforcement: Because Softmax creates many tiny values, any value below
0.01(1%) is explicitly set to0.0. - Array Flattening: Instead of a complex dictionary, it is sent as a raw 4D nested list.
This reduces a 5MB payload to under 200KB, allowing near-instant parsing by the frontend WalkthroughScene.
Sending the raw hidden states ([25_layers, seq_length, 896_hidden_size]) would be massive.
Instead, TokenPrint applies Principal Component Analysis (PCA) directly in the PyTorch backend (reduce.py).
- It fits PCA on the final layer's hidden states to find the 3 most significant dimensions of variance.
- It projects all 896-dimensional vectors from every layer into those 3 dimensions.
- The API only transmits arrays of
[x, y, z]floats.
| Previous | Home | Next |
|---|---|---|
| Data Models | Home | Research |
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