# xuejifang/lewam architecture

> Architecture diagram of the GitHub repository xuejifang/lewam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xuejifang/lewam
- Repository: https://github.com/xuejifang/lewam

## Overview

LeWAM is a robot manipulation policy that combines frozen I-JEPA visual features with a Transformer to generate action sequences, then evaluates the policy in RoboTwin. The main runtime path is RoboTwin evaluation through the LeWAM policy adapter, camera preprocessing, and pipeline inference, followed by actions applied to the simulation. Internally, the pipeline uses the vision adapter, predictor, and inference optimizations. The README also documents joint future-world prediction, AdaFuse, and DemoDPO; source excerpts establish the first two implementation areas but do not show DemoDPO internals. Some evaluation orchestration details are unsampled, so those links are omitted.

Main entry points: [`lewam/pipelines/lewam/pipeline_lewam.py`](https://github.com/xuejifang/lewam/blob/main/lewam/pipelines/lewam/pipeline_lewam.py) (LeWAM Pipeline), [`experiments/robotwin/lewam_policy/deploy_policy.py`](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/lewam_policy/deploy_policy.py) (RobotWin Policy), [`lewam/models/lewam_model.py`](https://github.com/xuejifang/lewam/blob/main/lewam/models/lewam_model.py) (Joint Action and World Predictor), [`experiments/robotwin/eval_robotwin_single.py`](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/eval_robotwin_single.py) (Single-Task Evaluator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_evaluation["RoboTwin Evaluation"]
  node_manager["Evaluation Manager"]
  node_single_eval["Single-Task Evaluator"]
end

subgraph group_policy["Policy Inference"]
  node_policy_adapter["RobotWin Policy<br/>[deploy_policy.py]"]
  node_image_utils["Image and Stats Helpers<br/>[image_utils.py]"]
end

subgraph group_model["LeWAM Model"]
  node_pipeline["LeWAM Pipeline<br/>[pipeline_lewam.py]"]
  node_vision["Vision Encoder and AdaFuse<br/>[vision_encoder.py]"]
  node_predictor["Joint Action and World Predictor<br/>[lewam_model.py]"]
  node_transformer_blocks["Transformer Blocks<br/>[module.py]"]
  node_position_encoding["3D Rotary Positions<br/>[rope.py]"]
  node_sparse_offsets["Sparse Future Offsets<br/>[sparse_offsets.py]"]
  node_demo_dpo["DemoDPO Refinement"]
end

subgraph group_optimization["Inference Support"]
  node_action_cache["Visual KV Cache<br/>[action_cache.py]"]
  node_cuda_graph["CUDA Graph Replay<br/>[cuda_graph.py]"]
end

node_user(("Evaluation User"))
node_robotwin["RoboTwin Simulator"]

node_user -->|"starts evaluation"| node_manager
node_manager -.-> node_single_eval
node_single_eval -->|"loads policy"| node_policy_adapter
node_single_eval -.->|"runs task"| node_robotwin
node_policy_adapter -->|"prepares images and stats"| node_image_utils
node_policy_adapter -->|"requests actions"| node_pipeline
node_policy_adapter -->|"sends actions"| node_robotwin
node_pipeline -->|"encodes observations"| node_vision
node_pipeline -->|"predicts actions and futures"| node_predictor
node_pipeline -->|"normalizes offsets"| node_sparse_offsets
node_pipeline -->|"uses cached inference"| node_action_cache
node_pipeline -->|"uses graph replay"| node_cuda_graph
node_predictor -->|"builds transformer"| node_transformer_blocks
node_predictor -->|"uses rotary positions"| node_position_encoding
node_predictor -->|"normalizes offsets"| node_sparse_offsets
node_position_encoding -->|"normalizes offsets"| node_sparse_offsets
node_action_cache -->|"reuses block operations"| node_transformer_blocks
node_action_cache -->|"builds rotary positions"| node_position_encoding

click node_manager "https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/run_robotwin_manager.py"
click node_single_eval "https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/eval_robotwin_single.py"
click node_policy_adapter "https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/lewam_policy/deploy_policy.py"
click node_image_utils "https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/image_utils.py"
click node_pipeline "https://github.com/xuejifang/lewam/blob/main/lewam/pipelines/lewam/pipeline_lewam.py"
click node_vision "https://github.com/xuejifang/lewam/blob/main/lewam/models/vision_encoder.py"
click node_predictor "https://github.com/xuejifang/lewam/blob/main/lewam/models/lewam_model.py"
click node_transformer_blocks "https://github.com/xuejifang/lewam/blob/main/lewam/models/module.py"
click node_position_encoding "https://github.com/xuejifang/lewam/blob/main/lewam/models/rope.py"
click node_sparse_offsets "https://github.com/xuejifang/lewam/blob/main/lewam/models/sparse_offsets.py"
click node_demo_dpo "https://github.com/xuejifang/lewam/tree/main/lewam/models"
click node_action_cache "https://github.com/xuejifang/lewam/blob/main/lewam/models/action_cache.py"
click node_cuda_graph "https://github.com/xuejifang/lewam/blob/main/lewam/pipelines/lewam/cuda_graph.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manager,node_single_eval,node_user toneBlue
class node_policy_adapter,node_image_utils toneAmber
class node_pipeline,node_vision,node_predictor,node_transformer_blocks,node_position_encoding,node_sparse_offsets,node_demo_dpo toneMint
class node_action_cache,node_cuda_graph toneRose
class node_robotwin toneIndigo
```

## Components

### RoboTwin Evaluation

- [Evaluation Manager](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/run_robotwin_manager.py): `experiments/robotwin/run_robotwin_manager.py`
- [Single-Task Evaluator](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/eval_robotwin_single.py): `experiments/robotwin/eval_robotwin_single.py`

### Policy Inference

- [RobotWin Policy](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/lewam_policy/deploy_policy.py): `experiments/robotwin/lewam_policy/deploy_policy.py`
- [Image and Stats Helpers](https://github.com/xuejifang/lewam/blob/main/experiments/robotwin/image_utils.py): `experiments/robotwin/image_utils.py`

### LeWAM Model

- [LeWAM Pipeline](https://github.com/xuejifang/lewam/blob/main/lewam/pipelines/lewam/pipeline_lewam.py): `lewam/pipelines/lewam/pipeline_lewam.py`
- [Vision Encoder and AdaFuse](https://github.com/xuejifang/lewam/blob/main/lewam/models/vision_encoder.py): `lewam/models/vision_encoder.py`
- [Joint Action and World Predictor](https://github.com/xuejifang/lewam/blob/main/lewam/models/lewam_model.py): `lewam/models/lewam_model.py`
- [Transformer Blocks](https://github.com/xuejifang/lewam/blob/main/lewam/models/module.py): `lewam/models/module.py`
- [3D Rotary Positions](https://github.com/xuejifang/lewam/blob/main/lewam/models/rope.py): `lewam/models/rope.py`
- [Sparse Future Offsets](https://github.com/xuejifang/lewam/blob/main/lewam/models/sparse_offsets.py): `lewam/models/sparse_offsets.py`
- [DemoDPO Refinement](https://github.com/xuejifang/lewam/tree/main/lewam/models): `lewam/models`

### Inference Support

- [Visual KV Cache](https://github.com/xuejifang/lewam/blob/main/lewam/models/action_cache.py): `lewam/models/action_cache.py`
- [CUDA Graph Replay](https://github.com/xuejifang/lewam/blob/main/lewam/pipelines/lewam/cuda_graph.py): `lewam/pipelines/lewam/cuda_graph.py`

### Other components

- **Evaluation User**
- **RoboTwin Simulator**

## Connections

- Evaluation User → Evaluation Manager: starts evaluation (evidence: `README.md`)
- Evaluation Manager → Single-Task Evaluator
- Single-Task Evaluator → RobotWin Policy: loads policy (evidence: `experiments/robotwin/eval_robotwin_single.py`)
- Single-Task Evaluator → RoboTwin Simulator: runs task
- RobotWin Policy → Image and Stats Helpers: prepares images and stats (evidence: `experiments/robotwin/lewam_policy/deploy_policy.py`)
- RobotWin Policy → LeWAM Pipeline: requests actions (evidence: `experiments/robotwin/lewam_policy/deploy_policy.py`)
- RobotWin Policy → RoboTwin Simulator: sends actions (evidence: `experiments/robotwin/lewam_policy/deploy_policy.py`)
- LeWAM Pipeline → Vision Encoder and AdaFuse: encodes observations (evidence: `lewam/pipelines/lewam/pipeline_lewam.py`)
- LeWAM Pipeline → Joint Action and World Predictor: predicts actions and futures (evidence: `lewam/pipelines/lewam/pipeline_lewam.py`)
- LeWAM Pipeline → Sparse Future Offsets: normalizes offsets (evidence: `lewam/pipelines/lewam/pipeline_lewam.py`)
- LeWAM Pipeline → Visual KV Cache: uses cached inference (evidence: `lewam/pipelines/lewam/pipeline_lewam.py`)
- LeWAM Pipeline → CUDA Graph Replay: uses graph replay (evidence: `lewam/pipelines/lewam/pipeline_lewam.py`)
- Joint Action and World Predictor → Transformer Blocks: builds transformer (evidence: `lewam/models/lewam_model.py`)
- Joint Action and World Predictor → 3D Rotary Positions: uses rotary positions (evidence: `lewam/models/lewam_model.py`)
- Joint Action and World Predictor → Sparse Future Offsets: normalizes offsets (evidence: `lewam/models/lewam_model.py`)
- 3D Rotary Positions → Sparse Future Offsets: normalizes offsets (evidence: `lewam/models/rope.py`)
- Visual KV Cache → Transformer Blocks: reuses block operations (evidence: `lewam/models/action_cache.py`)
- Visual KV Cache → 3D Rotary Positions: builds rotary positions (evidence: `lewam/models/action_cache.py`)
