Mamba × TTT · IRSTD
A hidden state can itself be a learner.
Use a hand-checkable gradient step to understand internal memory, external supervision and inference boundaries.
About 25 min
Course chapters
One acronym, different questions
Classic TTT prepares an auxiliary self-supervised task during training and uses it to adjust shared features at test time under distribution shifts. TTT layers instead treat a small model’s parameters as sequence state, making internal learning part of representation computation. The ideas are related, but TTT does not universally mean entropy minimization.
| Route | What learns? | Role here |
|---|---|---|
| Classic TTT / test-domain adaptation | Shared features or selected model parameters | Historical and conceptual comparison |
| TTT layers | Inner state model W; outer θ controls its inputs and readout | Working hypothesis and experimental focus |
Write with K and V, read with Q
Project a token x into a key k, value v and query q. The inner model fW learns a mapping from k to v; q reads a representation from the updated model. W changes with the current sequence. θ contains projections, initialization or other network parameters, as defined by the implementation.
ℓinner(W) = ½‖fW(k) − v‖²
W′ = W − η∇W ℓinner(W)
z = fW′(q)
This is a teaching form of associative reconstruction. Real layers may add normalization, residuals, token/chunk batching and learned step sizes. It is not a complete implementation, and the inner loss receives no test mask.
Why is the outer loop necessary?
During IRSTD training, predicted masks and training annotations define the outer objective. The outer loop learns useful k/v/q views and how to send the inner readout into a segmentation decoder. It learns how internal learning can help detection, rather than merely minimizing each image’s inner loss.
Lseg(prediction, training mask) → update trainable outer parameters θ
Follow the selected baseline for differentiation through updates, detach boundaries, analytical updates or gradient approximations. Arbitrarily wrapping the whole inner process in no_grad breaks this contract. Inserting a new TTT layer into a trained MiM model does not guarantee useful behavior without training.
Interactive: predict the next gradient step
Start with w₀=0, k=2, v=1, η=0.1 and q=3: the gradient is −2, w₁=0.2 and the readout is 0.6. Increase the learning rate and observe when loss oscillates or grows. Lower inner loss is not evidence of higher detection accuracy.
State lifetime
| Phase | Outer θ | Inner W | Labels |
|---|---|---|---|
| Source training | Updated through the outer task objective | Initialized and internally trained as the layer specifies | Training masks supervise the outer task |
| Single-image inference | Usually fixed | Initialized at image/layer boundaries; prescribed updates run | No test masks |
| Next independent image | Still fixed | Reset by default; verify the selected algorithm | Held-out labels belong only to the evaluator |
When updates are part of normal TTT computation, disabling them is a mechanism ablation, not the original baseline. Carrying state between independent images also requires an explicit protocol.
From the toy equation to a reproducible model
Record the inner model, initialization, objective, learning rate and steps, projections, token/chunk order, reset scope, precision and gradient path. TTT-Linear uses a linear state model; TTT-MLP uses a nonlinear small network. A richer state model is not automatically faster or more memory-efficient.
Pause and check your understanding
Connect this unit to your IRSTD work
Progress and notes stay in this browser.
