26k and fix bpu round
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
- `bpu_policy.py`:BPU policy wrapper,默认使用 `cpp_dnn_api_x5` C++ DNN API 后端。
|
||||
- `cpp/`:C++ DNN API 推理库源码、板端编译脚本和纯 C++ benchmark。
|
||||
- `deploy_go1_robotlab_bpu_x5_fastcpp.py`:基于现有 `lab_fastcpp` 状态机的 BPU 版本。
|
||||
- `deploy_go1_robotlab_bpu_x5_fastcpp.py`:基于现有 `lab_fastcpp` 状态机的 BPU 版本,默认 26000。
|
||||
|
||||
## 重要限制
|
||||
|
||||
@@ -52,7 +52,7 @@ bash build_board.sh
|
||||
默认模型:
|
||||
|
||||
```text
|
||||
deploy_45dim_rl_gym/bpu_quantization/mapper_output_6500_gemm/policy_robotlab_6500_int16_gemm.bin
|
||||
deploy_45dim_rl_gym/bpu_quantization/mapper_output_26000_gemm/policy_robotlab_26000_int16_gemm.bin
|
||||
```
|
||||
|
||||
输入输出:
|
||||
@@ -66,12 +66,12 @@ deploy_45dim_rl_gym/bpu_quantization/mapper_output_6500_gemm/policy_robotlab_650
|
||||
|
||||
```bash
|
||||
cd /root/go1_pro_deploy
|
||||
ls deploy_45dim_rl_gym/bpu_quantization/mapper_output_6500_gemm/policy_robotlab_6500_int16_gemm.bin
|
||||
ls deploy_45dim_rl_gym/bpu_quantization/mapper_output_26000_gemm/policy_robotlab_26000_int16_gemm.bin
|
||||
ls deploy_45dim_rl_gym/bpu_quantization/calibration_data/00000.bin
|
||||
ls deploy_45dim_rl_gym/bpu_deploy_x5/cpp/libbpu_dnn_policy.so
|
||||
```
|
||||
|
||||
如果 `mapper_output_6500_gemm/` 没有同步到 git,需要手动把 `.bin` 放到对应路径,
|
||||
如果 `mapper_output_26000_gemm/` 没有同步到 git,需要手动把 `.bin` 放到对应路径,
|
||||
或用 `--bpu-model` 指定绝对路径。
|
||||
|
||||
## 纯离线 BPU 自检
|
||||
@@ -82,38 +82,32 @@ ls deploy_45dim_rl_gym/bpu_deploy_x5/cpp/libbpu_dnn_policy.so
|
||||
cd /root/go1_pro_deploy
|
||||
PYTHONPATH=/root/go1_pro_deploy \
|
||||
python3 deploy_45dim_rl_gym/bpu_deploy_x5/test_bpu_policy.py \
|
||||
--check-reference-00000 \
|
||||
--bpu-model deploy_45dim_rl_gym/bpu_quantization/mapper_output_26000_gemm/policy_robotlab_26000_int16_gemm.bin \
|
||||
--input-bin deploy_45dim_rl_gym/bpu_quantization/calibration_data_26000_robotlab_fast64/00000.bin \
|
||||
--repeat 1000
|
||||
```
|
||||
|
||||
通过时应看到:
|
||||
|
||||
```text
|
||||
reference_max_abs_diff 0.0
|
||||
```
|
||||
|
||||
当前板端 `root@192.168.150.167` 已验证:
|
||||
|
||||
```text
|
||||
reference_max_abs_diff 4.76837158203125e-07
|
||||
reference_mean_abs_diff 3.071812386679085e-07
|
||||
repeat=1000 avg_ms=1.019592 # Python ctypes -> C++ DNN API
|
||||
duplicate_errors=0
|
||||
repeat=1000 avg_ms=... # Python ctypes -> C++ DNN API
|
||||
```
|
||||
|
||||
纯 C++ benchmark:
|
||||
|
||||
```bash
|
||||
cd /root/go1_pro_deploy/deploy_45dim_rl_gym/bpu_deploy_x5/cpp
|
||||
./bpu_dnn_bench
|
||||
./bpu_dnn_bench \
|
||||
/root/go1_pro_deploy/deploy_45dim_rl_gym/bpu_quantization/mapper_output_26000_gemm/policy_robotlab_26000_int16_gemm.bin \
|
||||
/root/go1_pro_deploy/deploy_45dim_rl_gym/bpu_quantization/calibration_data_26000_robotlab_fast64/00000.bin \
|
||||
1000
|
||||
```
|
||||
|
||||
当前板端结果:
|
||||
|
||||
```text
|
||||
reference_max_abs_diff 0
|
||||
repeat=1000 cpp_avg_ms=0.711932
|
||||
duplicate_errors=0
|
||||
input_floats=450 output_floats=12
|
||||
repeat=1000 cpp_avg_ms=...
|
||||
```
|
||||
|
||||
## 离线推理检查
|
||||
@@ -132,6 +126,18 @@ python3 deploy_45dim_rl_gym/bpu_deploy_x5/deploy_go1_robotlab_bpu_x5_fastcpp.py
|
||||
|
||||
这一步仍会连接 MCU 读取状态,但不会发送电机指令。
|
||||
|
||||
如果要切回旧轮次:
|
||||
|
||||
```bash
|
||||
PYTHONPATH=/root/go1_pro_deploy \
|
||||
python3 deploy_45dim_rl_gym/bpu_deploy_x5/deploy_go1_robotlab_bpu_x5_fastcpp.py \
|
||||
--bpu-round 6500
|
||||
|
||||
PYTHONPATH=/root/go1_pro_deploy \
|
||||
python3 deploy_45dim_rl_gym/bpu_deploy_x5/deploy_go1_robotlab_bpu_x5_fastcpp.py \
|
||||
--bpu-round 15000
|
||||
```
|
||||
|
||||
## 悬空状态机测试
|
||||
|
||||
只有 `--infer-check` 日志确认 action 正常后,再悬空测试状态机。先不加
|
||||
|
||||
@@ -5,7 +5,7 @@ Deploy the RoboGauge Go1 45-dim RobotLab BPU policy on Unitree Go1 PRO.
|
||||
This uses go1_pro_sdk direct MCU control, not LCM or the official Unitree SDK.
|
||||
|
||||
Policy:
|
||||
- policy_robotlab_6500_int16_gemm.bin
|
||||
- policy_robotlab_26000_int16_gemm.bin by default
|
||||
- single-frame obs: 45 dims
|
||||
- BPU input: 10-frame history, 1x1x1x450 featuremap, stacked by observation terms
|
||||
- command scale: [1.0, 1.0, 1.0]
|
||||
@@ -66,10 +66,16 @@ except ImportError as exc:
|
||||
"PYTHONPATH=/root/go1_pro_sdk python3 setup.py build_ext --inplace"
|
||||
) from exc
|
||||
|
||||
DEFAULT_BPU_MODEL = (
|
||||
HERE.parent / "bpu_quantization" / "mapper_output_6500_gemm" /
|
||||
"policy_robotlab_6500_int16_gemm.bin"
|
||||
)
|
||||
BPU_MODEL_REGISTRY = {
|
||||
"6500": HERE.parent / "bpu_quantization" / "mapper_output_6500_gemm" /
|
||||
"policy_robotlab_6500_int16_gemm.bin",
|
||||
"15000": HERE.parent / "bpu_quantization" / "mapper_output_gemm" /
|
||||
"policy_robotlab_15000_int16_gemm.bin",
|
||||
"26000": HERE.parent / "bpu_quantization" / "mapper_output_26000_gemm" /
|
||||
"policy_robotlab_26000_int16_gemm.bin",
|
||||
}
|
||||
DEFAULT_BPU_ROUND = "26000"
|
||||
DEFAULT_BPU_MODEL = BPU_MODEL_REGISTRY[DEFAULT_BPU_ROUND]
|
||||
LOWCMD_BACKEND = "cpp_lowcmd_cpp_lowstate"
|
||||
SPORT_KILL_CMD = (
|
||||
'ssh pi@192.168.123.161 "sudo pkill -9 -f keep_sport_alive; '
|
||||
@@ -217,6 +223,38 @@ def validate_joint_order():
|
||||
print(f" [{i:02d}] {sdk_name:4s} -> {policy_name:8s} default={q0:+.3f}")
|
||||
|
||||
|
||||
def resolve_bpu_model(args):
|
||||
if args.bpu_model:
|
||||
return Path(args.bpu_model).expanduser().resolve()
|
||||
key = str(args.bpu_round)
|
||||
if key not in BPU_MODEL_REGISTRY:
|
||||
choices = ", ".join(sorted(BPU_MODEL_REGISTRY))
|
||||
raise ValueError(f"Unknown --bpu-round {args.bpu_round!r}; choices: {choices}")
|
||||
return BPU_MODEL_REGISTRY[key].expanduser().resolve()
|
||||
|
||||
|
||||
def make_policy(args):
|
||||
model_path = resolve_bpu_model(args)
|
||||
policy = BpuInferLibPolicy(
|
||||
model_path,
|
||||
priority=args.bpu_priority,
|
||||
bpu_cores=args.bpu_cores,
|
||||
)
|
||||
if policy.input_size != POLICY_INPUT_DIM:
|
||||
policy.close()
|
||||
raise ValueError(
|
||||
f"BPU model input has {policy.input_size} values, expected {POLICY_INPUT_DIM}. "
|
||||
"Use a RobotLab 10-frame/450-dim .bin."
|
||||
)
|
||||
if policy.output_size != NUM_ACTIONS:
|
||||
policy.close()
|
||||
raise ValueError(
|
||||
f"BPU model output has {policy.output_size} values, expected exactly {NUM_ACTIONS}. "
|
||||
"Compile an actions-only ONNX for deployment."
|
||||
)
|
||||
return policy
|
||||
|
||||
|
||||
def apply_deadzone(value, deadzone):
|
||||
if deadzone <= 0.0:
|
||||
return float(value)
|
||||
@@ -346,7 +384,8 @@ class JsonlLogger:
|
||||
"num_obs": NUM_OBS,
|
||||
"history_len": HISTORY_LEN,
|
||||
"policy_backend": BpuInferLibPolicy.backend_name,
|
||||
"bpu_model": str(Path(args.bpu_model).expanduser()),
|
||||
"bpu_model": str(resolve_bpu_model(args)),
|
||||
"bpu_round": args.bpu_round,
|
||||
"policy_input_dim": POLICY_INPUT_DIM,
|
||||
"bpu_input_shape": BPU_INPUT_SHAPE,
|
||||
"bpu_output_shape": BPU_OUTPUT_SHAPE,
|
||||
@@ -750,7 +789,7 @@ def run_infer_check(args):
|
||||
logger = JsonlLogger(args.log_dir, args)
|
||||
client = None
|
||||
try:
|
||||
policy = BpuInferLibPolicy(args.bpu_model, priority=args.bpu_priority, bpu_cores=args.bpu_cores)
|
||||
policy = make_policy(args)
|
||||
client, state = connect_client(args)
|
||||
obs_builder = ObsHistoryBuilder()
|
||||
cmd_filter = CommandFilter(args)
|
||||
@@ -845,7 +884,7 @@ def run_deploy(args):
|
||||
print(STARTUP_BANNER)
|
||||
input("Press Enter when ready...")
|
||||
|
||||
policy = BpuInferLibPolicy(args.bpu_model, priority=args.bpu_priority, bpu_cores=args.bpu_cores)
|
||||
policy = make_policy(args)
|
||||
logger = JsonlLogger(args.log_dir, args)
|
||||
client = None
|
||||
state = None
|
||||
@@ -1162,8 +1201,11 @@ def run_deploy(args):
|
||||
|
||||
def build_arg_parser():
|
||||
parser = argparse.ArgumentParser(description="Deploy RoboGauge Go1 RobotLab BPU on Go1 PRO")
|
||||
parser.add_argument("--bpu-model", default=str(DEFAULT_BPU_MODEL),
|
||||
help="Path to policy_robotlab_6500_int16_gemm.bin")
|
||||
parser.add_argument("--bpu-model", default="",
|
||||
help="Path to a compiled RobotLab 10-frame BPU .bin; overrides --bpu-round")
|
||||
parser.add_argument("--bpu-round", default=DEFAULT_BPU_ROUND,
|
||||
choices=sorted(BPU_MODEL_REGISTRY),
|
||||
help="Quick-select RobotLab BPU model round")
|
||||
parser.add_argument("--bpu-priority", type=int, default=0)
|
||||
parser.add_argument("--bpu-cores", type=int, nargs="+", default=[0],
|
||||
help="Reserved BPU core ids for future runtime scheduling")
|
||||
|
||||
Reference in New Issue
Block a user