outsider86 commited on
Commit
12f96d0
·
verified ·
1 Parent(s): 3dbae9e

Add NewModel v2 deployment guide

Browse files
NewModel/v2/deployment/README.md ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Policy-server deployment
2
+
3
+ This server exposes every active checkpoint in `outputs/FULL_VISION_512`
4
+ through the same
5
+ msgpack-over-WebSocket envelope used by the previous Piper deployment:
6
+
7
+ - handshake: server metadata is sent immediately after connection;
8
+ - request: `{"type":"infer","request_id":...,"payload":{"examples":[...]}}`;
9
+ - response: `response["data"]["actions"]`, shape `[B,30,7]`, already in
10
+ physical absolute Piper coordinates;
11
+ - realtime request type: `infer_realtime`;
12
+ - transport: WebSocket, compression disabled, NumPy-aware msgpack.
13
+
14
+ The implementation is in `src/robot_policy/deployment`. It loads architecture,
15
+ model size, representation, sampling settings, and normalization from the
16
+ checkpoint itself. An operator does not select a separate model YAML. For the
17
+ versioned Hugging Face package it automatically resolves shared immutable
18
+ sidecars from `NewModel/v2/sidecars/{raw,bspline}`; `--prepared-path` remains
19
+ available for custom layouts.
20
+
21
+ ## Observation and action contract
22
+
23
+ Each example is:
24
+
25
+ ```python
26
+ {
27
+ "image": [global_rgb, hand_rgb], # HWC uint8, exact order
28
+ "state": normalized_state[None, :], # shape [1,7]
29
+ "lang": "Stack the cups.",
30
+ }
31
+ ```
32
+
33
+ The server resizes both RGB images to 224x224 and applies the same frozen
34
+ DINOv2 + SigLIP preprocessing as training. The default `state` contract is the
35
+ legacy Piper client's min/max normalization to `[-1,1]`. The server inverts
36
+ that transform and then applies this codebase's training z-score. Requests can
37
+ instead set `state_coordinates="physical"` or `state_coordinates="zscore"`.
38
+
39
+ The language string is checked because this checkpoint is task-specific, but
40
+ these compact policies were not trained with language tokens. A different
41
+ instruction is rejected rather than silently implying language conditioning.
42
+
43
+ Actions are decoded inside the server:
44
+
45
+ - raw checkpoints: 30x7 normalized actions -> q01/q99 unnormalization;
46
+ - B-spline checkpoints: 18x7 controls -> authoritative smooth cubic 30x18
47
+ basis multiplication -> 30x7 normalized actions -> q01/q99
48
+ unnormalization;
49
+ - the gripper is projected to 0/1 at physical threshold 0.3 by default.
50
+
51
+ ## Start a server
52
+
53
+ From `robot_policy`:
54
+
55
+ ```bash
56
+ export CKPT="$PWD/outputs/FULL_VISION_512/dit_b/bspline/checkpoints/fm_base.pt"
57
+ CUDA_VISIBLE_DEVICES=0 deployment/run_policy_server.sh
58
+ ```
59
+
60
+ Equivalent direct invocation:
61
+
62
+ ```bash
63
+ PYTHONPATH=src /home/wangpc/miniconda3/envs/starVLA/bin/python \
64
+ -m robot_policy.deployment.server \
65
+ --ckpt_path outputs/FULL_VISION_512/dit_b/bspline/checkpoints/fm_base.pt \
66
+ --port 10093 --device cuda --precision bf16
67
+ ```
68
+
69
+ Useful switches are `--no-binary-gripper`, `--gripper-threshold`,
70
+ `--prepared-path`, `--host`, and `--idle-timeout`.
71
+
72
+ Before using the existing Piper live client, export its expected statistics:
73
+
74
+ ```bash
75
+ PYTHONPATH=src /home/wangpc/miniconda3/envs/starVLA/bin/python \
76
+ -m robot_policy.deployment.export_stats \
77
+ --ckpt_path "$CKPT" \
78
+ --output outputs/FULL_VISION_512/summary/deployment/piper_dataset_statistics.json \
79
+ --start-output outputs/FULL_VISION_512/summary/deployment/stacking_cups_start_statistics.json
80
+ ```
81
+
82
+ Pass that JSON as the Piper client's `--stats` file. It deliberately exposes
83
+ the training-episode physical state range for the legacy client transform;
84
+ the server converts the resulting min/max-normalized state to the z-score used
85
+ during this policy's training.
86
+
87
+ Pass the second JSON as `--start-stats`; it contains min/max/median over the
88
+ first physical state of all 52 stacking-cups demonstrations, as required by
89
+ the handoff's guarded start-pose check.
90
+
91
+ ## Base and ttRTC behavior
92
+
93
+ All 16 active checkpoints support ordinary `infer`. An RTC/ttRTC checkpoint also
94
+ supports `infer_realtime`, with a strict representation contract:
95
+
96
+ | Checkpoint | Required previous field | Coordinates | Delay |
97
+ | --- | --- | --- | --- |
98
+ | raw ttRTC | `prev_action_chunk`, `[B,30,7]` | physical robot actions returned by the prior call | 1..10 raw 30 Hz steps |
99
+ | B-spline ttRTC | `prev_control_rows`, `[B,18,7]` | normalized spline controls returned as `normalized_control_rows` by the prior call | 1..10 raw 30 Hz steps |
100
+
101
+ The B-spline endpoint rejects decoded 30x7 actions. A delay of `d` raw steps
102
+ shifts and refits the prior curve, maps to `ceil(d/2)` affected spline spans,
103
+ and preserves `ceil(d/2)+3` cubic-support control rows. It never treats a
104
+ 30 Hz action index as a control-row index.
105
+
106
+ The former Piper async client can be used unchanged for raw ttRTC. It cannot
107
+ be used unchanged for B-spline ttRTC because it discards control rows. Use
108
+ `robot_policy.deployment.PolicyClient`, which retains them:
109
+
110
+ ```python
111
+ from robot_policy.deployment import PolicyClient
112
+
113
+ with PolicyClient("127.0.0.1", 10093) as client:
114
+ first = client.predict_action([example])
115
+ second = client.predict_action_realtime(
116
+ [next_example],
117
+ inference_delay=3,
118
+ previous=first["normalized_control_rows"],
119
+ )
120
+ ```
121
+
122
+ The server is stateless across requests and clients. RTC history is explicit
123
+ in each request, preventing one robot/client from inheriting another client's
124
+ plan.
125
+
126
+ ## Safety and dry-run boundary
127
+
128
+ This package performs inference only. It does not publish robot commands. Keep
129
+ the reference Piper client in dry-run mode until camera order, state units,
130
+ task string, 30 Hz execution, action range, start pose, gripper direction, and
131
+ emergency-stop behavior have been verified. Do not add `--execute` merely
132
+ because server inference succeeds.
133
+
134
+ With the server running, the existing reference live client can be exercised
135
+ without robot commands as follows (there is intentionally no `--execute`):
136
+
137
+ ```bash
138
+ cd /scratch/wangpc/DiscreteRTCv2
139
+ /home/wangpc/miniconda3/envs/starVLA/bin/python \
140
+ examples/realRobots/Piper/eval_files/piper_live_client.py \
141
+ --host 127.0.0.1 --port 10093 \
142
+ --stats /scratch/wangpc/B-Spline-Inpainting/robot_policy/outputs/FULL_VISION_512/summary/deployment/piper_dataset_statistics.json \
143
+ --start-stats /scratch/wangpc/B-Spline-Inpainting/robot_policy/outputs/FULL_VISION_512/summary/deployment/stacking_cups_start_statistics.json \
144
+ --task "Stack the cups." --rate-hz 30 --duration 30 \
145
+ --save-viewer-data
146
+ ```
147
+
148
+ For a raw ttRTC checkpoint, the reference
149
+ `piper_async_training_rtc_client.py` recognizes the advertised
150
+ `rtc_mode=training_time_hard_prefix` and can use `infer_realtime`. The server
151
+ advertises this sweep's trained maximum of 10 raw action steps and never
152
+ silently accepts a larger delay.
153
+
154
+ ## Verification
155
+
156
+ ```bash
157
+ cd /scratch/wangpc/B-Spline-Inpainting/robot_policy
158
+ PYTHONPATH=src /home/wangpc/miniconda3/envs/starVLA/bin/python -m pytest -q
159
+ ```
160
+
161
+ Deployment coverage includes checkpoint-sidecar validation for all 16 active
162
+ files, FM and joint-DD across both representations, both RTC conditioning spaces,
163
+ prefix preservation, invalid-shape/task/delay rejection, NumPy serialization,
164
+ router errors, and a real localhost WebSocket handshake/inference round-trip.
NewModel/v2/deployment/run_policy_server.sh ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ POLICY_PYTHON="${ROBOT_POLICY_PYTHON:-/home/wangpc/miniconda3/envs/starVLA/bin/python}"
6
+ CHECKPOINT="${CKPT:?Set CKPT to a robot_policy .pt checkpoint}"
7
+ PORT="${PORT:-10093}"
8
+ DEVICE="${DEVICE:-cuda}"
9
+ PRECISION="${PRECISION:-bf16}"
10
+
11
+ cd "${PROJECT_ROOT}"
12
+ export PYTHONPATH="${PROJECT_ROOT}/src${PYTHONPATH:+:${PYTHONPATH}}"
13
+
14
+ arguments=(
15
+ -m robot_policy.deployment.server
16
+ --ckpt_path "${CHECKPOINT}"
17
+ --port "${PORT}"
18
+ --device "${DEVICE}"
19
+ --precision "${PRECISION}"
20
+ )
21
+ if [[ -n "${PREPARED_PATH:-}" ]]; then
22
+ arguments+=(--prepared-path "${PREPARED_PATH}")
23
+ fi
24
+ exec "${POLICY_PYTHON}" "${arguments[@]}" "$@"
25
+