Spaces:
Sleeping
Sleeping
Commit Β·
67f6350
1
Parent(s): bfea990
Rewrite README for clarity: add quick start, streamline structure
Browse filesReorganize sections with a clearer flow (quick start first, details
later), simplify explanations, tighten copy throughout, and update
the table of contents to match the new structure.
README.md
CHANGED
|
@@ -1,192 +1,166 @@
|
|
| 1 |
# smolvla-inspect
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |

|
| 6 |
-
*
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
- [
|
| 13 |
-
- [
|
| 14 |
-
- [
|
| 15 |
-
- [
|
| 16 |
-
- [
|
| 17 |
-
- [CLI
|
| 18 |
-
- [
|
| 19 |
-
- [Project layout](#project-layout)
|
| 20 |
- [Roadmap](#roadmap)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
## What this does
|
| 25 |
-
|
| 26 |
-
SmolVLA is a **vision-language-action** policy: it takes camera images and a language instruction, then outputs robot actions. This tool has three modes:
|
| 27 |
-
|
| 28 |
-
1. **Attention visualization** (default) -- extracts and visualizes attention heatmaps showing where the model looks
|
| 29 |
-
2. **Gradient-based attribution** (`--gradient`) -- computes saliency maps and GradCAM to show which pixels *causally influence* the predicted action
|
| 30 |
-
3. **Model internals report** (`--internals-only`) -- runs spectral analysis, attention entropy, and head redundancy checks across all model components
|
| 31 |
-
|
| 32 |
-
### Attention visualization
|
| 33 |
-
|
| 34 |
-
Extracts attention maps from two places:
|
| 35 |
-
|
| 36 |
-
1. **SigLIP vision encoder** (self-attention) -- which image patches the encoder considers important during feature extraction
|
| 37 |
-
2. **Action expert** (cross-attention) -- which image regions the action decoder actually reads when predicting actions
|
| 38 |
-
|
| 39 |
-
That lets you check whether the model attends to task-relevant regions (gripper, object, goal) or background (walls, table texture) -- useful for debugging overfitting or distribution shift.
|
| 40 |
-
|
| 41 |
-
**Input:** A pretrained or fine-tuned SmolVLA policy + a LeRobot dataset (e.g. episodes of pick-and-place).
|
| 42 |
-
**Output:** A multi-row grid PNG per episode, optional per-frame PNGs, an optional per-head attention grid, and a positional baseline diagnostic (`positional_baseline.png`) showing the position-dependent attention pattern that gets subtracted.
|
| 43 |
|
| 44 |
-
###
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
**SmoothGrad** (`--smooth-grad N`) averages saliency over N noisy copies of the input, producing cleaner maps. Set `--smooth-grad-sigma` to control the noise level (default: 0.15).
|
| 53 |
-
|
| 54 |
-
Since gradient computation requires `.backward()` through the full model (~176 transformer layer passes), it is slower than attention-only mode. MPS backward support is limited for some ops, so you can run attention on MPS and gradients on CPU with `--gradient-device cpu` (see [Split device execution](#split-device-execution)).
|
| 55 |
-
|
| 56 |
-
**Output:** Up to 2 additional rows in the grid PNG -- saliency overlay (inferno colormap) and GradCAM overlay (magma colormap).
|
| 57 |
-
|
| 58 |
-
### Extended attribution
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
| Connector GradCAM | `--gradcam-connector` | Extra row in main grid | GradCAM on the VLM connector output (post-pixel-shuffle, 8x8 token resolution) |
|
| 66 |
-
| VLM layer GradCAM | `--gradcam-vlm-layers [4,8,12,16]` | `vlm_layers_ep*.png` | GradCAM at specific VLM intermediate layers, showing how visual features are transformed through the language model |
|
| 67 |
-
| Vision vs. state | `--vision-vs-state` | `vision_vs_state_ep*.txt` | Compares gradient norms for vision vs. proprioceptive state inputs -- answers "does the model rely more on what it sees or what it feels?" |
|
| 68 |
-
| Per-action-dim GradCAM | `--per-action-dim` | `per_action_dim_ep*.png` | Separate GradCAM per action dimension (shoulder_pan, gripper, etc.) -- shows which image regions drive each joint. Uses `retain_graph`, GPU recommended |
|
| 69 |
-
| Language-conditional diff | `--language-diff [alt_task]` | `language_diff_ep*.png` + extra row in main grid | Compares GradCAM between two task instructions to show how language changes the model's visual attention |
|
| 70 |
|
| 71 |
-
###
|
| 72 |
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
2. **Attention entropy** -- measures how focused or diffuse each attention head is across three attention operations: SigLIP self-attention, VLM+Expert joint self-attention, and Expert-to-VLM cross-attention.
|
| 77 |
-
3. **Head redundancy** -- measures pairwise cosine similarity between attention heads within each layer. High similarity means wasted capacity.
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
##
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
| 109 |
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
| 2 | SigLIP self-attention heatmap | jet (blue-to-red) | always |
|
| 117 |
-
| 3 | Action cross-attention heatmap | Greens | `--cross-attention` |
|
| 118 |
-
| 4 | Saliency / SmoothGrad overlay | inferno | `--gradient saliency` or `both` |
|
| 119 |
-
| 5 | Self-attention overlay on frame | jet | always |
|
| 120 |
-
| 6 | Co-attention overlay (self x cross) | cyan (black-cyan-white) | `--cross-attention` |
|
| 121 |
-
| 7 | GradCAM overlay (SigLIP last layer) | magma | `--gradient gradcam` or `both` |
|
| 122 |
-
| 8 | GradCAM overlay (Connector) | magma | `--gradcam-connector` |
|
| 123 |
-
| 9 | Language-conditional diff | RdBu_r (diverging red-blue) | `--language-diff` |
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
*Each subplot is one attention head. Look for specialization -- e.g. one head tracking the gripper, another tracking the object.*
|
| 135 |
|
| 136 |
-
-
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
##
|
| 139 |
|
| 140 |
-
|
| 141 |
|
| 142 |
```bash
|
| 143 |
brew install ffmpeg@6
|
| 144 |
```
|
| 145 |
|
| 146 |
-
Then:
|
| 147 |
|
| 148 |
```bash
|
| 149 |
-
|
| 150 |
-
|
| 151 |
pip install -r requirements.txt
|
| 152 |
```
|
| 153 |
|
| 154 |
-
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
| 160 |
-
sudo apt-get install -y nodejs
|
| 161 |
-
```
|
| 162 |
-
Or use [nvm](https://github.com/nvm-sh/nvm) if you manage multiple Node versions. `setup-gpu.sh` handles this automatically.
|
| 163 |
|
| 164 |
-
###
|
| 165 |
|
| 166 |
-
For an
|
| 167 |
|
| 168 |
```bash
|
| 169 |
-
# Clone and set up in one step:
|
| 170 |
chmod +x clone-and-setup.sh && ./clone-and-setup.sh
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
chmod +x setup-gpu.sh && ./setup-gpu.sh
|
| 174 |
```
|
| 175 |
|
| 176 |
-
`setup-gpu.sh` installs
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
|
| 179 |
|
| 180 |
## Run
|
| 181 |
|
| 182 |
-
Use `run.sh` so TorchCodec
|
| 183 |
|
| 184 |
```bash
|
| 185 |
source .venv/bin/activate
|
| 186 |
./run.sh
|
| 187 |
```
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
```bash
|
| 192 |
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/ffmpeg@6/lib:$DYLD_LIBRARY_PATH"
|
|
@@ -195,408 +169,354 @@ python inspect_attention.py
|
|
| 195 |
|
| 196 |
### Config files
|
| 197 |
|
| 198 |
-
Defaults
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
```bash
|
| 201 |
-
# Use GPU-optimized config (runs all features)
|
| 202 |
./run.sh --config configs/gpu.yaml
|
| 203 |
-
|
| 204 |
-
# Override a single value from the config
|
| 205 |
./run.sh --config configs/gpu.yaml --episode 3
|
| 206 |
```
|
| 207 |
|
| 208 |
-
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|--------|-------------|
|
| 212 |
-
| `configs/defaults.yaml` | Conservative defaults: attention + cross-attention, no gradients, CPU-friendly |
|
| 213 |
-
| `configs/gpu.yaml` | Enables everything: gradient both, SmoothGrad N=20, connector GradCAM, per-step cross-attention, VLM layer GradCAM, vision vs state, per-action-dim, language diff. Targets CUDA. |
|
| 214 |
-
|
| 215 |
-
### Examples
|
| 216 |
|
| 217 |
```bash
|
| 218 |
-
# Default: rollout aggregation + cross-attention + per-head grid
|
| 219 |
./run.sh
|
| 220 |
-
|
| 221 |
-
# Use GPU config (all features enabled)
|
| 222 |
-
./run.sh --config configs/gpu.yaml
|
| 223 |
-
|
| 224 |
-
# Your fine-tuned model
|
| 225 |
./run.sh --model path/to/finetuned_checkpoint --dataset path/to/dataset
|
| 226 |
-
|
| 227 |
-
# More frames, specific episode
|
| 228 |
./run.sh --episode 3 --num-frames 12
|
| 229 |
-
|
| 230 |
-
# Override the language instruction (useful for multi-task datasets)
|
| 231 |
./run.sh --task "pick up the red cube"
|
| 232 |
-
|
| 233 |
-
# Last-layer method instead of rollout
|
| 234 |
./run.sh --method last-layer
|
| 235 |
-
|
| 236 |
-
# Skip cross-attention capture (faster, omits rows 4-5)
|
| 237 |
-
./run.sh --no-cross-attention
|
| 238 |
-
|
| 239 |
-
# Skip per-head attention grid
|
| 240 |
-
./run.sh --no-show-heads
|
| 241 |
-
|
| 242 |
-
# Raw attention without positional baseline subtraction
|
| 243 |
./run.sh --raw-attention
|
| 244 |
-
|
| 245 |
-
# Higher threshold to suppress more positional noise (default 0.5)
|
| 246 |
./run.sh --attn-threshold 0.7
|
| 247 |
-
|
| 248 |
-
# No threshold (show all baseline-subtracted values)
|
| 249 |
./run.sh --attn-threshold 0
|
|
|
|
| 250 |
|
| 251 |
-
# Gradient
|
| 252 |
-
./run.sh --gradient
|
| 253 |
|
| 254 |
-
|
|
|
|
| 255 |
./run.sh --gradient saliency
|
| 256 |
-
|
| 257 |
-
# SmoothGrad with 20 samples for cleaner saliency maps
|
| 258 |
./run.sh --gradient saliency --smooth-grad 20
|
| 259 |
-
|
| 260 |
-
# Attention on MPS, gradients on CPU (avoids MPS backward issues)
|
| 261 |
./run.sh --device mps --gradient both --gradient-device cpu
|
|
|
|
| 262 |
|
| 263 |
-
# Extended
|
| 264 |
-
./run.sh --cross-attention --per-step-cross-attention
|
| 265 |
|
| 266 |
-
|
|
|
|
| 267 |
./run.sh --gradient gradcam --gradcam-connector --gradcam-vlm-layers 4,8,12,16
|
| 268 |
-
|
| 269 |
-
# Extended: vision vs state attribution
|
| 270 |
./run.sh --gradient gradcam --vision-vs-state
|
| 271 |
-
|
| 272 |
-
# Extended: per-action-dim GradCAM (GPU recommended)
|
| 273 |
./run.sh --gradient gradcam --per-action-dim
|
| 274 |
-
|
| 275 |
-
# Extended: compare attention between two task instructions
|
| 276 |
./run.sh --language-diff "pick up the blue cube"
|
|
|
|
| 277 |
|
| 278 |
-
# Model internals
|
| 279 |
-
./run.sh --internals-only
|
| 280 |
|
| 281 |
-
|
|
|
|
| 282 |
./run.sh --with-internals
|
| 283 |
-
|
| 284 |
-
# More sample frames for stable internals estimates
|
| 285 |
./run.sh --internals-only --internals-frames 10
|
| 286 |
-
|
| 287 |
-
# Custom thresholds for internals warnings
|
| 288 |
./run.sh --internals-only --entropy-warn 0.85 --redundancy-warn 0.75
|
| 289 |
-
|
| 290 |
-
# Explicit device override (auto-detected by default: mps > cuda > cpu)
|
| 291 |
-
./run.sh --device cuda
|
| 292 |
```
|
| 293 |
|
| 294 |
-
|
|
|
|
|
|
|
| 295 |
|
| 296 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
## Web Viewer
|
| 299 |
|
| 300 |
-
The web viewer lets you
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |

|
| 303 |
-
*Browsing
|
| 304 |
|
| 305 |

|
| 306 |
-
*Run Insights
|
| 307 |
|
| 308 |

|
| 309 |
-
*Compare
|
| 310 |
-
|
| 311 |
-
### Launch (development)
|
| 312 |
|
| 313 |
-
|
| 314 |
|
| 315 |
```bash
|
| 316 |
source .venv/bin/activate
|
| 317 |
./start_servers.sh
|
| 318 |
-
# or with a custom outputs folder:
|
| 319 |
./start_servers.sh --base-dir ./my_outputs
|
| 320 |
```
|
| 321 |
|
| 322 |
This starts:
|
| 323 |
-
- **Backend** (FastAPI) at `http://localhost:8080`
|
| 324 |
-
- **Frontend** (Vite dev server) at `http://localhost:5173`
|
| 325 |
|
| 326 |
-
|
|
|
|
| 327 |
|
| 328 |
-
|
|
|
|
|
|
|
| 329 |
|
| 330 |
```bash
|
| 331 |
-
cd web/frontend
|
|
|
|
|
|
|
|
|
|
| 332 |
python inspect_attention.py serve --port 8080 --base-dir ./outputs
|
| 333 |
```
|
| 334 |
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
### LLM analysis setup
|
| 338 |
|
| 339 |
-
|
| 340 |
|
| 341 |
```bash
|
| 342 |
-
# Anthropic (Claude)
|
| 343 |
export ANTHROPIC_API_KEY=sk-ant-...
|
| 344 |
-
|
| 345 |
-
# OpenAI (GPT-4o)
|
| 346 |
export OPENAI_API_KEY=sk-...
|
| 347 |
```
|
| 348 |
|
| 349 |
-
Click **LLM configured** in the top-right corner to choose the model and customize the analysis prompt.
|
| 350 |
-
|
| 351 |
### `serve` flags
|
| 352 |
|
| 353 |
| Flag | Default | Description |
|
| 354 |
|------|---------|-------------|
|
| 355 |
| `--port` | `8080` | Server port |
|
| 356 |
| `--host` | `0.0.0.0` | Server host |
|
| 357 |
-
| `--base-dir` | `./outputs` | Root
|
| 358 |
-
| `--no-open` | off |
|
| 359 |
|
| 360 |
-
|
| 361 |
|
| 362 |
-
|
|
|
|
| 363 |
|
| 364 |
-
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
| 376 |
-
|
|
| 377 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
|
| 379 |
-
|
| 380 |
|
| 381 |
-
|
| 382 |
-
|------|---------|-------------|
|
| 383 |
-
| `--method` | `rollout` | `last-layer`, `rollout`, or `all-layers` |
|
| 384 |
-
| `--cross-attention` | `true` | Capture action-expert cross-attention |
|
| 385 |
-
| `--show-heads` | `true` | Save per-head attention grid for first frame |
|
| 386 |
-
| `--raw-attention` | `false` | Skip positional baseline subtraction |
|
| 387 |
-
| `--attn-threshold` | `0.5` | Percentile (0-1) below which attention values are zeroed to suppress positional noise |
|
| 388 |
|
| 389 |
-
|
|
|
|
| 390 |
|
| 391 |
-
|
| 392 |
-
|------|---------|-------------|
|
| 393 |
-
| `--gradient` | off | `saliency`, `gradcam`, or `both` (bare `--gradient` means `both`) |
|
| 394 |
-
| `--gradient-device` | same as `--device` | Device for gradient computation (`cpu`, `cuda`, `mps`) |
|
| 395 |
-
| `--gradient-seed` | `42` | Fixed noise seed for reproducible gradient attribution |
|
| 396 |
-
| `--smooth-grad` | `1` | SmoothGrad samples (1 = vanilla saliency, >1 = averaged over N noisy inputs) |
|
| 397 |
-
| `--smooth-grad-sigma` | `0.15` | Gaussian noise std for SmoothGrad |
|
| 398 |
|
| 399 |
-
|
| 400 |
|
| 401 |
-
|
|
| 402 |
-
|------
|
| 403 |
-
|
|
| 404 |
-
|
|
| 405 |
-
|
|
| 406 |
-
|
|
| 407 |
-
| `--per-action-dim` | `false` | Per-action-dimension GradCAM (uses `retain_graph` -- GPU recommended) |
|
| 408 |
-
| `--language-diff` | off | Language-conditional comparison (`auto` to auto-generate alt task, or provide a string) |
|
| 409 |
|
| 410 |
-
|
| 411 |
|
| 412 |
-
|
|
| 413 |
-
|------
|
| 414 |
-
|
|
| 415 |
-
|
|
| 416 |
-
|
|
| 417 |
-
|
|
| 418 |
-
| `--entropy-critical` | `0.95` | Entropy ratio threshold for "dead" heads |
|
| 419 |
-
| `--entropy-low` | `0.1` | Entropy ratio threshold for "collapsed" heads |
|
| 420 |
-
| `--redundancy-warn` | `0.7` | Cosine similarity threshold for "high redundancy" |
|
| 421 |
-
| `--redundancy-critical` | `0.9` | Cosine similarity threshold for "collapsed" heads |
|
| 422 |
|
| 423 |
-
|
| 424 |
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
-
###
|
| 428 |
|
| 429 |
-
|
|
| 430 |
-
|---------
|
| 431 |
-
|
|
| 432 |
-
|
|
| 433 |
-
|
|
| 434 |
-
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
-
###
|
| 437 |
|
| 438 |
-
|
|
| 439 |
-
|------
|
| 440 |
-
|
|
| 441 |
-
|
|
| 442 |
-
|
|
| 443 |
-
| Self-attn focused but cross-attn diffuse | Encoder features are good but the decoder doesn't exploit them |
|
| 444 |
|
| 445 |
-
###
|
| 446 |
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
-
|
| 450 |
|
| 451 |
-
|
|
| 452 |
-
|---------|----------------|
|
| 453 |
-
|
|
| 454 |
-
|
|
| 455 |
-
|
|
| 456 |
-
| Saliency focused on unexpected region (e.g. table edge) | Model may be using a visual shortcut rather than task understanding |
|
| 457 |
-
| GradCAM and saliency disagree | GradCAM operates at patch level while saliency is pixel-level -- some divergence is normal, but large disagreement warrants investigation |
|
| 458 |
|
| 459 |
-
###
|
| 460 |
|
| 461 |
-
|
| 462 |
-
|---------|-----------------|
|
| 463 |
-
| Per-step cross-attention | Focus should sharpen over denoising steps. If attention is static across steps, the denoising process isn't refining its visual queries. |
|
| 464 |
-
| Connector GradCAM | Should roughly agree with SigLIP GradCAM but at coarser resolution (8x8 vs 32x32). Large disagreement means the connector is transforming features significantly. |
|
| 465 |
-
| VLM layer GradCAM | Early layers (4) should show broad/low-level features, later layers (12, 16) should show task-specific focus. If all layers look the same, the VLM isn't progressively refining visual information. |
|
| 466 |
-
| Vision vs. state | A healthy manipulation policy typically shows 60-90% vision. Near-100% vision or near-0% vision suggests the model ignores one modality. |
|
| 467 |
-
| Per-action-dim | Different joints should attend to different regions -- e.g. shoulder_pan attends to object position, gripper attends to object shape/edges. If all dims look identical, the model uses a single visual representation for all actions. |
|
| 468 |
-
| Language diff | Changing the task instruction should shift attention to the referenced object. If attention doesn't change, the model may not be grounding language in vision. |
|
| 469 |
-
|
| 470 |
-
### Grid row reference
|
| 471 |
-
|
| 472 |
-
| Row | Name | Question it answers | Resolution | Interpretation of hot spots |
|
| 473 |
-
|-----|------|---------------------|------------|----------------------------|
|
| 474 |
-
| SigLIP self-attn | Vision encoder attention | Which patches attend to each other inside the encoder? | 32x32 patches | Encoder's internal processing focus -- structural, not necessarily action-relevant |
|
| 475 |
-
| Action cross-attn | Action-to-vision cross-attention | Which vision tokens does the action decoder query? | 8x8 tokens (post pixel-shuffle) | Visual regions the action decoder pulls information from |
|
| 476 |
-
| Saliency \|dA/dpx\| | Input-gradient saliency | If I changed this pixel, would the action change? | Full pixel (480x640) | Pixels that causally influence the predicted action -- fine-grained but noisy |
|
| 477 |
-
| Self-attn overlay | Self-attention on frame | Where does the encoder focus, overlaid on the image? | 32x32 upsampled | Visual check of encoder focus against actual scene content |
|
| 478 |
-
| Co-attention | Self x cross product | Which regions are both visually salient and action-queried? | 8x8 upsampled | Strongest attention signal for "what the model looks at to decide what to do" |
|
| 479 |
-
| GradCAM SigLIP L-1 | Gradient-weighted activations | Which learned feature regions drive the action? | 32x32 patches | Patch regions whose features most influence the action -- coarser but more semantic |
|
| 480 |
-
| GradCAM Connector | Connector gradient-weighted activations | Which post-connector tokens drive the action? | 8x8 tokens | How the pixel-shuffle connector redistributes visual importance |
|
| 481 |
-
| Lang-cond diff | GradCAM difference between two task instructions | Does changing the instruction change where the model looks? | 32x32 patches | Red = more attention with original task, blue = more with alternative |
|
| 482 |
-
|
| 483 |
-
**Attention vs gradient:**
|
| 484 |
-
|
| 485 |
-
| | Attention rows | Gradient rows |
|
| 486 |
-
|--|----------------|---------------|
|
| 487 |
-
| Measures | Correlation ("model looked here") | Causation ("changing here changes the action") |
|
| 488 |
-
| High attn + low gradient | Model looks but doesn't use it for action | -- |
|
| 489 |
-
| Low attn + high gradient | -- | Region subtly influences output without dominating attention |
|
| 490 |
-
| Both high | -- | Strong evidence this region genuinely drives behavior |
|
| 491 |
-
|
| 492 |
-
### Split device execution
|
| 493 |
-
|
| 494 |
-
Gradient computation requires `.backward()` through the full model, which can fail or be slow on MPS. Use `--gradient-device cpu` to run attention on MPS (fast, forward-only) and gradients on CPU (backward-compatible):
|
| 495 |
|
| 496 |
```bash
|
| 497 |
./run.sh --device mps --gradient both --gradient-device cpu
|
| 498 |
```
|
| 499 |
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
### Per-head patterns
|
| 503 |
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
### Model internals report
|
| 507 |
-
|
| 508 |
-
| Metric | Healthy | Warning | Critical |
|
| 509 |
-
|--------|---------|---------|----------|
|
| 510 |
-
| Spectral alpha | 2-4 | 4-6 (undertrained) | >6 (severely undertrained) or <2 (overcorrelated) |
|
| 511 |
-
| Attention entropy | 0.10-0.80 | >0.80 (unfocused) | >0.95 (dead) or <0.10 (collapsed) |
|
| 512 |
-
| Head redundancy | <0.70 (diverse) | >0.70 (redundant) | >0.90 (collapsed) |
|
| 513 |
|
| 514 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
-
|
| 517 |
-
|-----------------|----------------------|-------------|
|
| 518 |
-
| SigLIP Vision (12L, 12H) | Self-attention inside the vision encoder | Image encoding |
|
| 519 |
-
| VLM+Expert Joint Self-Attn (16L, 15H) | VLM and Expert tokens concatenated, attend to each other | Prefill (initial encoding) |
|
| 520 |
-
| Expert-to-VLM Cross-Attn (16L, 8H) | Expert queries VLM's cached keys/values | Generation (action decoding, 10 steps) |
|
| 521 |
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
|
| 524 |
-
|
| 525 |
|
| 526 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
smolvla-inspect/
|
| 530 |
-
βββ inspect_attention.py
|
| 531 |
-
βββ smolvla_inspect/
|
| 532 |
-
β βββ
|
| 533 |
-
β βββ
|
| 534 |
-
β βββ
|
| 535 |
-
β βββ
|
| 536 |
-
β βββ gradient.py
|
| 537 |
-
β βββ
|
| 538 |
-
β βββ
|
| 539 |
-
β βββ
|
| 540 |
-
β βββ
|
| 541 |
-
β βββ _compat.py
|
| 542 |
βββ web/
|
| 543 |
-
β βββ backend/
|
| 544 |
-
β
|
| 545 |
-
β β βββ config.py # Settings (base_dir, host, port, CORS origins)
|
| 546 |
-
β β βββ routers/ # API routes (runs, visualizations, internals, compare, LLM, notes)
|
| 547 |
-
β β βββ services/ # Business logic (run scanner, image loader)
|
| 548 |
-
β β βββ models/ # Pydantic request/response schemas
|
| 549 |
-
β βββ frontend/ # React + Vite + TypeScript frontend
|
| 550 |
-
β βββ src/
|
| 551 |
-
β β βββ App.tsx
|
| 552 |
-
β β βββ components/ # UI components (RunSelector, HeatmapCanvas, LLMPanel, ...)
|
| 553 |
-
β β βββ stores/ # Zustand state stores
|
| 554 |
-
β β βββ services/ # API client
|
| 555 |
-
β β βββ hooks/
|
| 556 |
-
β βββ package.json
|
| 557 |
βββ assets/
|
| 558 |
-
β βββ architecture.md # Architecture diagrams and report reference
|
| 559 |
-
β βββ gradcam_walkthrough.md # GradCAM worked example with numerical walkthrough
|
| 560 |
-
β βββ how_it_works_architecture.png
|
| 561 |
-
β βββ example_grid.png
|
| 562 |
-
β βββ example_per_head.png
|
| 563 |
-
β βββ example_model_internals_report.png
|
| 564 |
-
β βββ web_viewer_main.png # Web viewer: main visualization view
|
| 565 |
-
β βββ web_viewer_insights.png # Web viewer: Run Insights with LLM analysis
|
| 566 |
-
β βββ web_viewer_compare.png # Web viewer: Compare Runs view
|
| 567 |
βββ configs/
|
| 568 |
-
β βββ defaults.yaml # Conservative defaults (no gradients, CPU-friendly)
|
| 569 |
-
β βββ gpu.yaml # GPU config: all features enabled (CUDA, SmoothGrad N=20)
|
| 570 |
-
βββ scripts/
|
| 571 |
-
β βββ gen_architecture_diagram.py # Generates architecture diagram assets
|
| 572 |
βββ docs/
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
βββ
|
| 576 |
-
βββ
|
| 577 |
-
βββ start_servers.sh # Dev launcher: starts FastAPI backend + Vite frontend together
|
| 578 |
-
βββ run.sh # CLI wrapper that sets FFmpeg lib path (macOS)
|
| 579 |
βββ requirements.txt
|
| 580 |
-
βββ outputs/ # Generated images and reports (gitignored)
|
| 581 |
βββ README.md
|
| 582 |
```
|
| 583 |
|
| 584 |
-
---
|
| 585 |
-
|
| 586 |
## Roadmap
|
| 587 |
|
| 588 |
-
- [x]
|
| 589 |
-
- [x]
|
| 590 |
-
- [x]
|
| 591 |
-
- [x]
|
| 592 |
-
- [x]
|
| 593 |
-
- [ ]
|
| 594 |
-
- [ ]
|
| 595 |
-
- [ ]
|
| 596 |
-
- [ ]
|
| 597 |
-
|
| 598 |
-
---
|
| 599 |
|
| 600 |
## Note on FFmpeg
|
| 601 |
|
| 602 |
-
If you
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# smolvla-inspect
|
| 2 |
|
| 3 |
+
Inspect where a SmolVLA policy looks, what pixels actually drive its actions, and how its internal attention/weight structure behaves.
|
| 4 |
|
| 5 |

|
| 6 |
+
*Example inspection grid for a pick-and-place episode. It combines raw attention, overlays, and gradient attribution in one view.*
|
| 7 |
+
|
| 8 |
+
## Table of Contents
|
| 9 |
+
|
| 10 |
+
- [Quick Start](#quick-start)
|
| 11 |
+
- [What This Tool Does](#what-this-tool-does)
|
| 12 |
+
- [Setup](#setup)
|
| 13 |
+
- [Run](#run)
|
| 14 |
+
- [Web Viewer](#web-viewer)
|
| 15 |
+
- [How It Works](#how-it-works)
|
| 16 |
+
- [Interpreting Results](#interpreting-results)
|
| 17 |
+
- [CLI Reference](#cli-reference)
|
| 18 |
+
- [Project Layout](#project-layout)
|
|
|
|
| 19 |
- [Roadmap](#roadmap)
|
| 20 |
|
| 21 |
+
## Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
### 1. Install dependencies
|
| 24 |
|
| 25 |
+
```bash
|
| 26 |
+
python3.11 -m venv .venv
|
| 27 |
+
source .venv/bin/activate
|
| 28 |
+
pip install -r requirements.txt
|
| 29 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
On macOS, install FFmpeg 6 first:
|
| 32 |
|
| 33 |
+
```bash
|
| 34 |
+
brew install ffmpeg@6
|
| 35 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
### 2. Run a standard inspection
|
| 38 |
|
| 39 |
+
```bash
|
| 40 |
+
source .venv/bin/activate
|
| 41 |
+
./run.sh
|
| 42 |
+
```
|
| 43 |
|
| 44 |
+
### 3. Run gradients and the web-viewer-friendly export
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
```bash
|
| 47 |
+
./run.sh --config configs/gpu.yaml
|
| 48 |
+
```
|
| 49 |
|
| 50 |
+
### 4. Run the model internals report
|
| 51 |
|
| 52 |
+
```bash
|
| 53 |
+
./run.sh --internals-only
|
| 54 |
+
```
|
| 55 |
|
| 56 |
+
Or append it to a normal run:
|
| 57 |
|
| 58 |
+
```bash
|
| 59 |
+
./run.sh --with-internals
|
| 60 |
+
```
|
| 61 |
|
| 62 |
+
### 5. Launch the web viewer
|
| 63 |
|
| 64 |
+
```bash
|
| 65 |
+
source .venv/bin/activate
|
| 66 |
+
./start_servers.sh
|
| 67 |
+
```
|
| 68 |
|
| 69 |
+
Results are written to `outputs/` by default.
|
| 70 |
|
| 71 |
+
## What This Tool Does
|
| 72 |
|
| 73 |
+
SmolVLA is a vision-language-action policy: it takes camera images and a language instruction, then predicts robot actions. This repository gives you four practical ways to inspect that behavior:
|
| 74 |
|
| 75 |
+
| Capability | Primary flags | What it answers | Main outputs |
|
| 76 |
+
|------------|---------------|-----------------|--------------|
|
| 77 |
+
| Attention visualization | default, `--cross-attention`, `--show-heads` | Where does the encoder or action decoder focus? | `episode_dashboard_ep*.png`, `per_head_ep*.png` |
|
| 78 |
+
| Gradient attribution | `--gradient` | Which pixels causally affect the predicted action? | extra rows in the dashboard |
|
| 79 |
+
| Extended attribution | `--gradcam-connector`, `--gradcam-vlm-layers`, `--vision-vs-state`, `--per-action-dim`, `--language-diff` | How information moves through the connector, VLM, and action heads | feature-specific PNGs / reports |
|
| 80 |
+
| Model internals report | `--internals-only`, `--with-internals` | Are weights and attention heads well-behaved internally? | `model_internals_report.md`, `model_internals_report.png` |
|
| 81 |
|
| 82 |
+
### Core outputs
|
| 83 |
|
| 84 |
+
- Main grid per episode: attention, overlays, and optional gradient rows.
|
| 85 |
+
- Optional per-head grid for SigLIP attention heads on the first frame.
|
| 86 |
+
- Structured run directory for the web viewer when `--export-data` is enabled.
|
| 87 |
+
- Model internals report covering spectral alpha, attention entropy, and head redundancy.
|
| 88 |
|
| 89 |
+
### Model internals at a glance
|
| 90 |
|
| 91 |
+
The internals report runs three checks across the SigLIP vision encoder, VLM text model, action expert, connector, and projection heads:
|
| 92 |
|
| 93 |
+
1. Weight spectral analysis with WeightWatcher.
|
| 94 |
+
2. Attention entropy across key attention operations.
|
| 95 |
+
3. Head redundancy within each layer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
Use `--internals-only` when you want just that report. Use `--with-internals` when you want it in addition to the normal attention / gradient run.
|
| 98 |
|
| 99 |
+

|
| 100 |
+
*Example 3-panel internals report. The full markdown version lives at [assets/example_model_internals_report.md](assets/example_model_internals_report.md).*
|
| 101 |
|
| 102 |
+
For a visual walkthrough of the architecture behind these views, see [assets/architecture.md](assets/architecture.md).
|
| 103 |
|
| 104 |
+
## Setup
|
| 105 |
|
| 106 |
+
### Requirements
|
|
|
|
| 107 |
|
| 108 |
+
- Python 3.10+
|
| 109 |
+
- FFmpeg 4-7 for video decoding through TorchCodec
|
| 110 |
+
- Node.js 20.19+ for the web viewer
|
| 111 |
|
| 112 |
+
### macOS
|
| 113 |
|
| 114 |
+
Install FFmpeg 6:
|
| 115 |
|
| 116 |
```bash
|
| 117 |
brew install ffmpeg@6
|
| 118 |
```
|
| 119 |
|
| 120 |
+
Then install Python dependencies:
|
| 121 |
|
| 122 |
```bash
|
| 123 |
+
python3.11 -m venv .venv
|
| 124 |
+
source .venv/bin/activate
|
| 125 |
pip install -r requirements.txt
|
| 126 |
```
|
| 127 |
|
| 128 |
+
Install Node.js if you want the web viewer:
|
| 129 |
|
| 130 |
+
```bash
|
| 131 |
+
brew install node
|
| 132 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
### Ubuntu + CUDA
|
| 135 |
|
| 136 |
+
For an NVIDIA GPU machine, use the setup helper:
|
| 137 |
|
| 138 |
```bash
|
|
|
|
| 139 |
chmod +x clone-and-setup.sh && ./clone-and-setup.sh
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
Or if the repo is already cloned:
|
| 143 |
|
| 144 |
+
```bash
|
| 145 |
chmod +x setup-gpu.sh && ./setup-gpu.sh
|
| 146 |
```
|
| 147 |
|
| 148 |
+
`setup-gpu.sh` installs CUDA-compatible PyTorch, creates a virtualenv, installs dependencies, and checks GPU access.
|
| 149 |
+
|
| 150 |
+
### Node.js note
|
| 151 |
|
| 152 |
+
On Ubuntu, the default `apt install nodejs` is often too old. Prefer [NodeSource](https://github.com/nodesource/distributions) or `nvm`.
|
| 153 |
|
| 154 |
## Run
|
| 155 |
|
| 156 |
+
Use `run.sh` on macOS so TorchCodec can find FFmpeg 6:
|
| 157 |
|
| 158 |
```bash
|
| 159 |
source .venv/bin/activate
|
| 160 |
./run.sh
|
| 161 |
```
|
| 162 |
|
| 163 |
+
If you prefer calling Python directly:
|
| 164 |
|
| 165 |
```bash
|
| 166 |
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/ffmpeg@6/lib:$DYLD_LIBRARY_PATH"
|
|
|
|
| 169 |
|
| 170 |
### Config files
|
| 171 |
|
| 172 |
+
Defaults come from `configs/defaults.yaml`. Use `--config` to load another config; direct CLI flags still override config values.
|
| 173 |
+
|
| 174 |
+
| Config | Purpose |
|
| 175 |
+
|--------|---------|
|
| 176 |
+
| `configs/defaults.yaml` | Conservative CPU-friendly defaults |
|
| 177 |
+
| `configs/gpu.yaml` | CUDA-oriented config with gradients and extended attribution enabled |
|
| 178 |
+
|
| 179 |
+
Example:
|
| 180 |
|
| 181 |
```bash
|
|
|
|
| 182 |
./run.sh --config configs/gpu.yaml
|
|
|
|
|
|
|
| 183 |
./run.sh --config configs/gpu.yaml --episode 3
|
| 184 |
```
|
| 185 |
|
| 186 |
+
### Common commands
|
| 187 |
|
| 188 |
+
#### Basic attention inspection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
```bash
|
|
|
|
| 191 |
./run.sh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
./run.sh --model path/to/finetuned_checkpoint --dataset path/to/dataset
|
|
|
|
|
|
|
| 193 |
./run.sh --episode 3 --num-frames 12
|
|
|
|
|
|
|
| 194 |
./run.sh --task "pick up the red cube"
|
|
|
|
|
|
|
| 195 |
./run.sh --method last-layer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
./run.sh --raw-attention
|
|
|
|
|
|
|
| 197 |
./run.sh --attn-threshold 0.7
|
|
|
|
|
|
|
| 198 |
./run.sh --attn-threshold 0
|
| 199 |
+
```
|
| 200 |
|
| 201 |
+
#### Gradient attribution
|
|
|
|
| 202 |
|
| 203 |
+
```bash
|
| 204 |
+
./run.sh --gradient
|
| 205 |
./run.sh --gradient saliency
|
|
|
|
|
|
|
| 206 |
./run.sh --gradient saliency --smooth-grad 20
|
|
|
|
|
|
|
| 207 |
./run.sh --device mps --gradient both --gradient-device cpu
|
| 208 |
+
```
|
| 209 |
|
| 210 |
+
#### Extended attribution
|
|
|
|
| 211 |
|
| 212 |
+
```bash
|
| 213 |
+
./run.sh --cross-attention --per-step-cross-attention
|
| 214 |
./run.sh --gradient gradcam --gradcam-connector --gradcam-vlm-layers 4,8,12,16
|
|
|
|
|
|
|
| 215 |
./run.sh --gradient gradcam --vision-vs-state
|
|
|
|
|
|
|
| 216 |
./run.sh --gradient gradcam --per-action-dim
|
|
|
|
|
|
|
| 217 |
./run.sh --language-diff "pick up the blue cube"
|
| 218 |
+
```
|
| 219 |
|
| 220 |
+
#### Model internals
|
|
|
|
| 221 |
|
| 222 |
+
```bash
|
| 223 |
+
./run.sh --internals-only
|
| 224 |
./run.sh --with-internals
|
|
|
|
|
|
|
| 225 |
./run.sh --internals-only --internals-frames 10
|
|
|
|
|
|
|
| 226 |
./run.sh --internals-only --entropy-warn 0.85 --redundancy-warn 0.75
|
|
|
|
|
|
|
|
|
|
| 227 |
```
|
| 228 |
|
| 229 |
+
Backward-compatible aliases `--model-health` and `--health-frames` are still accepted, but `--internals-only` and `--internals-frames` are the primary names now.
|
| 230 |
+
|
| 231 |
+
### Output layout
|
| 232 |
|
| 233 |
+
With `--export-data` enabled, each run gets a structured folder under `outputs/`:
|
| 234 |
+
|
| 235 |
+
```text
|
| 236 |
+
run_YYYY-MM-DD_HH-MM-SS/
|
| 237 |
+
images/
|
| 238 |
+
data/
|
| 239 |
+
run_manifest.json
|
| 240 |
+
```
|
| 241 |
+
|
| 242 |
+
That structure is what the web viewer reads.
|
| 243 |
|
| 244 |
## Web Viewer
|
| 245 |
|
| 246 |
+
The web viewer lets you:
|
| 247 |
+
|
| 248 |
+
- browse generated runs and available visualizations,
|
| 249 |
+
- inspect frames interactively,
|
| 250 |
+
- compare runs side by side,
|
| 251 |
+
- view model internals when exported,
|
| 252 |
+
- attach LLM-generated analysis to runs and visualizations.
|
| 253 |
|
| 254 |

|
| 255 |
+
*Browsing per-frame visualizations in the main viewer.*
|
| 256 |
|
| 257 |

|
| 258 |
+
*Run Insights summarizes statistics across a run and supports LLM analysis.*
|
| 259 |
|
| 260 |

|
| 261 |
+
*Compare multiple runs side by side.*
|
|
|
|
|
|
|
| 262 |
|
| 263 |
+
### Development launch
|
| 264 |
|
| 265 |
```bash
|
| 266 |
source .venv/bin/activate
|
| 267 |
./start_servers.sh
|
|
|
|
| 268 |
./start_servers.sh --base-dir ./my_outputs
|
| 269 |
```
|
| 270 |
|
| 271 |
This starts:
|
|
|
|
|
|
|
| 272 |
|
| 273 |
+
- backend on `http://localhost:8080`
|
| 274 |
+
- frontend on `http://localhost:5173`
|
| 275 |
|
| 276 |
+
### Production-style launch
|
| 277 |
+
|
| 278 |
+
Build the frontend once, then serve from FastAPI:
|
| 279 |
|
| 280 |
```bash
|
| 281 |
+
cd web/frontend
|
| 282 |
+
npm install
|
| 283 |
+
npm run build
|
| 284 |
+
cd ../..
|
| 285 |
python inspect_attention.py serve --port 8080 --base-dir ./outputs
|
| 286 |
```
|
| 287 |
|
| 288 |
+
### LLM setup
|
|
|
|
|
|
|
| 289 |
|
| 290 |
+
Set one of these before launching if you want LLM analysis:
|
| 291 |
|
| 292 |
```bash
|
|
|
|
| 293 |
export ANTHROPIC_API_KEY=sk-ant-...
|
|
|
|
|
|
|
| 294 |
export OPENAI_API_KEY=sk-...
|
| 295 |
```
|
| 296 |
|
|
|
|
|
|
|
| 297 |
### `serve` flags
|
| 298 |
|
| 299 |
| Flag | Default | Description |
|
| 300 |
|------|---------|-------------|
|
| 301 |
| `--port` | `8080` | Server port |
|
| 302 |
| `--host` | `0.0.0.0` | Server host |
|
| 303 |
+
| `--base-dir` | `./outputs` | Root directory scanned for runs |
|
| 304 |
+
| `--no-open` | off | Do not auto-open the browser |
|
| 305 |
|
| 306 |
+
## How It Works
|
| 307 |
|
| 308 |
+

|
| 309 |
+
*Left: where attention is captured. Right: how patch attention becomes a spatial heatmap.*
|
| 310 |
|
| 311 |
+
### Pipeline
|
| 312 |
|
| 313 |
+
1. Load a SmolVLA policy and a LeRobot dataset.
|
| 314 |
+
2. Capture self-attention from the SigLIP vision encoder.
|
| 315 |
+
3. Optionally capture action-expert cross-attention into the VLM prefix.
|
| 316 |
+
4. Convert patch-level scores into spatial heatmaps.
|
| 317 |
+
5. Optionally compute gradients, GradCAM, or extended attribution views.
|
| 318 |
+
6. Save images plus structured data for the viewer.
|
| 319 |
+
|
| 320 |
+
### Main dashboard rows
|
| 321 |
+
|
| 322 |
+
| Row | Content | When shown |
|
| 323 |
+
|-----|---------|------------|
|
| 324 |
+
| 1 | Original frame | always |
|
| 325 |
+
| 2 | SigLIP self-attention heatmap | always |
|
| 326 |
+
| 3 | Action cross-attention heatmap | `--cross-attention` |
|
| 327 |
+
| 4 | Saliency / SmoothGrad overlay | `--gradient saliency` or `both` |
|
| 328 |
+
| 5 | Self-attention overlay | always |
|
| 329 |
+
| 6 | Co-attention overlay | `--cross-attention` |
|
| 330 |
+
| 7 | GradCAM overlay (SigLIP) | `--gradient gradcam` or `both` |
|
| 331 |
+
| 8 | GradCAM overlay (Connector) | `--gradcam-connector` |
|
| 332 |
+
| 9 | Language-conditional diff | `--language-diff` |
|
| 333 |
|
| 334 |
+
### Per-head grid
|
| 335 |
|
| 336 |
+
With `--show-heads`, the first frame gets a separate 12-head SigLIP grid:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
|
| 338 |
+

|
| 339 |
+
*Look for specialization: some heads should track objects, gripper geometry, or broader scene structure.*
|
| 340 |
|
| 341 |
+
## Interpreting Results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
+
### Self-attention
|
| 344 |
|
| 345 |
+
| Pattern | Interpretation |
|
| 346 |
+
|---------|----------------|
|
| 347 |
+
| Bright on gripper, object, and goal | good task-relevant visual focus |
|
| 348 |
+
| Bright on shelves, cables, or table texture | possible background shortcut |
|
| 349 |
+
| Uniform / diffuse everywhere | weak or unfocused visual features |
|
| 350 |
+
| Focus shifts sensibly over time | model is tracking task progression |
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
### Cross-attention
|
| 353 |
|
| 354 |
+
| Pattern | Interpretation |
|
| 355 |
+
|---------|----------------|
|
| 356 |
+
| Tight focus on gripper tip and target object | decoder is reading useful vision tokens |
|
| 357 |
+
| Diffuse over all vision tokens | decoder has not specialized well |
|
| 358 |
+
| Self-attn diffuse but cross-attn focused | decoder is filtering noisy encoder features |
|
| 359 |
+
| Self-attn focused but cross-attn diffuse | encoder is better than the decoder's use of it |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
+
### Gradient attribution
|
| 362 |
|
| 363 |
+
| Pattern | Interpretation |
|
| 364 |
+
|---------|----------------|
|
| 365 |
+
| Saliency highlights object / gripper edges | action depends on relevant pixels |
|
| 366 |
+
| GradCAM agrees with attention | representation and causal signal align |
|
| 367 |
+
| Attention focused but saliency diffuse | model may look there without using it |
|
| 368 |
+
| Saliency spikes on irrelevant structure | likely shortcut or bias |
|
| 369 |
|
| 370 |
+
### Extended attribution checks
|
| 371 |
|
| 372 |
+
| Feature | What to look for |
|
| 373 |
+
|---------|-----------------|
|
| 374 |
+
| Per-step cross-attention | focus should sharpen over denoising steps |
|
| 375 |
+
| Connector GradCAM | should broadly agree with SigLIP GradCAM at coarser resolution |
|
| 376 |
+
| VLM layer GradCAM | later layers should become more task-specific |
|
| 377 |
+
| Vision vs. state | extreme imbalance can indicate one modality is ignored |
|
| 378 |
+
| Per-action-dim | different joints should not all attend to identical regions |
|
| 379 |
+
| Language diff | changing the instruction should move visual emphasis |
|
| 380 |
|
| 381 |
+
### Attention vs. gradient
|
| 382 |
|
| 383 |
+
| Case | Meaning |
|
| 384 |
+
|------|---------|
|
| 385 |
+
| High attention, low gradient | model represents the region but may not rely on it |
|
| 386 |
+
| Low attention, high gradient | subtle but causally important region |
|
| 387 |
+
| High attention, high gradient | strongest evidence of behavior-driving focus |
|
|
|
|
| 388 |
|
| 389 |
+
### Model internals report
|
| 390 |
|
| 391 |
+
| Metric | Healthy | Warning | Critical |
|
| 392 |
+
|--------|---------|---------|----------|
|
| 393 |
+
| Spectral alpha | 2-4 | 4-6 | >6 or <2 |
|
| 394 |
+
| Attention entropy | 0.10-0.80 | >0.80 | >0.95 or <0.10 |
|
| 395 |
+
| Head redundancy | <0.70 | >0.70 | >0.90 |
|
| 396 |
|
| 397 |
+
The report covers three attention components:
|
| 398 |
|
| 399 |
+
| Report component | Architecture operation |
|
| 400 |
+
|-----------------|------------------------|
|
| 401 |
+
| SigLIP Vision (12L, 12H) | self-attention inside the vision encoder |
|
| 402 |
+
| VLM+Expert Joint Self-Attn (16L, 15H) | joint prefill self-attention |
|
| 403 |
+
| Expert-to-VLM Cross-Attn (16L, 8H) | action decoding cross-attention |
|
|
|
|
|
|
|
| 404 |
|
| 405 |
+
### Split-device tip
|
| 406 |
|
| 407 |
+
If MPS backward is unstable or slow, run attention on MPS and gradients on CPU:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
|
| 409 |
```bash
|
| 410 |
./run.sh --device mps --gradient both --gradient-device cpu
|
| 411 |
```
|
| 412 |
|
| 413 |
+
## CLI Reference
|
|
|
|
|
|
|
| 414 |
|
| 415 |
+
### General
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
+
| Flag | Default | Description |
|
| 418 |
+
|------|---------|-------------|
|
| 419 |
+
| `--config` | `configs/defaults.yaml` | Load defaults from a YAML config |
|
| 420 |
+
| `--model` | `lerobot/smolvla_base` | HuggingFace model ID or local path |
|
| 421 |
+
| `--dataset` | `lerobot/svla_so101_pickplace` | LeRobot dataset ID or local path |
|
| 422 |
+
| `--episode` | `0` | Episode index |
|
| 423 |
+
| `--num-frames` | `8` | Number of sampled frames |
|
| 424 |
+
| `--image-key` | auto | Dataset image key override |
|
| 425 |
+
| `--image-map` | off | Explicit dataset-to-policy image key mapping |
|
| 426 |
+
| `--task` | dataset value | Override language instruction |
|
| 427 |
+
| `--output-dir` | `./outputs` | Output directory |
|
| 428 |
+
| `--device` | `auto` | `auto`, `cpu`, `cuda`, `mps` |
|
| 429 |
+
| `--save-individual` | `true` | Save per-frame overlays as separate files |
|
| 430 |
+
| `--export-data` | `true` | Save structured run data for the web viewer |
|
| 431 |
+
| `--no-export-data` | off | Disable structured run export |
|
| 432 |
+
| `--run-name` | timestamped | Override the generated run folder name |
|
| 433 |
|
| 434 |
+
### Attention
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
+
| Flag | Default | Description |
|
| 437 |
+
|------|---------|-------------|
|
| 438 |
+
| `--method` | `rollout` | `last-layer`, `rollout`, or `all-layers` |
|
| 439 |
+
| `--cross-attention` | `true` | Capture action-expert cross-attention |
|
| 440 |
+
| `--show-heads` | `true` | Save a per-head grid for frame 0 |
|
| 441 |
+
| `--raw-attention` | `false` | Skip positional baseline subtraction |
|
| 442 |
+
| `--attn-threshold` | `0.5` | Zero out low attention values after normalization |
|
| 443 |
+
| `--skip-attention` | `false` | Skip hook-based attention extraction and only run gradient features |
|
| 444 |
|
| 445 |
+
### Gradients and extended attribution
|
| 446 |
|
| 447 |
+
| Flag | Default | Description |
|
| 448 |
+
|------|---------|-------------|
|
| 449 |
+
| `--gradient` | off | `saliency`, `gradcam`, or `both` |
|
| 450 |
+
| `--gradient-device` | same as `--device` | Device for gradient computation |
|
| 451 |
+
| `--gradient-seed` | `42` | Fixed seed for reproducibility |
|
| 452 |
+
| `--smooth-grad` | `1` | SmoothGrad sample count |
|
| 453 |
+
| `--smooth-grad-sigma` | `0.15` | SmoothGrad noise std |
|
| 454 |
+
| `--per-step-cross-attention` | `false` | Save cross-attention per denoising step |
|
| 455 |
+
| `--gradcam-connector` | `false` | GradCAM on connector output |
|
| 456 |
+
| `--gradcam-vlm-layers` | off | GradCAM on selected VLM layers |
|
| 457 |
+
| `--vision-vs-state` | `false` | Compare vision vs state attribution |
|
| 458 |
+
| `--per-action-dim` | `false` | Per-action-dimension GradCAM |
|
| 459 |
+
| `--language-diff` | off | Compare attribution between two task prompts |
|
| 460 |
+
|
| 461 |
+
### Model internals
|
| 462 |
|
| 463 |
+
| Flag | Default | Description |
|
| 464 |
+
|------|---------|-------------|
|
| 465 |
+
| `--internals-only` | `false` | Run only the model internals report |
|
| 466 |
+
| `--with-internals` | `false` | Add the model internals report to a standard run |
|
| 467 |
+
| `--internals-frames` | `5` | Sampled frames for entropy / redundancy |
|
| 468 |
+
| `--entropy-warn` | `0.8` | Unfocused-head threshold |
|
| 469 |
+
| `--entropy-critical` | `0.95` | Dead-head threshold |
|
| 470 |
+
| `--entropy-low` | `0.1` | Collapsed-head threshold |
|
| 471 |
+
| `--redundancy-warn` | `0.7` | High-redundancy threshold |
|
| 472 |
+
| `--redundancy-critical` | `0.9` | Collapsed-redundancy threshold |
|
| 473 |
+
|
| 474 |
+
## Project Layout
|
| 475 |
+
|
| 476 |
+
```text
|
| 477 |
smolvla-inspect/
|
| 478 |
+
βββ inspect_attention.py
|
| 479 |
+
βββ smolvla_inspect/
|
| 480 |
+
β βββ cli.py
|
| 481 |
+
β βββ capture.py
|
| 482 |
+
β βββ data.py
|
| 483 |
+
β βββ export.py
|
| 484 |
+
β βββ gradient.py
|
| 485 |
+
β βββ heatmap.py
|
| 486 |
+
β βββ internals.py
|
| 487 |
+
β βββ serve.py
|
| 488 |
+
β βββ viz.py
|
| 489 |
+
β βββ _compat.py
|
| 490 |
βββ web/
|
| 491 |
+
β βββ backend/
|
| 492 |
+
β βββ frontend/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
βββ assets/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 494 |
βββ configs/
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
βββ docs/
|
| 496 |
+
βββ clone-and-setup.sh
|
| 497 |
+
βββ setup-gpu.sh
|
| 498 |
+
βββ start_servers.sh
|
| 499 |
+
βββ run.sh
|
|
|
|
|
|
|
| 500 |
βββ requirements.txt
|
|
|
|
| 501 |
βββ README.md
|
| 502 |
```
|
| 503 |
|
|
|
|
|
|
|
| 504 |
## Roadmap
|
| 505 |
|
| 506 |
+
- [x] Gradient-based attribution
|
| 507 |
+
- [x] SmoothGrad
|
| 508 |
+
- [x] Extended attribution features
|
| 509 |
+
- [x] Config file support
|
| 510 |
+
- [x] Interactive web viewer
|
| 511 |
+
- [ ] Occlusion / perturbation sensitivity
|
| 512 |
+
- [ ] Representation probing
|
| 513 |
+
- [ ] Causal tracing / activation patching
|
| 514 |
+
- [ ] Temporal consistency analysis
|
|
|
|
|
|
|
| 515 |
|
| 516 |
## Note on FFmpeg
|
| 517 |
|
| 518 |
+
If you linked `ffmpeg@6` and want to switch back later:
|
| 519 |
+
|
| 520 |
+
```bash
|
| 521 |
+
brew unlink ffmpeg@6 && brew link ffmpeg
|
| 522 |
+
```
|