CodeDiffuser: Attention-Enhanced Diffusion Policy via VLM-Generated Code for Instruction Ambiguity

Guoqiang Yin, Yitong Li, Yixuan Wang, Dale Mcconachie, Paarth Shah, Ko Hashimoto, Huan Zhang, K. J. Ray Liu, Yunzhu Li2025

Abstract

Instruction ambiguity remains a significant hurdle for end-to-end robotic manipulation models. While imitation learning methods like Diffusion Policy excel at low-level motor control, they often struggle to resolve high-level semantic uncertainties, such as selecting a specific object from a cluttered scene based on vague natural language. We present CodeDiffuser, a framework that bridges high-level reasoning and low-level execution by using Vision-Language Models (VLMs) to generate executable code. This code interfaces with Visual Foundation Models (VFMs) to produce 3D attention maps, which serve as an interpretable bottleneck for a diffusion-based policy. Our experiments in simulation and real-world environments demonstrate that CodeDiffuser significantly outperforms existing language-conditioned baselines, particularly as instruction ambiguity increases.

Introduction

Natural language is inherently underspecified. When a human instructs a robot to "place the battery in the slot," the command may refer to one of several batteries or multiple potential slots. Current state-of-the-art imitation learning architectures, such as Diffusion Policy or Action Chunking Transformer (ACT), typically attempt to map raw pixels and language embeddings directly to robot actions. However, these models often fail to jointly optimize for high-level semantic reasoning (identifying the correct object) and low-level dexterity (executing precise contact-rich movements).

CodeDiffuser addresses this gap by decoupling the problem into a modular pipeline. By leveraging the reasoning capabilities of VLMs and the zero-shot segmentation power of VFMs, the system translates ambiguous instructions into precise spatial attention, allowing the low-level policy to focus exclusively on the physical execution of the task.

The CodeDiffuser Framework

The CodeDiffuser architecture operates in three distinct stages:

1. Task-Specific Code Generation

Upon receiving a natural language instruction and visual observation, a VLM (such as GPT-4o) generates Python code. Rather than predicting raw coordinates or actions, the VLM utilizes a specialized Perception API. This API includes primitives like detect(), sel_name(), and sel_pos(), which allow the model to express complex logic—such as recursive spatial reasoning or conditional object selection—in a structured, executable format.

2. 3D Attention Map Computation

The generated code is executed against a suite of Visual Foundation Models. Specifically, the system employs DINOv2 for semantic feature extraction and Segment Anything (SAM) for 3D instance segmentation. The result of this execution is a 3D attention map: a point cloud where points corresponding to task-relevant objects are highlighted. This map acts as a "semantic bridge," translating the VLM's abstract reasoning into a concrete spatial representation.

3. Low-Level Visuomotor Policy

The 3D attention map is concatenated with the raw point cloud and processed by a PointNet++ encoder. This encoded representation conditions a Diffusion Policy, which generates the 6-DoF end-effector trajectories required for the task. By forcing the high-level reasoning to output an attention map, the low-level policy's task is simplified; it no longer needs to interpret language, but rather must navigate toward the "glowing" regions of the attention map.

Experimental Evaluation

Simulation and Real-World Benchmarks

We evaluated CodeDiffuser across both simulated (SAPIEN) and real-world (ALOHA) environments. The simulation tasks, "Pack Battery" and "Hang Mug," were specifically designed to test varying levels of instruction "slackness" (ambiguity):

  • No Slackness: Specific objects are named.
  • Picked-object Slackness: The object to be moved is ambiguous.
  • Placed-object Slackness: The target location is ambiguous.
  • Full Slackness: Both the object and the target are ambiguous.

In the real world, we utilized the ALOHA bimanual system for tasks including "Pack Battery," "Hang Mug," and "Stow Books." The latter is particularly complex, requiring the robot to push existing books aside to create space for a new one.

Results and Key Insights

CodeDiffuser demonstrated substantial performance gains over language-conditioned Diffusion Policy (Lang-DP) baselines:

  • Success Rates: In simulation, CodeDiffuser achieved an 86.5% success rate, whereas Lang-DP baselines struggled between 5.5% and 12%.
  • Robustness to Ambiguity: While baseline performance plummeted as instruction slackness increased, CodeDiffuser remained robust, successfully resolving spatial relations through recursive VLM reasoning.
  • Real-World Performance: On the ALOHA system, the framework maintained an 80% success rate, effectively identifying and interacting with the correct objects in cluttered scenes.
  • Interpretability: The 3D attention maps provide a built-in debugging mechanism. Failures can be easily categorized as either perception errors (incorrect attention map) or execution errors (physical slips), a level of transparency rarely found in end-to-end models.

Discussion and Limitations

While CodeDiffuser offers a powerful solution for instruction ambiguity, it is currently limited by its dependency on the underlying VFMs. If models like DINOv2 or SAM fail to segment an object correctly, the resulting attention map will be flawed. Additionally, the current Perception API is optimized for rigid objects; extending this to deformable objects like cloth or cables remains a subject for future work. Finally, the system requires a lightweight, one-time manual labeling of reference features to help the VFMs identify specific object categories in feature space.

Conclusion

CodeDiffuser represents a significant step toward more capable and interpretable robotic systems. By using code as an intermediate representation and 3D attention as a bottleneck, the framework successfully bridges the gap between high-level linguistic reasoning and low-level physical control, providing a robust path forward for handling the inherent messiness of human language in robotic manipulation.

Summary updated

BibTeX
@misc{yin2025codediffuser,
  author = {Guoqiang Yin and Yitong Li and Yixuan Wang and Dale Mcconachie and Paarth Shah and Ko Hashimoto and Huan Zhang and K. J. Ray Liu and Yunzhu Li},
  title = {{CodeDiffuser: Attention-Enhanced Diffusion Policy via VLM-Generated Code for Instruction Ambiguity}},
  year = {2025},
  doi = {10.15607/rss.2025.xxi.072},
}
Figure