XiangpengYang commited on
Commit
a3122c5
·
1 Parent(s): 21459d1

docs: design pi05 UR Gradio Space

Browse files
docs/superpowers/specs/2026-07-22-pi05-ur-gradio-design.md ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # π₀.₅ UR Hugging Face Gradio Deployment Design
2
+
3
+ ## Goal
4
+
5
+ Turn `pi0.5` into a self-contained Hugging Face Gradio Space for the locally
6
+ trained, state-conditioned UR policy. The Space loads a
7
+ `pi05_ur_demo_state` checkpoint, accepts the same observations used during
8
+ training, and returns a ten-step UR action chunk without controlling hardware.
9
+
10
+ ## Scope
11
+
12
+ The deployment supports only `pi05_ur_demo_state`. It does not expose LIBERO,
13
+ DROID, or the no-state UR configuration, and it does not host a websocket robot
14
+ control service. The Space is an inspection and action-prediction interface.
15
+
16
+ ## Runtime Packaging
17
+
18
+ The Space repository contains the OpenPI runtime required by the local UR
19
+ configuration instead of installing the upstream OpenPI repository at runtime.
20
+ This preserves the locally added `LeRobotURDataConfig`, `URInputs`,
21
+ `UROutputs`, and `pi05_ur_demo_state` configuration. Runtime files are copied
22
+ from the checked-in `VLA/openpi` implementation and reduced only where tests
23
+ prove the removed modules are unnecessary.
24
+
25
+ The Hugging Face Space uses Python 3.11 because it matches OpenPI's supported
26
+ runtime and dependency constraints. Python dependencies are pinned where the
27
+ OpenPI stack requires exact compatibility. The app uses a Hugging Face GPU
28
+ Space and decorates inference with the `spaces.GPU` helper while retaining a
29
+ local fallback when the `spaces` module is unavailable.
30
+
31
+ ## Model Artifacts and Loading
32
+
33
+ The UI accepts a Hugging Face model repository ID and checkpoint subdirectory.
34
+ The defaults come from environment variables so the public Space can be
35
+ configured without modifying code. A model manager:
36
+
37
+ 1. validates the repository ID and relative checkpoint path;
38
+ 2. downloads the checkpoint snapshot with `huggingface_hub`;
39
+ 3. verifies that the checkpoint and UR normalization statistics exist;
40
+ 4. builds the local `pi05_ur_demo_state` training configuration;
41
+ 5. creates the trained policy on CUDA; and
42
+ 6. caches one loaded model keyed by repository ID and checkpoint path.
43
+
44
+ Changing either artifact field unloads the previous model before loading the
45
+ new one. Loading is lazy, so Space startup remains responsive and model-load
46
+ failures appear in the status output instead of crashing module import.
47
+
48
+ ## Inputs and Data Flow
49
+
50
+ The Gradio interface collects:
51
+
52
+ - one fixed-camera RGB image (`video.image_0` during training);
53
+ - one wrist-camera RGB image (`video.wrist` during training);
54
+ - a required English task instruction;
55
+ - seven finite state values in the order `x, y, z, roll, pitch, yaw, gripper`;
56
+ - an integer trial index used to derive a deterministic inference seed; and
57
+ - the Hugging Face model repository and checkpoint path.
58
+
59
+ The inference adapter converts both images to RGB `uint8` arrays and constructs
60
+ the policy observation as `observation/image`, `observation/wrist_image`,
61
+ `observation/state`, and `prompt`. State is passed to the π₀.₅ discrete state
62
+ input configured during training. The policy's output transforms apply the
63
+ checkpoint's UR normalization statistics and return exactly the first seven
64
+ action dimensions.
65
+
66
+ The result must have shape `(10, 7)`. Columns are labelled `dx`, `dy`, `dz`,
67
+ `droll`, `dpitch`, `dyaw`, and `gripper`. The UI displays the action table and
68
+ offers a JSON download containing the input instruction, state, seed, artifact
69
+ identity, action labels, and action values.
70
+
71
+ ## Interface
72
+
73
+ The page follows the existing `qwengr00t` Space pattern: artifact controls at
74
+ the top, two image inputs in one row, instruction and state controls below,
75
+ then a primary prediction button, status text, action table, and JSON download.
76
+ It clearly states that predictions do not directly command a robot.
77
+
78
+ The app queues requests with concurrency one to prevent simultaneous access to
79
+ the heavyweight policy. The first-request status explains that model download
80
+ and loading can take several minutes.
81
+
82
+ ## Validation and Error Handling
83
+
84
+ Before model execution, the adapter rejects missing images, blank instructions,
85
+ non-finite or incorrectly sized state vectors, and invalid trial indices.
86
+ Artifact paths must remain relative and cannot contain parent traversal.
87
+
88
+ Model download, initialization, and inference exceptions are caught at the UI
89
+ boundary and rendered as status messages. A failed load is not cached as a
90
+ model. On CUDA failures the app runs garbage collection and empties the CUDA
91
+ cache, while preserving enough error detail for diagnosis.
92
+
93
+ ## Testing
94
+
95
+ CPU-only tests use fake policies and download/load functions. They verify:
96
+
97
+ - Space metadata selects Gradio, Python 3.11, and the correct app entry point;
98
+ - input validation and exact UR observation-key mapping;
99
+ - RGB image conversion and seven-value state ordering;
100
+ - deterministic seed selection;
101
+ - enforcement of the `(10, 7)` action shape;
102
+ - action table and JSON formatting;
103
+ - lazy, keyed, thread-safe model caching and replacement;
104
+ - artifact path validation and actionable load errors; and
105
+ - Gradio component wiring without downloading a checkpoint.
106
+
107
+ A syntax/import smoke test runs locally. Full checkpoint inference is documented
108
+ as an optional GPU smoke test because it requires large external artifacts and
109
+ a compatible CUDA environment.
110
+
111
+ ## Success Criteria
112
+
113
+ The `pi0.5` repository can be pushed directly to a Hugging Face GPU Space. With
114
+ a valid state-conditioned UR checkpoint repository configured, a user can
115
+ upload both camera images, provide the current seven-value UR state and an
116
+ instruction, and download a deterministic ten-by-seven action prediction.