← Back to Write-ups

Mamba + LNN Robot • Part I

Building a Robot Brain

Mamba SSMs and Liquid Neural Networks

By David Nash · · 13 min read (2,757 words)
Total Sparks: 0
Enjoyed this write-up? Charge it with sparks

Walk into an automotive manufacturing plant, and you will see dozens of heavy 6-axis robotic arms welding, stamping, and assembling chassis with millimeter precision. They move at blinding speeds with zero hesitation.

Yet if you shift a car frame three centimeters to the left, the robot keeps running its programmed path and misses the weld seam. Real cells avoid this with fixtures and guidance systems, and that infrastructure is exactly what I'd like a learned policy to need less of. Vision-guided robots aren't new, but most still run a fixed program with a camera bolted on to find the part. I wanted to see how far a single learned policy that reacts to what it sees would get, so I built one with Mamba State Space Models and Liquid Neural Networks.

How Robots Move

Most industrial robots move by blindly following pre-recorded coordinate paths. That works well in factories with rigid jigs, but if an object shifts by even a couple centimeters, the robot fails. Modern learned policies solve this by using neural networks to process camera pixels and joint sensors in real time, constantly adjusting their movement as the environment changes.

My benchmark task is a tabletop pick-and-place with a 7-DOF arm in the physics engine. A central workspace spawns either a red or green cube at a randomized position. The robot must look through its cameras, infer the color, descend, achieve a centered pinch grasp, transport the cube across the table to the corresponding landing pad (red to starboard/right at +0.2 m, green to port/left at -0.2 m), deposit it gently, and return to a ready pose.

Trained using Proximal Policy Optimization (PPO) paired with a demonstration-seeded reverse curriculum to bridge early exploration, the policy learns to coordinate vision, recurrent memory, and continuous velocity control. Privileged simulation state is used strictly during training to supervise an asymmetric critic and an auxiliary geometric grounding head. Both are discarded after training. At runtime, the deployed agent makes decisions purely from onboard sensory inputs, achieving a 98.7% task completion rate across cold-start evaluation rollouts.

FIG 1 Simulation Rollout: Franka Panda Pick-and-Place
A live capture from the MuJoCo interactive viewer showing the trained policy autonomously inspecting the cube, achieving a deep pinch grasp, transporting it across the workspace, and placing it onto the target pad. Ignore my broken table texture, I'll cover this in my domain randomization write up.

To achieve this in deployment without hardcoding coordinates or using privileged state, the policy relies strictly on realistic onboard sensors:

  • A global camera (128 × 128 RGB) gives an overhead view of the table and the landing pads.
  • A wrist camera (128 × 128 RGB) gives an eye-in-hand view with local depth, alignment, and contact cues near the fingers.
  • Proprioception is 18 numbers: 7 joint positions, 7 joint velocities, 2 gripper finger positions, and 2 finger velocities.

Why Mamba + LNN?

Robot learning leans heavily on Transformers, and I wanted to see how small a policy could get while still doing closed-loop pick-and-place from pixels. Pairing a Mamba State Space Model with a Liquid Neural Network gives a policy with a fixed-size memory and about 250,000 parameters. I haven't compared it against a plain GRU or MLP of the same size, so I can't tell you the architecture is what makes it work.

When I began researching recent work in adaptive robotics, I was looking for architectures designed specifically for continuous physical interaction. That search led directly to (Hasani et al., 2022) and their ability to approximately solve continuous neural differential equations in closed form. Around the same time, exciting work was emerging applying State Space Models to physical robot control, notably research papers like LocoMamba (vision-driven quadruped locomotion with Mamba) and StratMamba (a dual-memory Mamba for LiDAR obstacle avoidance on a quadruped).

I was also heavily inspired by recent work in real-time edge intelligence, such as "UAV Cybersecurity with Mamba-KAN-Liquid Hybrid Model: Deep Learning-Based Real-Time Anomaly Detection" (MDPI, 2025). That paper suggests that a hybrid architecture uniting Mamba's linear sequence memory with Liquid continuous dynamics can operate in strict real-time with high fidelity on physical edge systems.

If a hybrid model could process high-frequency sensor telemetry on an autonomous UAV, could a similar dual-rate hierarchy control the fine contact dynamics of a 7-DOF robotic arm? I wanted to test this in practice and see if I could contribute meaningful empirical findings to this emerging area of research.

Real robots are edge devices with hard power, thermal, latency, and memory budgets, and you can't mount a server rack of H100s to a robotic arm. I wanted a policy small enough that those budgets stop being a problem.

Even in simulation, a Transformer policy has to keep keys and values for every past step, which eats VRAM and limits how many environments a single GPU can run in parallel. A fixed-size recurrent state avoids that.

I believe we can engineer our way out of brute-force compute reliance by building smarter directly into the network architecture.

Liquid networks use continuous-time cells, so they can model smooth velocity and torque curves with very few parameters. Mamba keeps a fixed-size recurrent memory that updates in constant time per step and decides for itself which visual events to remember.

Mamba and Liquid Neural Networks may not end up being the best answer to the compute problem. Implementing them from scratch, finding where they break, and iterating on those failures is the point of this project.

A 250k-Parameter Robot Brain

Together, these inductive biases give a complete perception, memory, and motor control system totaling just 250,547 parameters. The Cortex (vision encoders plus Mamba) holds 161,444 of them and the Brainstem (CfC, actor, and critic) holds 89,103. The critic and the grounding head are only used in training, so the deployed policy is about 227k parameters, roughly 450 KB in FP16.

For scale, RT-1, a Transformer-based manipulation policy, has about 35 million parameters, roughly 140 times more.

Parameter count alone does not tell the full compute story. The two camera encoders only have about 68,000 weights, which is tiny, but because convolutional filters slide across every single pixel in an image, they require roughly (multiply-accumulate math steps) for every visual frame. At 10 frames a second, that is about 1.4 billion calculations per second (1.4 GFLOP/s).

This is why the 5:1 multi-rate split is such an advantage. By restricting the heavy image processing to just 10 times a second, the fast 50 Hz motor loop only has to crunch 18 joint numbers on each tick. That keeps the high-frequency control loop lightweight.

The deployed weights are about 450 KB in FP16 (227 KB in INT8), so on paper they fit in the 1 MB of SRAM on a Teensy 4.1. I haven't run any of this on real hardware, and the vision encoder's activations would need to fit too, so treat that as a back-of-envelope result.

The Multi-Rate Sensorimotor Dilemma

Building an end-to-end visual policy presents an immediate physical paradox: vision is slow and computationally heavy, but robot dynamics must be fast.

Take highway driving. You don't re-evaluate your lane 100 times a second. You glance down the road once or twice a second (my 10 Hz Cortex) while your hands make constant small corrections on the wheel (my 50 Hz Brainstem).

I borrowed the cortex and brainstem names from biology, where vision takes tens of milliseconds to process and spinal reflexes close the loop much faster. In physical simulation, camera rendering is the dominant bottleneck—rendering at 50 Hz consumes 95% of total environment rollout time. But if you slow the whole robot down to 10 Hz to match vision, motor control becomes jerky, contact dynamics bounce unpredictably, and the arm frequently triggers simulator collision guardrails.

FIG 2 Multi-Rate Sensorimotor Execution Loop (10 Hz Cortex vs. 50 Hz Brainstem)
Scope Time: 40.0 ms (50 Hz Tick #2: 40ms)
10 Hz Vision (Clock & Bus)
50 Hz Motor Clock
Liquid Continuous Velocity
Logic Analyzer & Continuous Signal Trace (0–200 ms)
Click anywhere on grid to seek
CLK_VIS10 Hz (100ms)⚡ CAPTURE #0 (0ms)⚡ CAPTURE #1 (100ms)DATA_CLatched ContextContext C₀ ∈ ℝ⁶⁴ (Latched across Ticks #0–#4)Context C₁ ∈ ℝ⁶⁴ (Updated via Mamba SSM)CLK_MOT50 Hz (20ms)#0#1#2#3#4#5#6#7#8#9V_CMDLiquid ActionBaseline: 0.40 m/s (Filtered ODE Smooth)0ms20ms40ms60ms80ms100ms120ms140ms160ms180ms200mst = 40.0 ms
Scope Channel Probes at t = 40.0 ms Latched Context C_0
CLK_VIS & DATA_C (10 Hz): Holding Latched C_0 (Tick 3/5)
CLK_MOT & V_CMD (50 Hz): Tick #2 (v = 0.475 m/s via ODE)
The Engineering Impact (Per 200 ms Window)
5:1 Multi-Rate Policy 1.4 GFLOP/s

Heavy Conv2D + SpatialSoftmax runs only twice in 200 ms (10 Hz). Fast 50 Hz motor loop processes only 18 proprioception values, fitting in 1 MB on-chip SRAM on a $30 microcontroller.

Naive 50 Hz Synchronous Vision 7.1 GFLOP/s

Rendering cameras 10 times in 200 ms burns 95% of GPU simulation time and causes severe thermal throttling on robotic embedded computers.

Interactive execution timeline over 200 ms. The Mamba visual cortex updates its 64-dimensional latent state C_t every 100 ms (10 Hz). The Liquid Brainstem updates every 20 ms (50 Hz), integrating continuous proprioception with the latched visual context to compute fluid motor actions.

I solve this by decoupling the agent into a 5:1 multi-rate hierarchy:

  1. The Mamba Cortex runs at 10 Hz (every 100 ms). It processes both camera images, tracks visual history across the episode, and compresses the scene into a 64-dimensional context vector .
  2. The Liquid Brainstem runs at 50 Hz (every 20 ms), five ticks per visual update. It takes the latched context vector alongside fresh, high-frequency joint proprioception to command smooth Cartesian velocity deltas.
FIG 3 Cortex-Brainstem Dual Stream Architecture
CORTEX STREAM (10 Hz / 100ms)BRAINSTEM STREAM (50 Hz / 20ms)KINEMATICS & DYNAMICSContext C_tTask Delta a_tGlobal Camera128×128 RGB (Overhead)Wrist Camera128×128 RGB (Eye-in-Hand)SpatialSoftmax KeypointsConv2D Heatmaps → 64 Coordinate Floats (μ_x, μ_y)Resolution Invariant BottleneckFiLM Conditioning(1 + γ(vis)) ⊙ prop + β(vis)Prevents Vision SuppressionMamba-3 Selective SSMO(1) Step Memory • Selective Δ(x_t) Gating10 Hz Visual Context Vector (C_t ∈ ℝ⁶⁴)Joint Proprioception18-dim: qpos (7), qvel (7), grip (4)Liquid Brainstem (CfC)Continuous ODE RecurrenceSmooth 50 Hz Action GenerationDLS Inverse KinematicsJ^† with Null-Space Posture BiasMuJoCo Franka Panda Arm
Mamba-3 Selective SSM Cortex
10 Hz (Latched for 5 brainstem ticks) Context Vector C_t ∈ ℝ⁶⁴

Tracks episode visual history with linear O(1) step memory and selective input gating Δ(x_t).

The complete neural and kinematic hierarchy. Vision flows through SpatialSoftmax keypoint bottlenecks and FiLM conditioning into a 10 Hz Mamba-3 SSM Cortex, which produces a 64-dimensional context vector C_t. A 50 Hz Liquid CfC Brainstem consumes C_t and high-frequency proprioception to command Cartesian velocity deltas resolved via Damped Least Squares IK.

The Mamba Cortex

A pick-and-place episode lasts up to 900 control steps (18 seconds at 50 Hz, or 180 cortex updates at 10 Hz). Throughout that sequence, the visual environment undergoes drastic transitions: the cube is spotted, approached, occluded by the gripper during the reach, lifted into the air, and moved to the landing zone. The agent needs a sequence model to maintain temporal continuity.

Why Mamba Over Transformers or Standard RNNs?

A Transformer keeps a key and a value for every past step and attends over all of them, so memory grows with episode length and attention compute grows quadratically. An LSTM or GRU keeps a fixed-size state and gates how much to overwrite, but it can't be trained in parallel over time. Mamba also keeps a fixed-size state, and its input-dependent parameters decide how much of each new frame gets written. That's the property I wanted.

Beyond constant step-time inference, Mamba's linear hidden state update allows entire trajectory sequences to be trained in parallel on GPUs via an , which avoids the slow sequential backpropagation through time that traditional RNNs need.

Fixed Memory with Dynamic Input Valves

In classical State Space Models (SSMs), the system maps continuous input streams into a hidden memory state using static, unchanging parameters:

Continuous-time linear state equation: A governs how hidden memory decays on its own, B ingests the incoming sensory stream x(t), and C projects hidden state to output y(t).

The block I implemented is Mamba-3, which swaps the rule below for an exponential-trapezoidal discretization that also mixes in the previous input, and adds complex-valued state. I'm showing the original zero-order-hold form because it's the simplest way to see what the timescale does.

Discretized under a timescale step size using :

Zero-Order Hold (ZOH) discretization over timescale step Δ. In Mamba, Δ is a dynamic function of input x_t: modulating memory retention Ā and input ingestion B̄ based on incoming sensory significance.

In older linear models like S4, and are fixed constants. The key change in Mamba is making and dynamic functions of the current input .

This selective mechanism allows the cortex to regulate how strongly incoming observations update the stored 64-dimensional context vector .

In robot control, when key visual milestones occur, such as spotting the target landing pad after lift, the learned weights evaluate the sensory frame and drive open to commit the new destination coordinates to memory. When observations provide steady or redundant feedback, contracts, causing and , stabilizing the stored trajectory plan () against state drift.

SpatialSoftmax & Perception

Before visual frames can enter the Mamba sequence model, they must be processed by convolutional layers. But visual RL has a common problem: flattening into a linear layer throws away spatial structure.

The usual alternative flattens the 2D feature maps into one long vector and feeds it to a linear layer. That throws away where things are in the image and ties the layer size to the image resolution.

I replace the linear bottleneck with (Levine et al., 2016). Instead of passing raw pixels, it computes the center of mass of feature activations, outputting explicit normalized coordinate landmarks:

Computes the spatial center of mass for each feature channel c. Temperature τ sharpens activations into crisp, resolution-invariant normalized landmarks in [-1, 1].
FIG 4 Interactive SpatialSoftmax Keypoint Bottleneck
Inside 1 Feature Channel: 2D Activation Heatmap → (x, y) Landmark Coordinate Click anywhere on the grid to position a visual feature (e.g. cube edge or finger contact point).
Softmax Temp τ:
Bright Cells: Feature detected (e.g. cube)
Dark Cells: Inactive background space
Crosshair: Computed Center of Mass (μx, μy)
Calculated Spatial Landmark (μx, μy): 2 Floats
μx (Horizontal Coordinate) 0.6139
μy (Vertical Coordinate) -0.2488
Dimension & Resolution Scaling (32 Channels per Camera)
Flatten + Linear Brute-Force

64×64 → 8,192 floats
128×128 → 32,768 floats

❌ Breaks on resolution change
SpatialSoftmax Invariant

2 coordinates × 32 channels
= 64 floats per camera

✅ Fixed size regardless of pixels
Click anywhere on the 16x16 feature grid to position an activation peak. SpatialSoftmax condenses the 2D distribution into two floating-point coordinates (μ_x, μ_y). With 32 feature channels per camera, each camera's image representation is compressed into just 64 numbers (128 across both cameras) regardless of image resolution.

What the Robot Actually Sees

Profiling in MuJoCo confirmed that GPU rendering costs are largely a fixed per-call overhead regardless of image resolution (64 px vs 160 px). What saves compute is rendering frequency (10 Hz vs 50 Hz). Keeping the camera resolution at a clean 128 × 128 keeps the convolutional feature extractor lightweight, avoids overfitting to micro-surface textures, and minimizes GPU VRAM consumption across thousands of parallel environments.

FIG 5 What the Robot Actually Sees: Dual Camera Streams & Keypoint Attention
Comparing what we see, what the policy sees, and what the network focuses on. Tab 1 shows a crisp 4K recording of the dual camera views. Tab 2 shows the actual 128×128 pixel stream fed to the Mamba Cortex. Tab 3 reveals the live 10 Hz SpatialSoftmax attention keypoints (32 red/cyan coordinate landmarks) dynamically tracking the cube and gripper fingers during the rollout.

In the Attention Overlay (Tab 3 above) you can see a division of labor I didn't design. The overhead camera's red keypoints stay anchored along the table's center line and the landing pads, so those filters act as a fixed world reference. The wrist camera's cyan keypoints do the opposite: they cluster on the cube's top face and follow it as the gripper descends, grasps, and lifts.

The Proprioception Suppression Problem, FiLM & Auxiliary Grounding

When training dual-stream policies (vision + joint proprioception), gradient descent can discover a damaging shortcut.

In neural networks, joint sensors produce clean, immediate feedback, while camera pixels produce noisy, delayed signals. If you just glue vision and joint data together in a simple layer, the training algorithm gets lazy. It starts ignoring the camera and tries to steer the arm using joint momentum alone.

To force the agent to keep its eyes open, I apply two complementary architectural constraints:

  1. Multiplicative FiLM conditioning (Perez et al., 2018). Instead of simple concatenation, visual keypoint embeddings generate affine parameters that scale and shift the proprioceptive embedding. Vision is a volume knob for the motor stream: collapsing the visual weights collapses the dynamic scaling , which makes it harder for the optimizer to ignore pixels:
Feature-wise Linear Modulation: visual embeddings generate affine parameters (γ, β) that scale and shift proprioception, pushing the network to route through vision rather than navigating blind.
  1. Auxiliary keypoint grounding loss. FiLM alone isn't enough: if the visual generator weights stay near zero, and leave proprioception virtually unmodulated. What keeps vis_emb honest is an auxiliary regression head trained via Mean Squared Error to predict the true 3D gripper-to-cube offset vector (). This forces the convolutional and SpatialSoftmax layers to extract accurate spatial geometry directly from pixels regardless of policy reward noise.

The Liquid Brainstem

Next is the motor half of the architecture, and the main reason I chose a .

Operating on Stale Visual Context

Under the 5:1 multi-rate execution ratio, the visual cortex updates at 10 Hz (every 100 ms) while the motor brainstem updates at 50 Hz (every 20 ms). This means that for 4 out of every 5 ticks, the controller must command actions using an identical, latched visual context vector while receiving fresh 50 Hz joint feedback.

A memoryless MLP sees the same stale context on every tick between visual updates, so any noise in the joint readings goes straight into the action. A CfC cell carries a hidden state forward, so between updates it keeps moving along the trajectory it was already on and averages out sensor noise.

The brainstem achieves this continuous smoothing using a , which computes ODE-derived state updates in closed form:

The CfC update at a fixed 50 Hz step (Δt = 0.02 s). Because Δt is constant, the time-dependent head folds into the gate, so this behaves like a gated recurrent cell: σ(W_b x) blends a fresh candidate with the previous state.
Target Direction Candidate h_inter: computes the non-linear candidate velocity direction from current proprioception and latched visual context.
Adaptive Decay Gate σ: acts as an adaptive weighting factor that smooths high-frequency joint fluctuations into a continuous velocity curve.

Note on sampling rate: In a fixed-rate controller (), the time-dependent head is algebraically redundant with . Setting fixed_rate=True in the cell merges these heads, saving ~10.6k parameters while preserving the core benefit of the Liquid network: its exponential blending recurrence.

FIG 6 Interactive Liquid Brainstem Multi-Rate Interpolator
Time: 40.0 ms (Sub-Tick #3/5: 40 ms)
Liquid CfC (ODE Filtered)
Memoryless MLP (Noisy Jitter)
50 Hz Commanded Velocity Trajectory (m/s)
100 ms Visual Latency Window
0.5000.4500.4000.350Velocity Baseline (m/s)0 ms20 ms40 ms60 ms80 msLiquid CfC: 0.415 m/sMLP Baseline: 0.395 m/s
50 Hz Sub-Tick #3: 40 ms Latched C_t (Held Constant)
Sensor Proprioception (50 Hz): -0.18 rad/s (Rebound Noise Dip ↓)
Brainstem Timestep Δt: 0.020 s (50 Hz control rate)
Actuator Command Output Comparison
Liquid CfC (Continuous ODE) v = 0.415 m/s

Fluid Momentum: Recurrent state h_t bridges latched C_t with physical joint dynamics without jerk.

Memoryless MLP Policy v = 0.395 m/s

Negative sensor swing causes immediate trajectory drop (0.395 m/s undershoot).

Tracking the commanded 50 Hz velocity trajectory across the 100 ms visual latency window. Both models receive the same latched visual context C_t and fresh 50 Hz joint feedback. The Liquid CfC cell blends each new input with its previous state, which smooths out high-frequency sensor noise. This is an illustrative schematic, not a measured rollout.

Kinematics & Null-Space Control

If an RL policy outputs raw joint position deltas (), independent exploration noise causes chaotic whipping: a tiny angular twitch at the base shoulder compounds down the kinematic chain, whipping the hand across the workspace and into the table.

Instead, the policy commands intuitive Task-Space Cartesian Deltas at the Tool Center Point (TCP):

Intuitive 7-DOF Task-Space action commanded at the Tool Center Point (TCP) instead of chaotic raw joint angles.

I resolve these Cartesian velocities into 7 joint velocities using Damped Least Squares (DLS) Inverse Kinematics:

DLS inverse kinematics resolves 6-DOF Cartesian velocities into 7 joint velocities. Damping parameter λ prevents singularity velocity spikes; the null-space projector stabilizes redundant elbow drift.

Put your palm flat on your desk and hold it still. You can still swing your elbow up, down, left, and right without moving your palm a millimeter, and that's null-space redundancy. The Panda has 7 joints but the task only constrains 6 (3 position, 3 orientation), so one degree of freedom is left over. Without something to pin it down, the elbow drifts into awkward poses. The projection matrix adds a gentle pull toward a natural resting posture without disturbing the gripper's path.

The Traps I Walked Into

Reinforcement learning has an uncanny talent for finding mathematical and physical loopholes in whatever environment you hand it. This project found several of its own.

Reward shaping turned out to be way harder to get right than I expected. Small shaping terms kept interacting with each other in ways I didn't predict, and more than once the policy found some shortcut that technically satisfied the reward without actually doing the task.

I had an issue where the arm scored well for just getting close to the cube, but it wasn't motivated enough to actually close the gap and grasp it. So the policy just learned to stop short, hovering the gripper a few centimeters above the cube and pinching at empty air over and over, farming the approach bonuses without ever committing to the grasp. Part II will cover how I get that fixed.

As you may have noticed in the video above, the table texture I was using looks a little wonky, kind of broken. Well, in Part II I tried to fix that and swapped in a properly textured table that actually looked table-shaped, and it broke the model. I'll get into how I fixed that and how it ties into training best practices. Part II also covers training at scale on cloud GPUs and modeling the Franka's real grip physics to improve its success rate.

Continue Reading

Part II covers the hovering exploit fix, realistic grip physics, training at scale, and solving the Fancy Table breakdown with real domain randomization.

Read Part II →

Have feedback or thoughts?

Found a typo, have a question on the derivations, or want to discuss this topic?

Send Feedback →
RoboticsMamba SSMLiquid NetworksReinforcement LearningMuJoCo