Observed since 21 Oct, 10:14 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
AI Cognitive Mapping Tool — Real-time transformer layer activation visualization for SGLang
Real-time transformer layer activation visualization for SGLang inference servers.
Watch your AI model think. AI Cog Map captures per-layer activation patterns during inference and renders them as a live heatmap — showing which layers, attention heads, and MLP blocks are doing meaningful work on each forward pass.
Different types of work create different visual signatures. Code generation activates different layers than creative writing. Math reasoning lights up different patterns than summarization.
┌─────────────────────┐ shared memory ┌─────────────────────┐
│ │ + metadata JSON │ │
│ SGLang Server │ ─────────────────> │ AI Cog Map UI │
│ │ /dev/shm/aicogmap-* │ │
│ + forward hooks │ │ FastAPI + HTML │
│ (aicogmap.hook) │ │ localhost:7890 │
│ │ │ │
└─────────────────────┘ └─────────────────────┘
Hook Plugin (aicogmap.hook): SGLang forward hook factory. Attaches to every matched sub-module via SGLang's native --forward-hooks system. Computes the L2 norm of each module's output tensor and writes to a shared memory buffer. Also classifies each hook point by layer index, component type, and category, writing a metadata sidecar JSON. No SGLang source modification required.
Visualization Server (aicogmap.server): Standalone FastAPI server that reads the shared memory buffer and metadata, computes cognitive state, and serves a real-time heatmap UI. Polls at 500ms for smooth animation.
Shared Memory Bridge: Lock-free binary format (4-byte magic ACGM + header + float32 array) at /dev/shm/aicogmap-activations. Metadata sidecar at /dev/shm/aicogmap-metadata.json. Zero disk I/O, zero serialization overhead. The hook writes, the server reads.
pip install aicogmap
Or from source:
git clone https://github.com/openhelper/ai-cog-map.git
cd ai-cog-map
pip install -e .
python -m sglang.launch_server \
--model-path Qwen/Qwen3.5-27B \
--dtype bfloat16 \
--port 8000 \
--forward-hooks '[{
"name": "aicogmap",
"target_modules": ["model.layers.*"],
"hook_factory": "aicogmap.hook:create_activation_hook",
"config": {"shm_path": "/dev/shm/aicogmap-activations"}
}]'
aicogmap --port 7890
Navigate to http://localhost:7890 and send requests to your model. Watch the layers light up.
If SGLang runs in Docker, mount shared memory and the aicogmap package:
volumes:
- /dev/shm:/dev/shm
- ./aicogmap:/usr/local/lib/python3.12/dist-packages/aicogmap
See examples/docker-compose.example.yml for a complete setup.
| Option | Default | Description |
|---|---|---|
shm_path | /dev/shm/aicogmap-activations | Shared memory file path |
meta_path | /dev/shm/aicogmap-metadata.json | Metadata sidecar JSON path |
flush_interval | 0.1 | Seconds between shared memory flushes |
max_layers | 1024 | Maximum hook points to track |
| Flag | Default | Description |
|---|---|---|
--host | 0.0.0.0 | Bind address |
--port | 7890 | HTTP port |
--shm-path | /dev/shm/aicogmap-activations | Shared memory path |
--meta-path | /dev/shm/aicogmap-metadata.json | Metadata sidecar path |
The target_modules field uses fnmatch patterns. Common patterns:
| Pattern | Matches |
|---|---|
model.layers.* | All transformer layers and sub-modules (recommended) |
model.layers.*.self_attn | Attention modules only |
model.layers.*.mlp | Feed-forward modules only |
model.layers.0 | First layer only |
model.layers.3[0-9] | Layers 30-39 |
When using model.layers.*, the hook automatically classifies each sub-module:
| Component | Category | What it captures |
|---|---|---|
layer_output | layer | Full layer contribution to residual stream |
attention | attention | Attention block aggregated output |
attention_conv | attention | Mamba-style convolution (hybrid models) |
attention_qkv | attention | Query/Key/Value projections |
attention_gate | attention | Attention gating mechanism |
mlp | mlp | Feed-forward network block |
mlp_gate_up | mlp | MLP gated projection (SwiGLU) |
mlp_down | mlp | MLP output down-projection |
layernorm_input | norm | Pre-attention normalization |
layernorm_post | norm | Post-attention normalization |
The cognitive depth slider controls which categories are visible:
| Depth | Visible Categories | Typical cell count (64-layer model) |
|---|---|---|
| 1 | Layer outputs only | 64 |
| 2 | + Attention + MLP | ~192 |
| 3 | + Projections | ~448 |
| 4 | + Norms | ~576 |
| 5 | Everything | ~865 |
The auto-interpreter computes a cognitive state label from activation energy patterns:
| State | Pattern | Typical tasks |
|---|---|---|
| Attending | Attention energy > 65% of total | Reading context, following references |
| Reasoning | MLP dominant, deep layers active | Math, logic, code generation |
| Structuring | MLP dominant, early layers active | Parsing syntax, organizing output |
| Recalling | MLP gate projections highest | Factual recall, knowledge lookup |
| Searching | Low variance across layers | Uncertain, exploring possibilities |
| Generating | Deep layers > 50% of total energy | Token generation, text completion |
| Processing | No dominant pattern | Mixed or transitional processing |
GET /api/activations?depth=NReturns normalized activation norms, deltas, cognitive state, and hook metadata.
{
"status": "ok",
"num_layers": 192,
"total_hooks": 865,
"age_s": 0.05,
"depth": 2,
"norms": [0.23, 0.45, 0.12, "..."],
"raw_norms": [145.2, 278.9, 72.1, "..."],
"deltas": [0.01, 0.15, 0.03, "..."],
"cognitive_state": {
"label": "Reasoning",
"confidence": 0.82,
"attention_ratio": 0.31,
"energy": {
"attention": 1240.5,
"mlp": 2890.3,
"early": 980.2,
"mid": 1650.8,
"deep": 1499.8,
"total": 4130.8
}
},
"hooks": [
{"index": 0, "layer": 0, "type": "layer_output", "category": "layer"},
{"index": 1, "layer": 0, "type": "attention", "category": "attention"},
"..."
],
"history": ["..."]
}
GET /api/metadataReturns the full hook metadata sidecar.
GET /api/healthReturns connection status, hook count, and metadata availability.
tensor.norm() per hook per forward pass)--forward-hooks/dev/shm) is RAM-backedOn each forward pass through the model:
output.detach().float().norm().item() — a single scalar capturing the module's activation magnitudeThe L2 norm captures overall activation magnitude without being sensitive to individual outlier values, and is extremely cheap to compute on GPU tensors.
--forward-hooks support (PR #13217)/dev/shm for shared memory)Sonny Vleisides — CTO at ARRA Networks | VP Development at Alice Research
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.2.0 | 16 Mar 2026 | 3 |
This describes our collected data; it is not a security assessment.
Observed since 21 Oct, 10:14 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:05c1307c93248c72e0d74dd02dd317c5b55a6f8f9fe7f31132ff99ed162f37d5