Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- nix/lib/runtime.nixAdded+74
- nix/runtime-base.nixAdded+49
- nix/runtime-host-gpu.nixAdded+101
- nix/runtime.nixAdded+14
- scripts/deepspeed/zero2.jsonAdded+23
- scripts/deepspeed/zero3.jsonAdded+29
- scripts/deepspeed/zero3_offload.jsonAdded+56
- scripts/infer/multiturn_auto_scenario_backchannel_train_v1.jsonAdded+48
- scripts/infer/multiturn_auto_scenario_backchannel_val_v1.jsonAdded+48
- scripts/infer/multiturn_auto_scenario_emergency_stop_train_v1.jsonAdded+48
- scripts/infer/multiturn_auto_scenario_emergency_stop_val_v1.jsonAdded+40
- scripts/infer/multiturn_auto_scenario_hesitation_filled_train_v2.jsonAdded+60
- scripts/infer/multiturn_auto_scenario_hesitation_filled_val_v2.jsonAdded+60
- scripts/infer/multiturn_auto_scenario_hesitation_repair_train_v1.jsonAdded+42
- scripts/infer/multiturn_auto_scenario_hesitation_repair_train_v2.jsonAdded+63
- scripts/infer/multiturn_auto_scenario_hesitation_repair_val_v1.jsonAdded+42
- scripts/infer/multiturn_auto_scenario_hesitation_repair_val_v2.jsonAdded+62
- scripts/infer/multiturn_auto_scenario_interruption_train_v1.jsonAdded+60
- scripts/infer/multiturn_auto_scenario_pause_train_v1.jsonAdded+41
- scripts/infer/multiturn_auto_scenario_pause_train_v2.jsonAdded+60
- scripts/infer/multiturn_auto_scenario_safe_hold_val_v1.jsonAdded+40
- scripts/infer/multiturn_auto_scenario_v1.jsonAdded+61
- scripts/infer/multiturn_auto_scenario_val_v1.jsonAdded+100
- scripts/infer/multiturn_auto_suite_v2.jsonAdded+92
- scripts/infer/multiturn_auto_suite_v3.jsonAdded+92
- scripts/infer/mux_full_duplex_audio.pyAdded+180
- scripts/infer/render_third_party_review.pyAdded+287
- scripts/infer/render_third_party_scale.pyAdded+151
- scripts/infer/run_multiturn_infer_suite.pyAdded+700
- scripts/infer/seed_audio_to_motion.pyAdded+530
- scripts/infer/seed_motion_teacher_reconstruct.pyAdded+504
- scripts/infer/seed_text_to_motion.pyAdded+873
- scripts/infer/seed_video_to_motion.pyAdded+548
- scripts/infer/third_party_checkpoint_probe.pyAdded+434
- scripts/infer/third_party_scale_metrics.pyAdded+172
- src/InternVLA-M1/InternVLA/__init__.pyAdded
- src/InternVLA-M1/InternVLA/config/deepseeds/deepspeed_zero2.yamlAdded+10
- src/InternVLA-M1/InternVLA/config/deepseeds/ds_config.yamlAdded+28
- src/InternVLA-M1/InternVLA/config/deepseeds/zero2.yamlAdded+21
- src/InternVLA-M1/InternVLA/config/deepseeds/zero3.jsonAdded+28
- src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_custom.yamlAdded+126
- src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_humanoid.yamlAdded+128
- src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_libero.yamlAdded+126
- src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_oxe.yamlAdded+100
- src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_sim_demo.yamlAdded+124
- src/InternVLA-M1/InternVLA/dataloader/__init__.pyAdded+63
- src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/README.mdAdded
- src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/__init__.pyAdded
- src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/data_config.pyAdded+770
- src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/datasets.pyAdded+2118
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374{ lib, pkgs }:
let exportEnv = env: lib.concatStringsSep "\n" ( lib.mapAttrsToList (name: value: "export ${name}=${lib.escapeShellArg value}") env );
prependEnv = env: lib.concatStringsSep "\n" ( lib.mapAttrsToList ( name: value: '' _runtime_current_value="$(printenv ${name} || true)" if [ -n "$_runtime_current_value" ]; then export ${name}=${lib.escapeShellArg value}:"$_runtime_current_value" else export ${name}=${lib.escapeShellArg value} fi unset _runtime_current_value '' ) env );
mergeStringAttrs = runtimes: key: lib.foldl' ( acc: runtime: let current = runtime.${key} or { }; in acc // lib.mapAttrs ( name: value: if builtins.hasAttr name acc then "${value}:${builtins.getAttr name acc}" else value ) current ) { } runtimes;
mergeRuntimes = runtimes: { packages = lib.unique (lib.concatMap (runtime: runtime.packages or [ ]) runtimes); env = lib.foldl' (acc: runtime: acc // (runtime.env or { })) { } runtimes; prependEnv = mergeStringAttrs runtimes "prependEnv"; shellHook = lib.concatStringsSep "\n\n" ( lib.filter (chunk: chunk != "") (map (runtime: runtime.shellHook or "") runtimes) ); };
mkRuntimeShell = { name, runtimes, extraPackages ? [ ], extraShellHook ? "", stdenv ? null, }: let runtime = mergeRuntimes runtimes; shellHook = lib.concatStringsSep "\n\n" ( [ (exportEnv (runtime.env or { })) (prependEnv (runtime.prependEnv or { })) (runtime.shellHook or "") extraShellHook '' echo "${name} shell ready" '' ] ); in pkgs.mkShell ({ packages = lib.unique (extraPackages ++ runtime.packages); inherit shellHook; } // lib.optionalAttrs (stdenv != null) { inherit stdenv; });in{ inherit exportEnv prependEnv mergeRuntimes mkRuntimeShell;}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849{ pkgs }:
let cuda = pkgs.cudaPackages_12_8.cudatoolkit; gcc = pkgs.gcc13; ffmpeg = pkgs.ffmpeg_7; ffmpegLib = ffmpeg.lib; caBundle = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";in{ packages = [ pkgs.cmake pkgs.ninja pkgs.pkg-config gcc pkgs.cacert pkgs.linuxHeaders ffmpeg cuda ];
env = { CUDA_HOME = "${cuda}"; CUDA_PATH = "${cuda}"; CUDACXX = "${cuda}/bin/nvcc"; CUDAHOSTCXX = "${gcc}/bin/g++"; CC = "${gcc}/bin/gcc"; CXX = "${gcc}/bin/g++"; CMAKE_CUDA_HOST_COMPILER = "${gcc}/bin/gcc"; NVCC_PREPEND_FLAGS = "-ccbin ${gcc}/bin/gcc"; SSL_CERT_FILE = caBundle; NIX_SSL_CERT_FILE = caBundle; REQUESTS_CA_BUNDLE = caBundle; CURL_CA_BUNDLE = caBundle; GIT_SSL_CAINFO = caBundle; };
prependEnv = { PATH = "${ffmpeg}/bin"; CPATH = "${pkgs.linuxHeaders}/include:${cuda}/include"; LIBRARY_PATH = "${cuda}/lib64:${cuda}/lib"; LD_LIBRARY_PATH = "${ffmpegLib}/lib:${cuda}/lib64:${cuda}/lib:${pkgs.stdenv.cc.cc.lib}/lib"; };
shellHook = '' export CFLAGS="-I${pkgs.linuxHeaders}/include ''${CFLAGS:-}" export CXXFLAGS="-I${pkgs.linuxHeaders}/include ''${CXXFLAGS:-}" '';}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101{ pkgs }:
{ shellHook = '' _runtime_detect_and_prepend() { _runtime_var_name="$1" shift _runtime_joined_paths="" for _runtime_path in "$@"; do if [ -e "$_runtime_path" ]; then if [ -n "$_runtime_joined_paths" ]; then _runtime_joined_paths="$_runtime_joined_paths:$_runtime_path" else _runtime_joined_paths="$_runtime_path" fi fi done
if [ -n "$_runtime_joined_paths" ]; then eval "_runtime_current_value=\''${$_runtime_var_name}" if [ -n "$_runtime_current_value" ]; then export "$_runtime_var_name=$_runtime_joined_paths:$_runtime_current_value" else export "$_runtime_var_name=$_runtime_joined_paths" fi unset _runtime_current_value fi
unset _runtime_joined_paths unset _runtime_var_name unset _runtime_path }
if [ -z "''${VK_ICD_FILENAMES:-}" ]; then for _runtime_vk_icd in \ /run/opengl-driver/share/vulkan/icd.d/nvidia_icd.x86_64.json \ /usr/share/vulkan/icd.d/nvidia_icd.json \ /usr/share/vulkan/icd.d/nvidia_icd.x86_64.json \ /etc/vulkan/icd.d/nvidia_icd.json do if [ -f "$_runtime_vk_icd" ]; then export VK_ICD_FILENAMES="$_runtime_vk_icd" break fi done unset _runtime_vk_icd fi
if [ -z "''${__EGL_VENDOR_LIBRARY_FILENAMES:-}" ]; then for _runtime_egl_vendor in \ /run/opengl-driver/share/glvnd/egl_vendor.d/10_nvidia.json \ /usr/share/glvnd/egl_vendor.d/10_nvidia.json \ /usr/share/glvnd/egl_vendor.d/50_nvidia.json do if [ -f "$_runtime_egl_vendor" ]; then export __EGL_VENDOR_LIBRARY_FILENAMES="$_runtime_egl_vendor" break fi done unset _runtime_egl_vendor fi
_runtime_detect_and_prepend LD_LIBRARY_PATH \ /run/opengl-driver/lib \ /run/opengl-driver-32/lib \ /usr/lib/x86_64-linux-gnu/nvidia/current \ /usr/lib/x86_64-linux-gnu/nvidia \ /usr/lib/nvidia \ /usr/lib/nvidia-570 \ /usr/lib/nvidia-575 \ /usr/lib/nvidia-580 \ /usr/lib/nvidia-590 \ /usr/lib/wsl/lib
_runtime_detect_and_prepend XDG_DATA_DIRS \ /run/opengl-driver/share \ /usr/share
if [ -z "''${TRITON_LIBCUDA_PATH:-}" ]; then for _runtime_triton_cuda in \ /run/opengl-driver/lib \ /usr/lib/x86_64-linux-gnu \ /usr/lib/x86_64-linux-gnu/nvidia/current \ /usr/lib/x86_64-linux-gnu/nvidia \ /usr/lib/nvidia-590 \ /usr/lib/nvidia-580 \ /usr/lib/nvidia-575 \ /usr/lib/nvidia-570 \ /usr/lib/wsl/lib do if [ -d "$_runtime_triton_cuda" ]; then export TRITON_LIBCUDA_PATH="$_runtime_triton_cuda" break fi done unset _runtime_triton_cuda fi
unset -f _runtime_detect_and_prepend '';}1234567891011121314{ pkgs }:
let runtimeLib = import ./lib/runtime.nix { lib = pkgs.lib; inherit pkgs; }; baseRuntime = import ./runtime-base.nix { inherit pkgs; }; hostGpuRuntime = import ./runtime-host-gpu.nix { inherit pkgs; };inruntimeLib.mergeRuntimes [ baseRuntime hostGpuRuntime]1234567891011121314151617181920212223{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "train_micro_batch_size_per_gpu": "auto", "train_batch_size": "auto", "gradient_accumulation_steps": "auto", "zero_optimization": { "stage": 2, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto" }}1234567891011121314151617181920212223242526272829{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "train_micro_batch_size_per_gpu": "auto", "train_batch_size": "auto", "gradient_accumulation_steps": "auto", "gradient_clipping": 1.0, "zero_optimization": { "stage": 3, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 1e9, "stage3_max_reuse_distance": 1e9, "stage3_gather_16bit_weights_on_model_save": true }}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "optimizer": { "type": "AdamW", "params": { "lr": "auto", "betas": "auto", "eps": "auto", "weight_decay": "auto" } }, "scheduler": { "type": "WarmupLR", "params": { "warmup_min_lr": "auto", "warmup_max_lr": "auto", "warmup_num_steps": "auto" } }, "zero_optimization": { "stage": 3, "offload_optimizer": { "device": "cpu", "pin_memory": true }, "offload_param": { "device": "cpu", "pin_memory": true }, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 1e9, "stage3_max_reuse_distance": 1e9, "gather_16bit_weights_on_model_save": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "steps_per_print": 1e5, "wall_clock_breakdown": false}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "backchannel_grab_mmhmm_wave_zh", "interaction_mode": "backchannel", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "第一条动作执行中插入同音色的训练集短反馈“嗯嗯”,动作必须继续;随后再给一条真正的新指令。", "required_semantics_version": 22, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [10, 15], "inter_turn_background_seconds_by_turn": [4.0, 6.0], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "turns": [ { "turn_index": 1, "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000006/female_01_zh.wav", "spoken_command": "向前走并抓取某物", "ideal_motion": "听完后向前走并抓取,动作持续执行。" }, { "turn_index": 2, "backchannel_intent": "continuer", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_backchannel_commands_v2_short/audio/train/bc_cont_01/female_01_zh.wav", "spoken_command": "嗯嗯", "ideal_motion": "这是短反馈而不是新指令;控制持续输出 </motion>,抓取动作的相位、RTC 和 future progress 均连续,不进入 listen 或 idle。" }, { "turn_index": 3, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "这是真正的新指令,模型才应进入 listen,随后从当前状态执行双手挥动。" } ], "ideal_control_timeline": [ "第一条动作指令遵循 idle→listen→motion", "动作中听到“嗯嗯”仍保持 motion,不重置动作相位", "后续真正的新指令到来后才从 motion 切到 listen,再进入新 motion", "末尾纯背景回到 idle" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "backchannel_jog_indeed_pick_en", "interaction_mode": "backchannel", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "未见过的验证动作与验证短反馈组合;检查 backchannel 的语义泛化,而不是记住固定词。", "required_semantics_version": 22, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [9, 16], "inter_turn_background_seconds_by_turn": [3.6, 6.4], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "turns": [ { "turn_index": 1, "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000175/female_02_en.wav", "spoken_command": "start jog forward", "ideal_motion": "听完后向前慢跑,并保持连续闭环状态。" }, { "turn_index": 2, "backchannel_intent": "continuer", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_backchannel_commands_v2_short/audio/val/bc_cont_11/female_02_en.wav", "spoken_command": "Indeed.", "ideal_motion": "验证集短反馈不应抢占控制权;慢跑动作、RTC、进度和 Qwen KV 均连续。" }, { "turn_index": 3, "source_motion_filename": "medium_big_light_two_hands_right_side_low_to_right_side_high_R_001__A529", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000227/female_02_en.wav", "spoken_command": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "ideal_motion": "真正的新指令到来后才切入 listen,随后平滑执行右侧双手取放动作。" } ], "ideal_control_timeline": [ "初始背景输出 idle,第一条动作指令进入 listen 后执行 motion", "未见过的短反馈期间持续输出 motion,不出现假 interruption", "下一条真实指令出现后才切换 listen 和新 motion", "最后在背景中回到 idle" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "stop_train_grab_stop_wave_zh", "interaction_mode": "emergency-stop", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "训练集抓取行走执行中收到中文急停,停住并保持两秒背景后再接挥手指令,检查控制后的恢复交互。", "required_semantics_version": 21, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [8, 5], "inter_turn_background_seconds_by_turn": [3.2, 2.0], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "turns": [ { "turn_index": 1, "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000006/female_01_zh.wav", "spoken_command": "向前走并抓取某物", "ideal_motion": "听完后向前行走并开始抓取。" }, { "turn_index": 2, "control_intent": "emergency-stop", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_control_commands_v1/audio/emergency-stop/stop_02/female_01_zh.wav", "spoken_command": "马上停下来", "ideal_motion": "完整听到急停后直接从 motion 切到 idle,平滑停住,不出现 listen。" }, { "turn_index": 3, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "急停后保持约两秒,再正常进入 listen 并执行双手挥动。" } ], "ideal_control_timeline": [ "初始背景为 </idle>,第一条动作指令期间为 </listen>", "执行 </motion> 约 3.2 秒后收到急停语音", "急停语音未听完前仍是 </motion>,听完后直接转 </idle>", "保持约两秒连续背景后接收新指令,重新进入 </listen> → </motion>" ]}12345678910111213141516171819202122232425262728293031323334353637383940{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "stop_val_jog_en", "interaction_mode": "emergency-stop", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "未见过的慢跑 motion 执行中收到英文急停,检查特殊指令的泛化。", "required_semantics_version": 21, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [9], "inter_turn_background_seconds_by_turn": [3.6], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "turns": [ { "turn_index": 1, "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000175/female_02_en.wav", "spoken_command": "start jog forward", "ideal_motion": "开始向前慢跑。" }, { "turn_index": 2, "control_intent": "emergency-stop", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_control_commands_v1/audio/emergency-stop/stop_02/female_02_en.wav", "spoken_command": "Stop now.", "ideal_motion": "完整听到 stop 后直接平滑停住,不进入 listen。" } ], "ideal_control_timeline": [ "idle -> listen -> motion", "急停语音在 motion 中到来", "听清后 motion -> idle,中间没有 listen" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "filled_wave_then_left_zh", "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "训练集中文指令中插入同音色、自然拖长的“呃……”,实际不确定区间为 2.4 秒,最终意图不变。", "required_semantics_version": 24, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25 ], "inter_turn_background_seconds_by_turn": [ 10.0 ], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "disfluency_event": { "turn_index": 0, "subtype": "filled-pause", "gap_steps": 6, "gap_seconds": 2.4, "marker_id": "hes_fill_zh_02" }, "turns": [ { "turn_index": 1, "disfluency_subtype": "filled-pause", "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v2/audio/review_examples/train/filled_wave_zh_female_01_zh.wav", "spoken_command": "双手在身前……呃……挥动", "final_instruction": "双手在身前挥动", "ideal_motion": "听到呃时继续 listen,不提前抬手;完整指令结束后再完成双手挥动。" }, { "turn_index": 2, "source_motion_filename": "neutral_walk_ff_270_R_001__A534_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000120/female_01_zh.wav", "spoken_command": "向左走路", "ideal_motion": "随后相对当前朝向向左走。" } ], "ideal_control_timeline": [ "背景 idle", "前半句、呃和后半句均为 listen", "只有最终意图完整后才进入 motion", "第二轮正常执行" ], "continuity_requirements": [ "同一女性音色和语言", "同一 Qwen KV 与连续背景", "RTC 和动作相位不在犹豫处重置" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "filled_pick_then_jog_en", "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "验证集英文长指令中插入未用于训练的同音色、自然拖长的 Hmm,检查长语义在 KV 中继续累积。", "required_semantics_version": 24, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25 ], "inter_turn_background_seconds_by_turn": [ 10.0 ], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "disfluency_event": { "turn_index": 0, "subtype": "filled-pause", "gap_steps": 5, "gap_seconds": 2.0, "marker_id": "hes_fill_en_11" }, "turns": [ { "turn_index": 1, "disfluency_subtype": "filled-pause", "source_motion_filename": "medium_big_light_two_hands_right_side_low_to_right_side_high_R_001__A529", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v2/audio/review_examples/val/filled_pick_en_female_02_en.wav", "spoken_command": "picks up ... from low ... Hmm ... right side and puts it away to the right side high", "final_instruction": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "ideal_motion": "Hmm 前后都保持 listen,完整结束后才执行右下到右上的双手取放。" }, { "turn_index": 2, "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000175/female_02_en.wav", "spoken_command": "start jog forward", "ideal_motion": "随后从当前状态向前慢跑。" } ], "ideal_control_timeline": [ "初始 idle", "整条含 Hmm 的未完成指令保持 listen", "完整语义后进入 motion", "第二轮正常执行" ], "continuity_requirements": [ "验证 marker 与训练 marker 含义拆分", "同一音色、KV、背景和 RTC", "两条 motion source 均属于 val" ]}123456789101112131415161718192021222324252627282930313233343536373839404142{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "repair_grab_to_left_then_wave_zh", "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "先说出抓取指令的不完整前缀,再用同音色明确改口为完整向左走;只能执行最终指令。", "required_semantics_version": 23, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [25], "inter_turn_background_seconds_by_turn": [10.0], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "disfluency_event": {"turn_index": 0, "subtype": "self-repair", "gap_steps": 7, "gap_seconds": 2.8, "marker_id": "repair_zh_01"}, "turns": [ { "turn_index": 1, "disfluency_subtype": "self-repair", "source_motion_filename": "neutral_walk_ff_270_R_001__A534_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v1/audio/review_examples/train/repair_grab_to_left_zh_female_01_zh.wav", "spoken_command": "向前……不对,我是说……向左走路", "provisional_instruction": "向前走并抓取某物", "final_instruction": "向左走路", "ideal_motion": "整个改口过程只 listen;不得向前抓取,最终只相对当前朝向向左走。" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "第二轮正常挥手,验证最终意图替换没有破坏后续交互。" } ], "ideal_control_timeline": ["初始 idle", "错误前缀、改口词和完整新指令全程 listen", "只在完整最终指令后进入 motion", "不为错误前缀启动 motion"], "continuity_requirements": ["旧意图与最终意图共用同一 Qwen KV,不靠清缓存作弊", "同一音色和背景", "动作与 RTC 只从最终意图开始"]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "repair_grab_to_left_then_wave_zh", "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "先说出抓取指令的不完整前缀,再用同音色明确改口为完整向左走;只能执行最终指令。", "required_semantics_version": 24, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25 ], "inter_turn_background_seconds_by_turn": [ 10.0 ], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "disfluency_event": { "turn_index": 0, "subtype": "self-repair", "gap_steps": 7, "gap_seconds": 2.8, "marker_id": "repair_zh_01", "repair_style": "explicit-cue" }, "turns": [ { "turn_index": 1, "disfluency_subtype": "self-repair", "source_motion_filename": "neutral_walk_ff_270_R_001__A534_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v2/audio/review_examples/train/repair_grab_to_left_zh_female_01_zh.wav", "spoken_command": "向前……不对,我是说……向左走路", "provisional_instruction": "向前走并抓取某物", "final_instruction": "向左走路", "ideal_motion": "整个改口过程只 listen;不得向前抓取,最终只相对当前朝向向左走。", "repair_style": "explicit-cue" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "第二轮正常挥手,验证最终意图替换没有破坏后续交互。" } ], "ideal_control_timeline": [ "初始 idle", "错误前缀、改口词和完整新指令全程 listen", "只在完整最终指令后进入 motion", "不为错误前缀启动 motion" ], "continuity_requirements": [ "旧意图与最终意图共用同一 Qwen KV,不靠清缓存作弊", "同一音色和背景", "动作与 RTC 只从最终意图开始" ]}123456789101112131415161718192021222324252627282930313233343536373839404142{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "repair_pick_to_jog_then_pick_en", "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "未见 motion 上先说搬运长指令的错误前缀,再用验证集 cue 改口为完整向前慢跑。", "required_semantics_version": 23, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [25], "inter_turn_background_seconds_by_turn": [10.0], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "disfluency_event": {"turn_index": 0, "subtype": "self-repair", "gap_steps": 7, "gap_seconds": 2.8, "marker_id": "repair_en_11"}, "turns": [ { "turn_index": 1, "disfluency_subtype": "self-repair", "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v1/audio/review_examples/val/repair_pick_to_jog_en_female_02_en.wav", "spoken_command": "picks up ... Wait, I mean ... start jog forward", "provisional_instruction": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "final_instruction": "start jog forward", "ideal_motion": "不得执行搬运;完整听完 start jog forward 后才向前慢跑。" }, { "turn_index": 2, "source_motion_filename": "medium_big_light_two_hands_right_side_low_to_right_side_high_R_001__A529", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000227/female_02_en.wav", "spoken_command": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "ideal_motion": "只有第二轮真正完整重发搬运指令时,才执行右侧双手取放。" } ], "ideal_control_timeline": ["初始 idle", "假开头、Wait I mean 和完整最终指令全程 listen", "第一轮只执行 jog", "第二轮完整指令后才执行 pick"], "continuity_requirements": ["验证 cue 与训练 cue 词面分离", "Qwen KV 保留旧指令但最新完整意图应覆盖它", "两条动作与同一声音身份均保持 val 审计"]}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "repair_pick_to_jog_then_pick_en", "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "未见 motion 上先说搬运长指令的错误前缀,停顿后不使用 I mean 等提示词,直接重新说完整向前慢跑指令。", "required_semantics_version": 24, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25 ], "inter_turn_background_seconds_by_turn": [ 10.0 ], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "disfluency_event": { "turn_index": 0, "subtype": "self-repair", "gap_steps": 7, "gap_seconds": 2.8, "repair_style": "implicit-restart" }, "turns": [ { "turn_index": 1, "disfluency_subtype": "self-repair", "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v2/audio/review_examples/val/repair_pick_to_jog_en_female_02_en.wav", "spoken_command": "picks up ... (2.8 s pause) ... start jog forward", "provisional_instruction": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "final_instruction": "start jog forward", "ideal_motion": "没有改口提示词也不得执行搬运;完整听完 start jog forward 后才向前慢跑。", "repair_style": "implicit-restart" }, { "turn_index": 2, "source_motion_filename": "medium_big_light_two_hands_right_side_low_to_right_side_high_R_001__A529", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000227/female_02_en.wav", "spoken_command": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "ideal_motion": "只有第二轮真正完整重发搬运指令时,才执行右侧双手取放。" } ], "ideal_control_timeline": [ "初始 idle", "错误开头、停顿和重新开始的完整最终指令全程 listen", "第一轮只执行 jog", "第二轮完整指令后才执行 pick" ], "continuity_requirements": [ "不依赖 I mean 等关键词判断改口", "Qwen KV 保留旧指令但最新完整意图应覆盖它", "两条动作与同一声音身份均保持 val 审计" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "interrupt_grab_wave_walk_left_zh", "interaction_mode": "interruption", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "三轮训练集指令;第二、三条语音分别在上一动作开始约 4.0/4.8 秒后到来,用于检查因果打断、连续 KV 和连续 RTC。", "required_semantics_version": 20, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 10, 12 ], "inter_turn_background_seconds_by_turn": [ 4.0, 4.8 ], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "turns": [ { "turn_index": 1, "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000006/female_01_zh.wav", "spoken_command": "向前走并抓取某物", "ideal_motion": "听完后开始向前走并抓取;动作尚未结束时收到下一条指令。" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "新语音刚出现时短暂延续旧动作,听清后平滑切入 listen,再从当时真实姿态开始挥手。" }, { "turn_index": 3, "source_motion_filename": "neutral_walk_ff_270_R_001__A534_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000120/female_01_zh.wav", "spoken_command": "向左走路", "ideal_motion": "挥手尚未自然结束时响应新语音,随后相对当前身体朝向向左行走并最终恢复站立。" } ], "ideal_control_timeline": [ "初始背景输出 </idle>,第一条语音出现后进入 </listen>", "每次新语音刚开始时仍执行上一轮 </motion>,不提前读取未来语义", "听到有效语音后由 </motion> 平滑切到 </listen>", "语音结束后进入新的 </motion>,最后回到 </idle>" ], "continuity_requirements": [ "三轮共用一个 Qwen KV cache 和一段连续办公室背景", "打断不清空机器人状态或 RTC 历史", "新动作从旧动作被打断时的真实位置、朝向和关节状态接续", "旧动作的 future progress 仍以其原始完整时长为分母" ]}1234567891011121314151617181920212223242526272829303132333435363738394041{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "pause_grab_then_wave_zh", "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "训练集中文指令在句中静默 1.6 秒;停顿期间继续 listen,完整意图结束后才抓取,随后正常接收第二轮指令。", "required_semantics_version": 23, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [25], "inter_turn_background_seconds_by_turn": [10.0], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "disfluency_event": {"turn_index": 0, "subtype": "silent-pause", "gap_steps": 4, "gap_seconds": 1.6}, "turns": [ { "turn_index": 1, "disfluency_subtype": "silent-pause", "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v1/audio/review_examples/train/pause_grab_zh_female_01_zh.wav", "spoken_command": "向前……(静默思考 1.6 秒)……走并抓取某物", "final_instruction": "向前走并抓取某物", "ideal_motion": "静默段全程保持自然聆听,不提前走;听到完整后向前走并抓取。" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "从第一轮结束状态自然进入第二轮双手挥动。" } ], "ideal_control_timeline": ["背景为 idle", "语音开始后进入 listen", "句中静默仍保持 listen", "完整指令结束后进入 motion", "下一条完整指令按普通 turn-taking 执行"], "continuity_requirements": ["整段 session 只使用一个 Qwen KV", "同一连续办公室背景", "RTC、位置和朝向不在停顿或轮次边界重置"]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "pause_grab_then_wave_zh", "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "训练集中文指令在句中静默 1.6 秒;停顿期间继续 listen,完整意图结束后才抓取,随后正常接收第二轮指令。", "required_semantics_version": 24, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25 ], "inter_turn_background_seconds_by_turn": [ 10.0 ], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "disfluency_event": { "turn_index": 0, "subtype": "silent-pause", "gap_steps": 4, "gap_seconds": 1.6 }, "turns": [ { "turn_index": 1, "disfluency_subtype": "silent-pause", "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_hesitation_pause_v2/audio/review_examples/train/pause_grab_zh_female_01_zh.wav", "spoken_command": "向前……(静默思考 1.6 秒)……走并抓取某物", "final_instruction": "向前走并抓取某物", "ideal_motion": "静默段全程保持自然聆听,不提前走;听到完整后向前走并抓取。" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "从第一轮结束状态自然进入第二轮双手挥动。" } ], "ideal_control_timeline": [ "背景为 idle", "语音开始后进入 listen", "句中静默仍保持 listen", "完整指令结束后进入 motion", "下一条完整指令按普通 turn-taking 执行" ], "continuity_requirements": [ "整段 session 只使用一个 Qwen KV", "同一连续办公室背景", "RTC、位置和朝向不在停顿或轮次边界重置" ]}12345678910111213141516171819202122232425262728293031323334353637383940{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "hold_val_jump_en", "interaction_mode": "safe-hold", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "未见过的跳跃 motion 中收到保持不动,检查是否先落地稳定再保持。", "required_semantics_version": 21, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [7], "inter_turn_background_seconds_by_turn": [2.8], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "turns": [ { "turn_index": 1, "source_motion_filename": "reach_jump_R_003__A148_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000243/female_02_en.wav", "spoken_command": "reaching something during jump", "ideal_motion": "起跳并在空中伸手。" }, { "turn_index": 2, "control_intent": "safe-hold", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/yetinghong/videogen/hfd_control_commands_v1/audio/safe-hold/hold_06/female_02_en.wav", "spoken_command": "Stay balanced and don't move.", "ideal_motion": "如果正在腾空或落地中则先完成安全落地,然后保持真实稳定姿态,不回零到预设 idle。" } ], "ideal_control_timeline": [ "idle -> listen -> motion", "hold 语音在 motion 中到来,没有 listen", "不稳定时保持 motion,稳定后转 idle 并保持当时姿" ]}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "grab_wave_walk_left_zh", "interaction_mode": "turn-taking", "data_split": "train", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "description": "三轮连续中文指令;同一机器人状态、办公室背景、RTC 历史和 Qwen KV 从头保留到尾。", "required_semantics_version": 20, "initial_idle_steps": 5, "initial_idle_seconds": 2.0, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 25, 30 ], "inter_turn_background_seconds_by_turn": [ 10.0, 12.0 ], "terminal_background_steps": 5, "terminal_background_seconds": 2.0, "turns": [ { "turn_index": 1, "source_motion_filename": "grab_walk_ff_180_001__A548", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000006/female_01_zh.wav", "spoken_command": "向前走并抓取某物", "ideal_motion": "听完后向当前身体前方行走,同时完成清晰的伸手抓取;动作结束后在新位置恢复正常站立。" }, { "turn_index": 2, "source_motion_filename": "wave_two_hands_R_001__A533", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000155/female_01_zh.wav", "spoken_command": "双手在身前挥动", "ideal_motion": "保持第一轮累计的位置和朝向,身体基本原地站稳,双手在身前挥动,然后自然收手恢复站立。" }, { "turn_index": 3, "source_motion_filename": "neutral_walk_ff_270_R_001__A534_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000120/female_01_zh.wav", "spoken_command": "向左走路", "ideal_motion": "相对第二轮结束时的身体朝向向左侧行走,不重置到世界原点,最后恢复正常站立。" } ], "ideal_control_timeline": [ "初始纯背景时输出 </idle>,机器人自然站立且不提前抬手或移动", "每次有人说话时切到 </listen>,保持自然聆听动作", "每条指令结束后切到 </motion>,完整执行该轮动作", "第二轮前允许短暂停顿,第三轮前包含约 2 秒额外 idle", "最后一轮结束后,在 2 秒纯背景中回到并持续输出 </idle>" ], "continuity_requirements": [ "三轮只使用一个 Qwen KV cache,不在轮次边界清空", "三轮使用同一段连续办公室背景,不拼接不同背景音", "后续动作从上一轮真实生成的最终位置、朝向和关节状态继续", "RTC 历史按真实执行的动作连续传递,不读取 GT,也不重置机器人" ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100{ "format": "hfd_multiturn_auto_infer_scenario_v1", "name": "val_jog_pick_jump_idle_en_timeline_v2", "interaction_mode": "turn-taking", "description": "训练时 hash 划分到 val 的第 1199 条四轮 session;四条具体 motion source 均未进入训练集,并严格复现该 session 的真实语音起点。", "data_split": "val", "split_seed": 42, "val_ratio": 0.1, "split_source_namespace": "seed", "validation_session_index": 1199, "required_semantics_version": 20, "initial_idle_steps": 4, "initial_idle_seconds": 1.6, "motion_frames_per_turn": 450, "motion_seconds_per_turn": 9.0, "inter_turn_background_steps_by_turn": [ 18, 32, 14 ], "inter_turn_background_seconds_by_turn": [ 7.2, 12.8, 5.6 ], "turn_audio_window_counts": [ 4, 18, 5, 10 ], "expected_turn_window_starts": [ 0, 22, 72, 91 ], "source_turn_speech_start_frames_50fps": [ 80, 520, 1520, 1900 ], "source_turn_listen_start_frames_50fps": [ 120, 560, 1560, 1940 ], "source_inter_turn_idle_steps": [ 0, 8, 0 ], "terminal_background_steps": 6, "terminal_background_seconds": 2.4, "turns": [ { "turn_index": 1, "source_motion_filename": "jog_ff_start_180_R_003__A068", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000175/female_02_en.wav", "spoken_command": "start jog forward", "ideal_motion": "听完英文指令后从当前站立状态开始向身体前方慢跑,保持朝向连续。" }, { "turn_index": 2, "source_motion_filename": "medium_big_light_two_hands_right_side_low_to_right_side_high_R_001__A529", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000227/female_02_en.wav", "spoken_command": "picks up medium big light object with two hands from low right side and puts it away to the right side high", "ideal_motion": "在第一轮最终位置和朝向上,用双手从右下方拿起物体并举到右上方;这条完整指令和音频目录训练时从未出现。" }, { "turn_index": 3, "source_motion_filename": "reach_jump_R_003__A148_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/000243/female_02_en.wav", "spoken_command": "reaching something during jump", "ideal_motion": "保持累计状态,完成带伸手够物意图的跳跃并稳定落地。" }, { "turn_index": 4, "source_motion_filename": "idle_right_to_idle_003__A094_M", "audio_path": "/cpfs01/thscc/sharestorage/AIGC-06-01/Hithink_VideoGen_Group/user_workspace/buwendong/user/code/qwen3-tts/seed_audio/003713/female_02_en.wav", "spoken_command": "from neutral position with left leg forward to neutral position", "ideal_motion": "从左腿略在前的自然站姿平稳回到中立站姿,随后在纯背景中回到 idle。" } ], "ideal_control_timeline": [ "初始纯背景输出 </idle>", "每轮语音出现后切换到 </listen>", "听清完整指令后切换到 </motion>", "四轮语音起点严格复现验证 source 的 0、8.8、28.8、36.4 秒相对时间;7.2、12.8、5.6 秒是扣除上一条语音窗口后的实际背景间隔", "第四轮结束后在 2.4 秒背景中回到 </idle>" ], "continuity_requirements": [ "四轮共用一个 Qwen KV cache", "四轮使用同一段连续办公室背景", "机器人位置、朝向、关节状态和 RTC 历史不在轮次间重置", "所有 source_motion_filename 均按训练 run 的 split_seed=42、val_ratio=0.1 落在 val" ]}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192{ "format": "hfd_multiturn_auto_infer_suite_v2", "description": "同一 checkpoint 的既有五类任务及 pause、filled hesitation、self-repair hesitation × train/val 共十六组闭环推理;由空闲 GPU 动态领取任务。", "cases": [ { "interaction_mode": "turn-taking", "data_split": "train", "scenario_file": "multiturn_auto_scenario_v1.json" }, { "interaction_mode": "turn-taking", "data_split": "val", "scenario_file": "multiturn_auto_scenario_val_v1.json" }, { "interaction_mode": "interruption", "data_split": "train", "scenario_file": "multiturn_auto_scenario_interruption_train_v1.json" }, { "interaction_mode": "interruption", "data_split": "val", "scenario_file": "multiturn_auto_scenario_interruption_val_v1.json" }, { "interaction_mode": "emergency-stop", "data_split": "train", "scenario_file": "multiturn_auto_scenario_emergency_stop_train_v1.json" }, { "interaction_mode": "emergency-stop", "data_split": "val", "scenario_file": "multiturn_auto_scenario_emergency_stop_val_v1.json" }, { "interaction_mode": "safe-hold", "data_split": "train", "scenario_file": "multiturn_auto_scenario_safe_hold_train_v1.json" }, { "interaction_mode": "safe-hold", "data_split": "val", "scenario_file": "multiturn_auto_scenario_safe_hold_val_v1.json" }, { "interaction_mode": "backchannel", "data_split": "train", "scenario_file": "multiturn_auto_scenario_backchannel_train_v1.json" }, { "interaction_mode": "backchannel", "data_split": "val", "scenario_file": "multiturn_auto_scenario_backchannel_val_v1.json" }, { "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "train", "scenario_file": "multiturn_auto_scenario_pause_train_v1.json" }, { "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "val", "scenario_file": "multiturn_auto_scenario_pause_val_v1.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "train", "scenario_file": "multiturn_auto_scenario_hesitation_filled_train_v1.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "val", "scenario_file": "multiturn_auto_scenario_hesitation_filled_val_v1.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "train", "scenario_file": "multiturn_auto_scenario_hesitation_repair_train_v1.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "val", "scenario_file": "multiturn_auto_scenario_hesitation_repair_val_v1.json" } ]}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192{ "format": "hfd_multiturn_auto_infer_suite_v3", "description": "同一 checkpoint 的七类任务 × train/val 共十六组闭环推理;v24 使用自然拖长 filler,并同时覆盖显式提示和无提示词自我改口;由空闲 GPU 动态领取任务。", "cases": [ { "interaction_mode": "turn-taking", "data_split": "train", "scenario_file": "multiturn_auto_scenario_v1.json" }, { "interaction_mode": "turn-taking", "data_split": "val", "scenario_file": "multiturn_auto_scenario_val_v1.json" }, { "interaction_mode": "interruption", "data_split": "train", "scenario_file": "multiturn_auto_scenario_interruption_train_v1.json" }, { "interaction_mode": "interruption", "data_split": "val", "scenario_file": "multiturn_auto_scenario_interruption_val_v1.json" }, { "interaction_mode": "emergency-stop", "data_split": "train", "scenario_file": "multiturn_auto_scenario_emergency_stop_train_v1.json" }, { "interaction_mode": "emergency-stop", "data_split": "val", "scenario_file": "multiturn_auto_scenario_emergency_stop_val_v1.json" }, { "interaction_mode": "safe-hold", "data_split": "train", "scenario_file": "multiturn_auto_scenario_safe_hold_train_v1.json" }, { "interaction_mode": "safe-hold", "data_split": "val", "scenario_file": "multiturn_auto_scenario_safe_hold_val_v1.json" }, { "interaction_mode": "backchannel", "data_split": "train", "scenario_file": "multiturn_auto_scenario_backchannel_train_v1.json" }, { "interaction_mode": "backchannel", "data_split": "val", "scenario_file": "multiturn_auto_scenario_backchannel_val_v1.json" }, { "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "train", "scenario_file": "multiturn_auto_scenario_pause_train_v2.json" }, { "interaction_mode": "pause", "interaction_subtype": "silent-pause", "data_split": "val", "scenario_file": "multiturn_auto_scenario_pause_val_v2.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "train", "scenario_file": "multiturn_auto_scenario_hesitation_filled_train_v2.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "filled-pause", "data_split": "val", "scenario_file": "multiturn_auto_scenario_hesitation_filled_val_v2.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "train", "scenario_file": "multiturn_auto_scenario_hesitation_repair_train_v2.json" }, { "interaction_mode": "hesitation", "interaction_subtype": "self-repair", "data_split": "val", "scenario_file": "multiturn_auto_scenario_hesitation_repair_val_v2.json" } ]}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180#!/usr/bin/env python3from __future__ import annotations
import argparseimport jsonimport subprocessfrom pathlib import Pathfrom typing import Any
def probe(path: Path) -> dict[str, Any]: result = subprocess.run( [ "ffprobe", "-v", "error", "-show_streams", "-show_format", "-of", "json", str(path), ], capture_output=True, check=False, ) if result.returncode != 0: raise RuntimeError(result.stderr.decode("utf-8", errors="ignore")) return json.loads(result.stdout)
def stream(payload: dict[str, Any], codec_type: str) -> dict[str, Any]: for item in payload.get("streams", []): if item.get("codec_type") == codec_type: return item raise RuntimeError(f"ffprobe found no {codec_type} stream")
def fraction(value: str) -> float: numerator, denominator = str(value).split("/", 1) return float(numerator) / float(denominator)
def main() -> None: parser = argparse.ArgumentParser( description=( "Mux either a complete HFD streaming audio timeline or legacy " "speech-only audio onto the rendered motion" ) ) parser.add_argument("--video", required=True) parser.add_argument("--audio", required=True) parser.add_argument("--output", required=True) parser.add_argument("--infer-meta", required=True) parser.add_argument( "--audio-is-timeline", action="store_true", help=( "The audio already contains initial background, speech, and " "post-WAV background on the complete 50 Hz output timeline." ), ) parser.add_argument("--expected-fps", type=float, default=50.0) args = parser.parse_args()
video = Path(args.video).expanduser().resolve() audio = Path(args.audio).expanduser().resolve() output = Path(args.output).expanduser().resolve() meta_path = Path(args.infer_meta).expanduser().resolve() for path in (video, audio, meta_path): if not path.is_file(): raise FileNotFoundError(path)
video_probe = probe(video) video_stream = stream(video_probe, "video") video_duration = float( video_stream.get("duration") or video_probe["format"].get("duration") ) video_fps = fraction(video_stream.get("avg_frame_rate") or video_stream["r_frame_rate"]) if abs(video_fps - float(args.expected_fps)) > 0.01: raise RuntimeError( f"Rendered video FPS {video_fps} does not preserve the 50 Hz HFD timeline" )
metadata = json.loads(meta_path.read_text(encoding="utf-8")) requested_speech_delay_seconds = max( float(metadata.get("speech_start_seconds", 0.0)), 0.0, ) applied_audio_delay_seconds = ( 0.0 if bool(args.audio_is_timeline) else requested_speech_delay_seconds ) speech_delay_ms = int(round(applied_audio_delay_seconds * 1000.0)) delay_filter = ( f"adelay={speech_delay_ms}:all=1," if speech_delay_ms > 0 else "" ) output.parent.mkdir(parents=True, exist_ok=True) temporary = output.with_name(f".{output.name}.tmp.mp4") command = [ "ffmpeg", "-v", "error", "-y", "-i", str(video), "-i", str(audio), "-filter_complex", f"[1:a]{delay_filter}aresample=async=1:first_pts=0," f"apad=whole_dur={video_duration:.9f}[audio]", "-map", "0:v:0", "-map", "[audio]", "-c:v", "copy", "-c:a", "aac", "-movflags", "+faststart", "-t", f"{video_duration:.9f}", str(temporary), ] result = subprocess.run(command, capture_output=True, check=False) if result.returncode != 0: raise RuntimeError( f"ffmpeg mux failed: {result.stderr.decode('utf-8', errors='ignore')}" ) temporary.replace(output)
output_probe = probe(output) output_video = stream(output_probe, "video") output_audio = stream(output_probe, "audio") video_start = float(output_video.get("start_time", 0.0)) audio_start = float(output_audio.get("start_time", 0.0)) output_duration = float(output_probe["format"].get("duration", 0.0)) frame_tolerance = 1.0 / float(args.expected_fps) + 1e-3 if abs(video_start) > frame_tolerance or abs(audio_start) > frame_tolerance: raise RuntimeError( f"Muxed streams do not start together: video={video_start}, audio={audio_start}" ) if output_duration + frame_tolerance < video_duration: raise RuntimeError( f"Mux truncated the motion video: input={video_duration}, output={output_duration}" )
metadata["mux"] = { "video_without_audio": str(video), "video_with_audio": str(output), "audio": str(audio), "video_fps": video_fps, "video_start_seconds": video_start, "audio_start_seconds": audio_start, "video_duration_seconds": video_duration, "muxed_duration_seconds": output_duration, "audio_mode": ( "complete_stream_timeline" if bool(args.audio_is_timeline) else "speech_only_legacy" ), "audio_padding": ( "timeline_apad_only_if_container_rounding_requires_it" if bool(args.audio_is_timeline) else "silence_to_video_end" ), "speech_delay_seconds": requested_speech_delay_seconds, "applied_audio_delay_seconds": applied_audio_delay_seconds, "motion_start_frame_50fps": metadata.get("motion_start_frame_50fps"), "motion_start_seconds": metadata.get("motion_start_seconds"), } meta_path.write_text( json.dumps(metadata, ensure_ascii=False, indent=2) + "\n", encoding="utf-8" ) print(f"[done] synchronized video: {output}", flush=True)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287#!/usr/bin/env python3"""Render a stratified final-model review from saved predictions, CPU only."""from __future__ import annotations
import argparsefrom concurrent.futures import ThreadPoolExecutor, as_completedimport hashlibimport jsonimport osfrom pathlib import Pathimport randomimport shutilimport subprocessimport sysimport timeimport wave
PROJECT = Path(__file__).resolve().parents[2]sys.path[:0] = [str(PROJECT), str(PROJECT / "src")]PROFILES = ("single_short", "multi_single", "multi_babble", "mixed_short", "continuous", "same_voice_aside")LABELS = dict(zip(PROFILES, ("单段短人声", "多段单人声", "多段多人杂谈", "单/多人混合短声", "连续背景说话", "指令同音色旁话")))ASSETS = ("motion.npy", "body_pos.csv", "body_quat.csv", "joint_pos.csv", "body_lin_vel.csv", "body_ang_vel.csv", "joint_vel.csv", "metadata.txt", "infer_meta.json", "metrics.json", "session_recipe.json")
def read(path): return json.loads(Path(path).read_text())
def digest(path): h = hashlib.sha256() with Path(path).open("rb") as handle: for block in iter(lambda: handle.read(1024 * 1024), b""): h.update(block) return h.hexdigest()
def write(path, value): path = Path(path) temp = path.with_suffix(path.suffix + ".tmp") temp.write_text(json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False) + "\n") temp.replace(path)
def select_samples(selection, report, seed=26100801): rows, samples = selection["sessions"], report["samples"] ids = [r["session_id"] for r in rows] sample_ids = [r["session_id"] for r in samples] if (report.get("status") != "complete" or report.get("evaluation_split") != "train_only" or report.get("count") != 300 or len(rows) != 300 or len(samples) != 300 or len(set(ids)) != 300 or len(set(sample_ids)) != 300 or set(ids) != set(sample_ids) or selection["session_ids"] != ids): raise ValueError("Expected the same complete unique train300 selection and report") by_id = {r["session_id"]: r for r in rows} for sample in samples: row = by_id[sample["session_id"]] if (sample["profile"] != row["session_type"] or sample["background_language"] != row["background_language"]): raise ValueError("Prediction profile/language differs from frozen selection") rng, chosen = random.Random(seed), [] for profile in PROFILES: for language in ("zh", "en"): for high in (False, True): pool = sorted((s for s in samples if s["profile"] == profile and s["background_language"] == language and by_id[s["session_id"]]["background_high"] == high), key=lambda s: s["session_id"]) if not pool: raise ValueError(f"Empty review cell: {profile}/{language}/{high}") chosen.append({**rng.choice(pool), "number": f"{len(chosen) + 1:02d}", "background_high": high}) return chosen
def contained(path, root): path, root = Path(path).resolve(strict=True), Path(root).resolve(strict=True) if path == root or not path.is_relative_to(root): raise ValueError(f"Path escaped expected input root: {path}") return path
def render_session_alive(pid): """Include orphaned encoders/renderers, not only the coordinating worker.""" for stat in Path("/proc").glob("[0-9]*/stat"): try: fields = stat.read_text().rsplit(")", 1)[1].split() except (FileNotFoundError, ProcessLookupError): continue if fields[0] != "Z" and int(fields[3]) == int(pid): return True return False
def prepare(run, manifest): import numpy as np run = contained(run, PROJECT / "runs") report_path = run / "final_train300/report.json" report, result, selection = read(report_path), read(run / "result.json"), read(manifest) if result["status"] != "complete" or report["step"] != result["step"]: raise ValueError("Final report does not describe the completed run") status = read(run / "run_status.json") if digest(manifest) != status["manifest_sha256"]: raise ValueError("Frozen train300 selection hash changed") chosen = select_samples(selection, report) for row in chosen: source = contained(row["prediction_directory"], run / "final_train300/samples") meta = read(source / "infer_meta.json") recipe = read(source / "session_recipe.json") if (meta["session_id"] != row["session_id"] or meta["global_step"] != report["step"] or meta["artifact_role"] != "model_prediction_not_GT" or recipe["split"] != "train" or recipe["session_id"] != row["session_id"]): raise ValueError("Prediction provenance is inconsistent") audio = contained(meta["frozen_audio_path"], PROJECT / "data/hfd_third_party_multi_v5/production/audio/train") if digest(audio) != meta["frozen_audio_sha256"] or meta["frozen_audio_sha256"] != recipe["audio"]["sha256"]: raise ValueError("Frozen mixed audio changed") with wave.open(str(audio), "rb") as wav: if (wav.getframerate(), wav.getnchannels(), wav.getsampwidth()) != (16000, 1, 2): raise ValueError("Expected the original mono 16 kHz PCM16") frames, seconds = round(wav.getnframes() * 50 / 16000), wav.getnframes() / 16000 motion = np.load(source / "motion.npy", allow_pickle=False) if motion.shape != (frames, 36) or not np.isfinite(motion).all() or digest(source / "motion.npy") != row["motion_sha256"]: raise ValueError("Saved predicted trajectory is incomplete or changed") for name, width in (("body_pos.csv", 3), ("body_quat.csv", 4), ("joint_pos.csv", 29)): values = np.loadtxt(source / name, delimiter=",", skiprows=1, ndmin=2) if values.shape != (frames, width) or not np.isfinite(values).all(): raise ValueError(f"Render CSV has invalid length or values: {name}") row.update(source_directory=str(source), audio_path=str(audio), audio_sha256=meta["frozen_audio_sha256"], duration_seconds=seconds, source_files={name: digest(source / name) for name in ASSETS}) return {"schema": 1, "run_dir": str(run), "step": report["step"], "artifact_role": "model_prediction_not_GT", "evaluation_split": "train_only", "seed": 26100801, "count": 24, "inference_repeated": False, "report_sha256": digest(report_path), "manifest_sha256": digest(manifest), "selection_policy": "one random sample per profile/language/loudness cell; never select by score", "render": {"backend": "mesa_cpu", "workers": 4, "threads_each": 4, "fps": 25, "width": 320, "height": 240}, "audio_policy": "original mixed timeline; no gain/offset change; AAC encoding in MP4", "samples": chosen}
def render_one(row, output): from scripts.infer.third_party_checkpoint_probe import render_prediction from scripts.infer.mux_full_duplex_audio import probe, stream, fraction started = time.monotonic() source, audio = Path(row["source_directory"]), Path(row["audio_path"]) destination = output / "samples" / row["number"] flat = output / f"{row['number']}.mp4" saved_result = destination / "render_result.json" for path in (output, output / "samples", destination, flat, saved_result, *(destination / name for name in ASSETS)): if path.is_symlink(): raise ValueError("Refusing symlink in dedicated preview outputs") if saved_result.exists(): result = read(saved_result) if (result.get("status") != "complete" or any(result.get(key) != value for key, value in row.items()) or not result.get("full_decode_passed") or not result.get("source_files_unchanged") or result.get("video") != str(flat) or digest(flat) != result["video_sha256"] or flat.stat().st_size != result.get("video_bytes")): raise ValueError("Completed preview does not match the frozen render plan") if any(digest(source / name) != expected for name, expected in row["source_files"].items()) or digest(audio) != row["audio_sha256"]: raise ValueError("Original prediction/audio changed before preview reuse") return {**result, "reused_existing_video": True} if flat.exists(): raise ValueError("Unverified video exists without a completed render result; refusing overwrite") # Only unfinished copies in this dedicated output may be rewritten on resume. destination.mkdir(parents=True, exist_ok=True) for name, expected in row["source_files"].items(): if digest(source / name) != expected: raise ValueError("Source prediction changed after preflight") shutil.copy2(source / name, destination / name) if digest(destination / name) != expected: raise ValueError("Prediction copy changed") if digest(audio) != row["audio_sha256"]: raise ValueError("Audio changed after preflight") video = render_prediction(destination, audio) media = probe(video); v, a = stream(media, "video"), stream(media, "audio") if (v["width"], v["height"]) != (320, 240) or abs(fraction(v["avg_frame_rate"]) - 25) > .01: raise ValueError("Rendered dimensions/FPS changed") if int(a["channels"]) != 1 or int(a["sample_rate"]) != 16000: raise ValueError("Rendered audio stream format changed") if float(media["format"]["duration"]) < row["duration_seconds"] - .041: raise ValueError("Rendered video truncated the input timeline") for name, expected in row["source_files"].items(): if digest(source / name) != expected: raise ValueError("Original prediction was modified during rendering") if digest(audio) != row["audio_sha256"]: raise ValueError("Original audio was modified during rendering") # A second name for the same local output; no duplicate video storage. os.link(video, flat) result = {**row, "status": "complete", "video": str(flat), "video_sha256": digest(flat), "video_bytes": flat.stat().st_size, "full_decode_passed": True, "source_files_unchanged": True, "render_seconds": time.monotonic() - started} write(destination / "render_result.json", result) return result
def publish(output, plan, completed): lines = ["# 最终模型预测视频(不是 GT)", "", f"Checkpoint **{plan['step']}**;已完成 **{len(completed)}/24**。", "", "复用已保存的训练集预测,不重复推理;六类×中英文背景×普通/较高背景音量,每格固定随机抽一条。", "320×240、25fps审核预览;原始预测仍为50Hz。完整原混音不调音量、不改时间位置,MP4音轨编码为AAC。", "", "下表指标对应各自单条样本,仅供定位问题,不作为总体效果估计。", "", "| 序号/视频 | 类型 | 背景语言 | 背景音量 | 时长 | 控制准确率 | 背景误动率 |", "|---|---|---|---|---:|---:|---:|"] by_number = {r["number"]: r for r in completed} for row in plan["samples"]: number = row["number"]; label = f"[{number}]({number}.mp4)" if number in by_number else f"{number} 待完成" metrics = row["metrics"]; bg = metrics.get("background_only_false_motion_rate") bg = "无可评分区间" if bg is None else f"{bg:.1%}" lines.append(f"| {label} | {LABELS[row['profile']]} | {'中文' if row['background_language']=='zh' else '英文'} | " f"{'较高' if row['background_high'] else '普通'} | {row['duration_seconds']:.1f}s | {metrics['control_accuracy']:.1%} | {bg} |") lines.extend(["", "[原始逐条评估](../final_train300/report.json) · [抽样与来源校验](plan.json) · [渲染状态](status.json)", ""]) (output / "README.md").write_text("\n".join(lines)) run = Path(plan["run_dir"]); review = run / "review.md" if review.exists(): marker = "<!-- final_prediction_videos -->" text = review.read_text().split(marker)[0].rstrip() text = text.replace("| — | 尚无完整 probe 记录 | — | — | — | — |", "| — | 本轮采用轮末数值评估,见下方逐轮表 | — | — | — | [预测视频](prediction_videos/README.md) |") review.write_text(text + f"\n\n{marker}\n## 最终模型预测视频\n\n" f"Checkpoint {plan['step']},已渲染 {len(completed)}/24 条,**模型预测,不是GT**。\n\n" "[01–24 视频与类型表](prediction_videos/README.md) · [最终300条评估](final_train300/report.json)\n")
def worker(output): # Imports occur before parallel rendering; no CUDA model is loaded. from scripts.infer.third_party_checkpoint_probe import check_renderer check_renderer() plan = read(output / "plan.json") completed, failures = [], [] started = time.time() def status(phase): write(output / "status.json", {"phase": phase, "pid": os.getpid(), "started_at": started, "updated_at": time.time(), "completed": len(completed), "total": 24, "failed": len(failures), "samples": completed, "errors": failures, "gpu_used": False, "inference_repeated": False, "workers": plan["render"]["workers"]}) publish(output, plan, completed) status("rendering") with ThreadPoolExecutor(max_workers=plan["render"]["workers"]) as pool: jobs = {pool.submit(render_one, row, output): row for row in plan["samples"]} for future in as_completed(jobs): row = jobs[future] try: result = future.result(); completed.append(result) print(json.dumps({"number": row["number"], "seconds": result["render_seconds"], "status": "complete"}), flush=True) except Exception as error: failures.append({"number": row["number"], "error": repr(error)}) print(json.dumps(failures[-1]), flush=True) status("rendering") status("failed" if failures else "completed") if failures: raise RuntimeError(f"{len(failures)} preview renders failed; inspect per-sample render.log")
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--run-dir", type=Path, required=True) parser.add_argument("--manifest", type=Path, default=PROJECT / "data/hfd_third_party_multi_v5/training_pilot_300/selection.json") parser.add_argument("--workers", type=int, choices=range(1, 17), default=12) parser.add_argument("--resume", action="store_true", help="Reuse verified videos after the previous render worker has exited") mode = parser.add_mutually_exclusive_group(required=True) for name in ("launch", "worker", "check-only"): mode.add_argument(f"--{name}", action="store_true") args = parser.parse_args(); run = contained(args.run_dir, PROJECT / "runs"); output = run / "prediction_videos" if args.resume and not args.launch: parser.error("--resume requires --launch") os.environ.update(CUDA_VISIBLE_DEVICES="", PYTHONDONTWRITEBYTECODE="1", OMP_NUM_THREADS="1", MKL_NUM_THREADS="1") if args.worker: worker(output); return plan = prepare(run, args.manifest) plan["render"]["workers"] = args.workers if args.check_only: print(json.dumps({"passed": True, "step": plan["step"], "count": 24, "seconds": sum(r['duration_seconds'] for r in plan['samples'])})); return if args.resume: previous = read(output / "plan.json") if any(previous[key] != plan[key] for key in plan if key != "render"): raise ValueError("Cannot resume a different frozen prediction review") if any(previous["render"][key] != plan["render"][key] for key in plan["render"] if key != "workers"): raise ValueError("Resume can change worker count only, not rendering settings") previous_status = read(output / "status.json") if render_session_alive(previous_status["pid"]): raise ValueError("Previous render session is still present; refusing concurrent launch") else: output.mkdir(exist_ok=False) write(output / "plan.json", plan) with (output / "render.log").open("a" if args.resume else "x") as log: child = subprocess.Popen([sys.executable, str(Path(__file__).resolve()), "--run-dir", str(run), "--worker"], cwd=PROJECT, env=os.environ.copy(), stdin=subprocess.DEVNULL, stdout=log, stderr=subprocess.STDOUT, start_new_session=True) print(json.dumps({"render_pid": child.pid, "output": str(output), "index": str(output / 'README.md')}))
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151#!/usr/bin/env python3"""CPU-only final scale previews, with separate train and held-out indexes."""from __future__ import annotations
import argparsefrom concurrent.futures import ThreadPoolExecutor, as_completedimport osfrom pathlib import Pathimport sysimport timeimport wave
PROJECT = Path(__file__).resolve().parents[2]sys.path[:0] = [str(PROJECT), str(PROJECT / "src")]from scripts.infer.render_third_party_review import ( ASSETS, LABELS, contained, digest, read, render_one, write)
def selected_rows(selection, report, step): if (selection.get("scaleup") is not True or selection.get("split") not in ("train", "validation") or report.get("status") != "complete" or report.get("step") != step or report.get("evaluation_split") != selection["split"]): raise ValueError("Final prediction split/step differs from its frozen selection") by_id = {r["session_id"]: r for r in selection["sessions"]} samples = {r["session_id"]: r for r in report["samples"]} if len(samples) != report["count"] or len(samples) != len(report["samples"]): raise ValueError("Duplicate/incomplete final predictions") ids = selection["video_session_ids"] if not ids or len(ids) != len(set(ids)) or not set(ids) <= samples.keys() & by_id.keys(): raise ValueError("Missing predetermined video samples") rows = [] for index, sid in enumerate(ids, 1): row, chosen = samples[sid], by_id[sid] if (row["profile"] != chosen["session_type"] or row["split"] != selection["split"] or row["background_language"] != chosen["background_language"]): raise ValueError("Prediction labels differ from frozen selection") rows.append({**row, "number": f"{index:02d}", "background_high": chosen["background_high"]}) return rows
def prepare(run, manifest): import numpy as np run = contained(run, PROJECT / "runs") result, identity = read(run / "result.json"), read(run / "scale_identity.json") if result["status"] != "complete": raise ValueError("Training/evaluation has not completed") rows, hashes = [], {} for split in ("train", "validation"): path = manifest if split == "train" else manifest.parent / "validation.json" key = "manifest_sha256" if split == "train" else "validation_sha256" if digest(path) != identity[key]: raise ValueError("Frozen video selection changed") selection = read(path) report_path = run / "evaluations/final" / split / "report.json" report = read(report_path); hashes[split] = digest(report_path) for row in selected_rows(selection, report, result["step"]): source = contained(row["prediction_directory"], report_path.parent / "samples") meta, recipe = read(source / "infer_meta.json"), read(source / "session_recipe.json") if (meta["session_id"] != row["session_id"] or meta["global_step"] != result["step"] or meta.get("evaluation_split") != split or meta["artifact_role"] != "model_prediction_not_GT" or recipe["session_id"] != row["session_id"] or recipe["split"] != split): raise ValueError("Prediction provenance mismatch") audio = contained(meta["frozen_audio_path"], Path(selection["production_root"]) / "audio" / split) if digest(audio) != meta["frozen_audio_sha256"] or digest(audio) != recipe["audio"]["sha256"]: raise ValueError("Original mixed audio changed") with wave.open(str(audio), "rb") as wav: if (wav.getframerate(), wav.getnchannels(), wav.getsampwidth()) != (16000, 1, 2): raise ValueError("Expected original mono 16kHz PCM16") seconds = wav.getnframes() / 16000 frames = round(seconds * 50) motion = np.load(source / "motion.npy", allow_pickle=False) if motion.shape != (frames, 36) or not np.isfinite(motion).all() or digest(source / "motion.npy") != row["motion_sha256"]: raise ValueError("Prediction trajectory changed or incomplete") for name, width in (("body_pos.csv", 3), ("body_quat.csv", 4), ("joint_pos.csv", 29)): values = np.loadtxt(source / name, delimiter=",", skiprows=1, ndmin=2) if values.shape != (frames, width) or not np.isfinite(values).all(): raise ValueError(f"Invalid predicted render CSV: {name}") rows.append({**row, "source_directory": str(source), "audio_path": str(audio), "audio_sha256": meta["frozen_audio_sha256"], "duration_seconds": seconds, "source_files": {name: digest(source / name) for name in ASSETS}}) return {"schema": 1, "run_dir": str(run), "step": result["step"], "count": len(rows), "samples": rows, "report_hashes": hashes, "gpu_used": False, "inference_repeated": False, "selection_policy": "predetermined one per available class/language/loudness cell, never by model score", "artifact_role": "model_prediction_not_GT", "render": {"workers": 12, "fps": 25, "size": [320, 240]}}
def publish(output, plan, completed): done = {(r["split"], r["number"]) for r in completed} lines = ["# 全量训练最终预测视频(不是 GT)", "", f"新阶段 checkpoint {plan['step']};完成 {len(completed)}/{plan['count']}。", "复用完整预测;原混音不改变音量和时间。CPU 并行渲染,320×240、25fps;原预测仍为50Hz。", "样例在训练前按六类×中英文背景×普通/较高音量固定随机选定,不按效果挑选。", ""] for split, label in (("train", "训练集(拟合)"), ("validation", "独立验证集(未参与优化)")): lines += [f"## {label}", "", "| 视频序号 | 类型 | 背景语言 | 背景音量 | 控制准确率 | 背景误动率 |", "|---|---|---|---|---:|---:|"] for row in plan["samples"]: if row["split"] != split: continue number = row["number"] link = f"[{number}]({split}/{number}.mp4)" if (split, number) in done else f"{number} 待生成" metrics = row["metrics"]; bg = metrics.get("background_only_false_motion_rate") bg_text = "无评分区间" if bg is None else f"{bg:.1%}" lines.append(f"| {link} | {LABELS[row['profile']]} | {'中文' if row['background_language']=='zh' else '英文'} | " f"{'较高' if row['background_high'] else '普通'} | {metrics['control_accuracy']:.1%} | {bg_text} |") lines += ["", f"[本组原始逐条指标](../evaluations/final/{split}/report.json)", ""] lines += ["单条视频指标用于定位问题,不代替全部验证结果,也不代表机器人实际执行成功。", "", "[渲染状态](status.json) · [完整抽样溯源](plan.json)", ""] (output / "README.md").write_text("\n".join(lines))
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--run-dir", type=Path, required=True) parser.add_argument("--manifest", type=Path, required=True) args = parser.parse_args() os.environ.update(CUDA_VISIBLE_DEVICES="", OMP_NUM_THREADS="1", MKL_NUM_THREADS="1", PYTHONDONTWRITEBYTECODE="1") from scripts.infer.third_party_checkpoint_probe import check_renderer plan = prepare(args.run_dir, args.manifest.resolve()) output = Path(plan["run_dir"]) / "prediction_videos" output.mkdir(exist_ok=False) write(output / "plan.json", plan) for split in ("train", "validation"): (output / split).mkdir() completed, failures = [], [] def status(phase): write(output / "status.json", {"phase": phase, "time": time.time(), "pid": os.getpid(), "completed": len(completed), "total": plan["count"], "failures": failures, "gpu_used": False, "inference_repeated": False}) publish(output, plan, completed) status("starting") try: check_renderer() with ThreadPoolExecutor(max_workers=12) as pool: jobs = {pool.submit(render_one, row, output / row["split"]): row for row in plan["samples"]} for future in as_completed(jobs): row = jobs[future] try: completed.append(future.result()) print(f"{row['split']}/{row['number']} completed", flush=True) except Exception as error: failures.append({"split": row["split"], "number": row["number"], "error": repr(error)}) status("rendering") if failures: raise RuntimeError("Some final videos failed; inspect status.json and per-sample render.log") status("completed") except Exception as error: failures.append({"error": repr(error)}); status("failed"); raise
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700#!/usr/bin/env python3"""Run HFD multi-turn evaluation cases through a dynamic GPU queue."""
from __future__ import annotations
import hashlibimport jsonimport osimport reimport subprocessimport sysimport timefrom collections import dequefrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Any
PROJECT_ROOT = Path(__file__).resolve().parents[2]DEFAULT_SUITE_V23 = PROJECT_ROOT / "scripts/infer/multiturn_auto_suite_v2.json"DEFAULT_SUITE_V24 = PROJECT_ROOT / "scripts/infer/multiturn_auto_suite_v3.json"
@dataclass(frozen=True)class InferenceCase: name: str interaction_mode: str data_split: str scenario_path: Path scenario: dict[str, Any] interaction_subtype: str = ""
def _truthy(value: str | None) -> bool: return str(value or "").strip().lower() in {"1", "true", "yes", "on"}
def _motion_source_id(namespace: str, filename: str) -> str: leaf = filename.replace("\\", "/").rstrip("/").rsplit("/", 1)[-1] if leaf.lower().endswith(".csv"): leaf = leaf[:-4] return f"{namespace.strip().strip('/')}/{leaf}"
def _source_is_val(source_id: str, *, split_seed: int, val_ratio: float) -> bool: digest = hashlib.sha1( f"psi0-motion-source-split-v1\0{split_seed}\0{source_id}".encode() ).digest() threshold = int(float(val_ratio) * (1 << 64)) return int.from_bytes(digest[:8], "big", signed=False) < threshold
def _load_json(path: Path) -> dict[str, Any]: payload = json.loads(path.read_text(encoding="utf-8")) if not isinstance(payload, dict): raise ValueError(f"JSON root must be an object: {path}") return payload
def validate_scenario( path: Path, *, run_config: dict[str, Any], expected_mode: str | None = None, expected_split: str | None = None, expected_subtype: str | None = None,) -> InferenceCase: payload = _load_json(path) if payload.get("format") != "hfd_multiturn_auto_infer_scenario_v1": raise ValueError(f"Unsupported multi-turn scenario: {path}") turns = list(payload.get("turns", [])) if not 2 <= len(turns) <= 4: raise ValueError(f"Scenario must contain 2-4 turns, got {len(turns)}") mode = str(payload.get("interaction_mode", "turn-taking")).strip().lower() supported_modes = { "turn-taking", "interruption", "emergency-stop", "safe-hold", "backchannel", "hesitation", "pause", } if mode not in supported_modes: raise ValueError(f"Unsupported interaction_mode={mode!r}: {path}") split = str(payload.get("data_split", "custom")).strip().lower() if split not in {"train", "val", "custom"}: raise ValueError(f"Unsupported data_split={split!r}: {path}") if expected_mode is not None and mode != expected_mode: raise ValueError(f"Suite/scenario mode mismatch: {expected_mode} != {mode}") if expected_split is not None and split != expected_split: raise ValueError(f"Suite/scenario split mismatch: {expected_split} != {split}") subtype = str(payload.get("interaction_subtype", "")).strip().lower() valid_subtypes = { "hesitation": {"filled-pause", "self-repair"}, "pause": {"silent-pause"}, } if mode in valid_subtypes: if subtype not in valid_subtypes[mode]: raise ValueError( f"Invalid {mode} interaction_subtype={subtype!r}: {path}" ) elif subtype: raise ValueError( f"interaction_subtype is only valid for hesitation/pause: {path}" ) if expected_subtype is not None and subtype != expected_subtype: raise ValueError( f"Suite/scenario subtype mismatch: {expected_subtype} != {subtype}" )
gaps = [int(value) for value in payload["inter_turn_background_steps_by_turn"]] if len(gaps) != len(turns) - 1 or any(value < 0 for value in gaps): raise ValueError(f"Invalid per-turn background gaps: {gaps}") declared_gap_seconds = [ float(value) for value in payload.get("inter_turn_background_seconds_by_turn", []) ] if declared_gap_seconds: expected_gap_seconds = [0.4 * value for value in gaps] if len(declared_gap_seconds) != len(gaps) or any( abs(observed - expected) > 1e-9 for observed, expected in zip( declared_gap_seconds, expected_gap_seconds, ) ): raise ValueError( "Scenario gap seconds disagree with 0.4-second Qwen steps: " f"{declared_gap_seconds} != {expected_gap_seconds}" ) if mode in {"interruption", "emergency-stop", "safe-hold"}: gap_seconds = [0.4 * value for value in gaps] if any(value < 2.0 or value > 6.0 for value in gap_seconds): raise ValueError( "Mid-motion command gaps must stay within 2-6 seconds: " f"{gap_seconds}" ) if mode == "backchannel": marked = [ index for index, turn in enumerate(turns) if str(turn.get("backchannel_intent", "")).strip() ] if len(marked) != 1 or marked[0] == 0: raise ValueError( "Backchannel scenario needs exactly one acknowledgement after " f"a real action command: indices={marked}" ) if str(turns[marked[0]]["backchannel_intent"]).strip() not in { "continuer", "assessment", }: raise ValueError("Unknown backchannel intent category") voice_stems = { Path(str(turn["audio_path"])).stem for turn in turns } if len(voice_stems) != 1: raise ValueError( "Backchannel scenario must keep one speaker/language identity: " f"{sorted(voice_stems)}" ) onset_gap_seconds = 0.4 * gaps[marked[0] - 1] if not 1.2 <= onset_gap_seconds <= 6.0: raise ValueError( "Backchannel must arrive during active motion: " f"gap={onset_gap_seconds}s" )
window_counts = [ int(value) for value in payload.get("turn_audio_window_counts", []) ] expected_starts = [ int(value) for value in payload.get("expected_turn_window_starts", []) ] if window_counts or expected_starts: if len(window_counts) != len(turns) or len(expected_starts) != len(turns): raise ValueError("Timeline audit needs one window count/start per turn") derived_starts = [0] for count, gap in zip(window_counts, gaps): if count <= 0: raise ValueError(f"Invalid audio window counts: {window_counts}") derived_starts.append(derived_starts[-1] + count + gap) if derived_starts != expected_starts: raise ValueError( f"Scenario gap timeline mismatch: {derived_starts} != {expected_starts}" )
source_starts = [ int(value) for value in payload.get("source_turn_speech_start_frames_50fps", []) ] if source_starts: if len(source_starts) != len(turns) or not expected_starts: raise ValueError( "Source timeline audit needs one source start and one expected " "inference start per turn" ) relative_frames = [value - source_starts[0] for value in source_starts] if any(value % 20 != 0 for value in relative_frames): raise ValueError( "Source speech starts are not aligned to the 20-frame Qwen grid: " f"{source_starts}" ) source_relative_steps = [value // 20 for value in relative_frames] if source_relative_steps != expected_starts: raise ValueError( "Scenario inference starts do not reproduce the source speech " f"timeline: {source_relative_steps} != {expected_starts}" )
data = dict(run_config.get("data", {})) train = dict(run_config.get("train", {})) active_semantics = int(train.get("full_duplex_semantics_version", 0)) required_semantics = int(payload.get("required_semantics_version", 0)) if active_semantics < required_semantics: raise ValueError( f"Scenario requires semantics {required_semantics}, run has {active_semantics}" ) if mode == "interruption" and ( active_semantics < 20 or not bool(data.get("interruption_sessions", False)) ): raise ValueError("Interruption inference requires a semantics-v20 run") if mode in {"emergency-stop", "safe-hold"}: variants = { "emergency-stop": int( data.get("emergency_stop_session_variants", 0) ), "safe-hold": int(data.get("safe_hold_session_variants", 0)), } if ( active_semantics < 21 or not bool(data.get("independent_task_pools", False)) or variants[mode] <= 0 ): raise ValueError( f"{mode} inference requires an enabled semantics-v21 task pool" ) control_turns = [ turn for turn in turns if str(turn.get("control_intent", "")).strip() ] if len(control_turns) != 1 or str( control_turns[0].get("control_intent") ).strip() != mode: raise ValueError( f"{mode} scenario needs exactly one matching control command" ) if mode == "backchannel": if ( active_semantics < 22 or not bool(data.get("independent_task_pools", False)) or int(data.get("backchannel_session_variants", 0)) <= 0 ): raise ValueError( "Backchannel inference requires an enabled semantics-v22 pool" ) if mode in {"hesitation", "pause"}: variants = { "hesitation": int(data.get("hesitation_session_variants", 0)), "pause": int(data.get("pause_session_variants", 0)), } if ( active_semantics < 23 or not bool(data.get("independent_task_pools", False)) or variants[mode] <= 0 ): raise ValueError( f"{mode} inference requires an enabled semantics-v23 task pool" ) event = dict(payload.get("disfluency_event", {})) if str(event.get("subtype", "")).strip().lower() != subtype: raise ValueError( f"{mode} scenario has no matching disfluency_event: {path}" ) gap_steps = int(event.get("gap_steps", 0)) if not 1 <= gap_steps <= 7: raise ValueError( f"{mode} gap must use 1-7 Qwen steps, got {gap_steps}" ) event_turn = int(event.get("turn_index", -1)) if not 0 <= event_turn < len(turns): raise ValueError(f"Invalid disfluency event turn: {event_turn}") if str(turns[event_turn].get("disfluency_subtype", "")) != subtype: raise ValueError( "Scenario event turn does not carry the declared disfluency subtype" ) if active_semantics >= 24 and subtype == "self-repair": repair_style = str(event.get("repair_style", "")).strip().lower() if repair_style not in {"explicit-cue", "implicit-restart"}: raise ValueError( "Semantics-v24 self-repair scenario must declare " f"repair_style, got {repair_style!r}" ) marker_id = str(event.get("marker_id", "")).strip() if (repair_style == "explicit-cue") != bool(marker_id): raise ValueError( "Explicit self-repair requires a marker and implicit " "restart must not carry one" )
if split != "custom": split_seed = int(data.get("split_seed", -1)) val_ratio = float(data.get("val_ratio", -1.0)) namespace = str(data.get("split_source_namespace", "")).strip().strip("/") expected_namespace = str( payload.get("split_source_namespace", "") ).strip().strip("/") if split_seed != int(payload.get("split_seed", -2)): raise ValueError("Scenario/run split_seed mismatch") if abs(val_ratio - float(payload.get("val_ratio", -2.0))) > 1e-12: raise ValueError("Scenario/run val_ratio mismatch") if not namespace or namespace != expected_namespace: raise ValueError("Scenario/run split namespace mismatch") for turn in turns: filename = str(turn.get("source_motion_filename", "")).strip() # Stop/hold utterances are control events, not new primitive # motions. Their TTS path is audited above and deliberately has # no train/val motion identity of its own. if not filename and ( str(turn.get("control_intent", "")).strip() or str(turn.get("backchannel_intent", "")).strip() ): continue if not filename: raise ValueError("Split-tagged scenario turn has no motion filename") observed = ( "val" if _source_is_val( _motion_source_id(namespace, filename), split_seed=split_seed, val_ratio=val_ratio, ) else "train" ) if observed != split: raise ValueError( f"Scenario source split mismatch: {filename} is {observed}, " f"scenario claims {split}" )
for turn in turns: audio_path = Path(str(turn["audio_path"])).expanduser().resolve() if not audio_path.is_file(): raise FileNotFoundError(f"Missing scenario audio: {audio_path}") return InferenceCase( name=str(payload["name"]), interaction_mode=mode, data_split=split, scenario_path=path.resolve(), scenario=payload, interaction_subtype=subtype, )
def load_cases( suite_path: Path, *, run_config: dict[str, Any], single_scenario: Path | None = None,) -> list[InferenceCase]: if single_scenario is not None: return [validate_scenario(single_scenario, run_config=run_config)] suite = _load_json(suite_path) if suite.get("format") not in { "hfd_multiturn_auto_infer_suite_v2", "hfd_multiturn_auto_infer_suite_v3", }: raise ValueError(f"Unsupported inference suite: {suite_path}") data = dict(run_config.get("data", {})) enabled_variants = { "turn-taking": int(data.get("turn_taking_session_variants", 0)), "interruption": int( data.get("command_interruption_session_variants", 0) ), "emergency-stop": int( data.get("emergency_stop_session_variants", 0) ), "safe-hold": int(data.get("safe_hold_session_variants", 0)), "backchannel": int(data.get("backchannel_session_variants", 0)), "hesitation": int(data.get("hesitation_session_variants", 0)), "pause": int(data.get("pause_session_variants", 0)), } enabled_modes = { mode for mode, variants in enabled_variants.items() if variants > 0 } cases: list[InferenceCase] = [] for item in suite.get("cases", []): item_mode = str(item["interaction_mode"]) if item_mode not in enabled_modes: continue scenario_path = Path(str(item["scenario_file"])) if not scenario_path.is_absolute(): scenario_path = (suite_path.parent / scenario_path).resolve() cases.append( validate_scenario( scenario_path, run_config=run_config, expected_mode=item_mode, expected_split=str(item["data_split"]), expected_subtype=str(item.get("interaction_subtype", "")), ) ) identities = { (case.interaction_mode, case.interaction_subtype, case.data_split) for case in cases } expected = set() for mode in enabled_modes: subtypes = ( ("filled-pause", "self-repair") if mode == "hesitation" else ("silent-pause",) if mode == "pause" else ("",) ) expected.update( (mode, subtype, split) for subtype in subtypes for split in ("train", "val") ) if identities != expected: raise ValueError( "Suite must contain train/val cases for every enabled task: " f"expected={expected} observed={identities}" ) return cases
def checkpoint_ready(path: Path) -> bool: required = ( path / "model.safetensors", path / "hfd_fused_delta_manifest.json", path / "full_duplex_source_boundary.json", ) if any(not item.is_file() or item.stat().st_size <= 0 for item in required): return False try: marker = _load_json(required[-1]) except Exception: return False return bool(marker.get("source_group_complete", False))
def ready_checkpoint_steps(run_dir: Path) -> list[int]: checkpoints = run_dir / "checkpoints" found: list[int] = [] for path in checkpoints.glob("ckpt_[0-9]*"): match = re.fullmatch(r"ckpt_([0-9]+)", path.name) if match and path.is_dir() and checkpoint_ready(path): found.append(int(match.group(1))) return sorted(found)
def visible_gpus() -> list[str]: configured = os.environ.get("HFD_INFER_GPUS", "").strip() if not configured: configured = os.environ.get("CUDA_VISIBLE_DEVICES", "").strip() if configured: values = [value.strip() for value in configured.split(",") if value.strip()] else: result = subprocess.run( ["nvidia-smi", "--query-gpu=index", "--format=csv,noheader"], check=False, text=True, capture_output=True, ) values = [line.strip() for line in result.stdout.splitlines() if line.strip()] if not values: raise RuntimeError("No inference GPU is visible") if len(values) != len(set(values)): raise ValueError(f"Duplicate GPU identifiers: {values}") return values
def _safe_component(value: str) -> str: return re.sub(r"[^A-Za-z0-9_.-]+", "_", value)
def case_result_dir(run_dir: Path, case: InferenceCase, step: int) -> Path: turns = list(case.scenario["turns"]) # ``infer_render_auto.sh`` historically sanitizes ``echo "$stem"`` with # ``tr -cs``. The terminating newline therefore becomes one trailing # underscore. Reproduce that established on-disk name here rather than # silently renaming or re-rendering every existing inference result. audio_stem = _safe_component(Path(str(turns[0]["audio_path"])).stem + "\n") sample_name = ( f"00_{_safe_component(case.name)}_{_safe_component(audio_stem)}_" f"session{len(turns)}turn" ) output_group = Path(case.interaction_mode) if case.interaction_mode == "hesitation": output_group /= ( "filled" if case.interaction_subtype == "filled-pause" else "self-repair" ) return ( run_dir / output_group / f"ckpt_{step}" / case.data_split / sample_name )
def case_settled(run_dir: Path, case: InferenceCase, step: int) -> bool: result_dir = case_result_dir(run_dir, case, step) return (result_dir / ".complete").is_file() or (result_dir / ".failed").is_file()
def case_failed(run_dir: Path, case: InferenceCase, step: int) -> bool: return (case_result_dir(run_dir, case, step) / ".failed").is_file()
def case_environment( run_dir: Path, case: InferenceCase, *, step: int, gpu: str,) -> dict[str, str]: payload = case.scenario turns = list(payload["turns"]) audio_paths = [str(Path(str(turn["audio_path"])).expanduser().resolve()) for turn in turns] environment = os.environ.copy() output_group = Path(case.interaction_mode) if case.interaction_mode == "hesitation": output_group /= ( "filled" if case.interaction_subtype == "filled-pause" else "self-repair" ) environment.update( { "CUDA_VISIBLE_DEVICES": gpu, "HFD_INFER_GPUS": gpu, "HFD_INFER_DEVICE": "cuda:0", "HFD_INFER_ONCE": "1", "HFD_INFER_EXACT_CHECKPOINT_STEP": str(step), "HFD_INFER_MIN_CHECKPOINT_STEP": str(step), "HFD_INFER_OUTPUT_ROOT": str(run_dir / output_group), "HFD_INFER_SAMPLE_PARENT": case.data_split, "HFD_INFER_SAMPLE_TAG": case.name, "HFD_INFER_SCENARIO_FILE": str(case.scenario_path), "HFD_INFER_AUDIO_PATHS": audio_paths[0], "HFD_INFER_ADDITIONAL_AUDIO_PATHS": ",".join(audio_paths[1:]), "HFD_INFER_INITIAL_IDLE_STEPS": str(payload["initial_idle_steps"]), "HFD_INFER_MOTION_FRAMES": str(payload["motion_frames_per_turn"]), "HFD_INFER_INTER_TURN_BACKGROUND_STEPS_BY_TURN": ",".join( str(int(value)) for value in payload["inter_turn_background_steps_by_turn"] ), "HFD_INFER_TERMINAL_BACKGROUND_STEPS": str( payload["terminal_background_steps"] ), } ) init_motion = str(payload.get("init_motion_dir", "")).strip() if init_motion: environment["HFD_INFER_INIT_MOTION_DIRS"] = init_motion return environment
def run_dynamic_queue( run_dir: Path, cases: list[InferenceCase], *, step: int, gpus: list[str],) -> None: pending = deque(case for case in cases if not case_settled(run_dir, case, step)) available = deque(gpus) running: dict[subprocess.Popen[bytes], tuple[InferenceCase, str]] = {} failures: list[str] = [] base_script = PROJECT_ROOT / "infer_render_auto.sh" while pending or running: while pending and available: case = pending.popleft() gpu = available.popleft() print( f"[suite] start ckpt_{step} {case.interaction_mode}/{case.data_split} " f"on GPU {gpu}", flush=True, ) process = subprocess.Popen( ["bash", str(base_script), str(run_dir)], cwd=PROJECT_ROOT, env=case_environment(run_dir, case, step=step, gpu=gpu), ) running[process] = (case, gpu) finished = [process for process in running if process.poll() is not None] if not finished: time.sleep(0.25) continue for process in finished: case, gpu = running.pop(process) available.append(gpu) if process.returncode != 0: failures.append( f"{case.interaction_mode}/{case.data_split} " f"exited {process.returncode}" ) elif case_failed(run_dir, case, step): failures.append( f"{case.interaction_mode}/{case.data_split} wrote .failed" ) elif not case_settled(run_dir, case, step): failures.append( f"{case.interaction_mode}/{case.data_split} wrote no marker" ) else: print( f"[suite] done ckpt_{step} " f"{case.interaction_mode}/{case.data_split} on GPU {gpu}", flush=True, ) if failures: raise RuntimeError( f"ckpt_{step} inference suite failed: " + "; ".join(failures) )
def main() -> None: if len(sys.argv) != 2: raise SystemExit(f"usage: {Path(sys.argv[0]).name} RUN_DIR") run_dir = Path(sys.argv[1]).expanduser().resolve() run_config_path = run_dir / "run_config.json" if not run_config_path.is_file(): raise SystemExit(f"Invalid HFD run directory: {run_dir}") run_config = _load_json(run_config_path) configured_suite = os.environ.get("HFD_MULTITURN_SUITE_FILE", "").strip() active_semantics = int( dict(run_config.get("train", {})).get( "full_duplex_semantics_version", 0, ) ) suite_path = Path( configured_suite or (DEFAULT_SUITE_V24 if active_semantics >= 24 else DEFAULT_SUITE_V23) ) suite_path = suite_path.expanduser().resolve() single_raw = os.environ.get("HFD_MULTITURN_SCENARIO_FILE", "").strip() single_scenario = Path(single_raw).expanduser().resolve() if single_raw else None cases = load_cases( suite_path, run_config=run_config, single_scenario=single_scenario, ) gpus = visible_gpus() check_interval = max(int(os.environ.get("HFD_INFER_CHECK_INTERVAL", "30")), 1) infer_once = _truthy(os.environ.get("HFD_INFER_ONCE")) exact_raw = os.environ.get("HFD_INFER_EXACT_CHECKPOINT_STEP", "").strip() exact_step = int(exact_raw) if exact_raw else None minimum_raw = os.environ.get("HFD_INFER_MIN_CHECKPOINT_STEP", "auto").strip() initial_steps = ready_checkpoint_steps(run_dir) if minimum_raw == "auto": minimum_step = initial_steps[-1] if initial_steps else 0 else: minimum_step = int(minimum_raw) print( f"AUTO INFER SUITE: cases={len(cases)} GPUs={','.join(gpus)} " f"min_step={minimum_step} exact_step={exact_step or 'none'}", flush=True, )
while True: ready = ready_checkpoint_steps(run_dir) if exact_step is not None: candidates = [exact_step] if exact_step in ready else [] else: candidates = [step for step in ready if step >= minimum_step] pending_steps = [ step for step in candidates if any(not case_settled(run_dir, case, step) for case in cases) ] if pending_steps: step = max(pending_steps) run_dynamic_queue(run_dir, cases, step=step, gpus=gpus) if infer_once or exact_step is not None: break else: failed = [ f"{case.interaction_mode}/{case.data_split}" for step in candidates for case in cases if case_failed(run_dir, case, step) ] if failed: raise RuntimeError( "Existing inference failure marker(s) require inspection or " f"cleanup before retry: {', '.join(failed)}" ) print(f"[{time.strftime('%F %T')}] no pending checkpoint", flush=True) if infer_once or exact_step is not None: break time.sleep(check_interval)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530#!/usr/bin/env python3from __future__ import annotations
import argparseimport jsonimport mathimport randomimport reimport shutilimport subprocessfrom pathlib import Pathfrom typing import List
import numpy as npimport torch
from psi.config.config import LaunchConfigfrom psi.data.seed.motion_repr import quat_inv_wxyz, quat_mul_wxyz, recover_seed_abs_from_textop_actionfrom psi.data.seed.progress import build_progress_conditionsfrom psi.models.psi0 import Psi0Modelfrom psi.utils import parse_args_to_tyro_config, seed_everything
from seed_text_to_motion import ( TARGET_FPS, build_model_states_from_abs, finite_difference, load_pose_from_motion_dir, load_source_frame_count, normalize_quaternion_rows, quaternion_angular_velocity, recover_seed_abs_from_textop_action_with_joint_delta, resolve_ckpt_step, sanitize_motion_name, should_decode_textop_joint_from_delta, write_csv, write_metadata,)
def cfg_get(obj, key: str, default=None): if isinstance(obj, dict): return obj.get(key, default) return getattr(obj, key, default)
def audio_data_cfg(launch_config: LaunchConfig, key: str = "audio"): return cfg_get(launch_config.data, key, launch_config.data)
def load_audio_array(video_path: Path, sampling_rate: int) -> np.ndarray: cmd = [ "ffmpeg", "-v", "error", "-i", str(video_path), "-ac", "1", "-ar", str(sampling_rate), "-f", "f32le", "-", ] proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) if proc.returncode != 0: msg = proc.stderr.decode("utf-8", errors="ignore") raise RuntimeError(f"ffmpeg failed to decode audio from {video_path}: {msg}") audio = np.frombuffer(proc.stdout, dtype=np.float32).copy() if audio.size == 0: raise RuntimeError(f"No audio samples decoded from {video_path}") return audio
def audio_segment(audio: np.ndarray, sampling_rate: int, start_sec: float, duration_sec: float) -> np.ndarray: num_samples = max(1, int(round(duration_sec * sampling_rate))) start_sample = int(round(start_sec * sampling_rate)) end_sample = start_sample + num_samples
segment = np.zeros((num_samples,), dtype=np.float32) src_start = max(0, start_sample) src_end = min(audio.shape[0], end_sample) if src_end > src_start: dst_start = src_start - start_sample segment[dst_start : dst_start + (src_end - src_start)] = audio[src_start:src_end] return segment
def read_start_hold_seconds(motion_dir: Path, align_start_hold: bool) -> float: if not align_start_hold: return 0.0 info_path = motion_dir / "info.txt" if not info_path.exists(): return 0.0 text = info_path.read_text(encoding="utf-8", errors="ignore") match = re.search(r"start_hold_seconds:\s*([0-9.]+)", text) return float(match.group(1)) if match else 0.0
def resolve_motion_dir(root_dir: Path, motion_dir_arg: str) -> Path: motion_dir = Path(motion_dir_arg).expanduser() if motion_dir.is_absolute(): return motion_dir return root_dir / motion_dir
def resolve_video_path(video_dir: Path, motion_dir: Path, video_path_arg: str) -> Path: if video_path_arg: video_path = Path(video_path_arg).expanduser() if video_path.is_absolute(): return video_path return video_dir / video_path return video_dir / f"{motion_dir.name}.mp4"
def resolve_audio_path(audio_path: Path, extensions: str = ".wav,.flac,.mp3,.m4a,.aac,.ogg") -> Path: if audio_path.is_file(): return audio_path if not audio_path.is_dir(): return audio_path audio_exts = tuple( ext if ext.startswith(".") else f".{ext}" for ext in [part.strip().lower() for part in str(extensions).split(",")] if ext ) candidates = sorted(p for p in audio_path.iterdir() if p.is_file() and p.suffix.lower() in audio_exts) if not candidates: raise FileNotFoundError(f"No audio files found under {audio_path}") return random.choice(candidates)
def normalize_action_for_rtc(maxmin, action: np.ndarray) -> np.ndarray: action_min = np.asarray(maxmin.action_min, dtype=np.float32) action_max = np.asarray(maxmin.action_max, dtype=np.float32) ill_mask = np.abs(action_max - action_min) < 1e-4 * (np.abs(action_max) + np.abs(action_min) + 1e-8) action_max = action_max.copy() action_max[ill_mask] = 1.0 action_norm = np.where(ill_mask, action, (action - action_min) / (action_max - action_min) * 2 - 1) if bool(getattr(maxmin, "use_norm_mask", False)): action_norm_masks = np.asarray(maxmin.action_norm_masks, dtype=bool) action_norm = np.where(action_norm_masks, action_norm, action) return np.clip(action_norm, -1.0, 1.0).astype(np.float32)
def rollout_audio_motion( *, model: Psi0Model, maxmin, odim: int, device: str, instruction: str, audio: np.ndarray, audio_sampling_rate: int, audio_window_seconds: float, audio_left_context_seconds: float, full_audio: bool, start_hold_seconds: float, normalize_state: bool, textop_actions: bool, decode_textop_joint_from_delta: bool, num_past_frames: int, use_future_progress_embedding: bool, enable_rtc: bool, action_exec_horizon: int, rtc_max_delay: int, num_inference_steps: int, target_frames: int, init_abs_state: np.ndarray,) -> tuple[np.ndarray, np.ndarray, int]: horizon = int(model.action_horizon) exec_horizon = int(action_exec_horizon) if enable_rtc else horizon if exec_horizon <= 0 or exec_horizon > horizon: raise ValueError(f"Invalid action_exec_horizon={exec_horizon}, action_horizon={horizon}") rtc_delay = horizon - exec_horizon if enable_rtc and rtc_delay > 0 and rtc_delay >= int(rtc_max_delay): raise ValueError( f"RTC requires action_horizon - action_exec_horizon < max_delay, " f"got {horizon} - {exec_horizon} = {rtc_delay}, max_delay={rtc_max_delay}" ) if not textop_actions: raise ValueError("This audio inference path is for the 39D TextOp action checkpoint.") if target_frames <= 0: target_frames = max(exec_horizon, int(round(audio.shape[0] / float(audio_sampling_rate) * TARGET_FPS)))
num_chunks = int(math.ceil(float(target_frames) / float(exec_horizon))) current_abs = np.asarray(init_abs_state, dtype=np.float32).copy() state_horizon = int(num_past_frames) + 1 state_history: List[np.ndarray] = [current_abs.copy() for _ in range(state_horizon)] all_abs: List[np.ndarray] = [] all_delta: List[np.ndarray] = [] prev_actions_norm: np.ndarray | None = None remaining_frames = int(target_frames)
for _ in range(num_chunks): frame_cursor = target_frames - remaining_frames states = build_model_states_from_abs( state_history[-state_horizon:], textop_actions=textop_actions, odim=odim, ) if normalize_state: states = maxmin.normalize_state_func(states) states_t = torch.from_numpy(states).unsqueeze(0).to(device) future_progress_t = None if use_future_progress_embedding: _, future_progress = build_progress_conditions( frame_id=frame_cursor, total_frames=target_frames, action_horizon=horizon, ) future_progress_t = torch.from_numpy(future_progress[None]).to(device)
# <modify_full_audio> 和训练一致:full_audio=True时每个chunk都看到整段音频embedding,不再给time/progress。 if full_audio: audio_clip = audio.astype(np.float32) else: audio_start_sec = ( frame_cursor / float(TARGET_FPS) - float(start_hold_seconds) - float(audio_left_context_seconds) ) audio_clip = audio_segment(audio, audio_sampling_rate, audio_start_sec, audio_window_seconds)
with torch.inference_mode(): if enable_rtc and prev_actions_norm is not None and rtc_delay > 0: prev_rtc = np.concatenate( [ prev_actions_norm[exec_horizon:, :], np.zeros((exec_horizon, prev_actions_norm.shape[1]), dtype=np.float32), ], axis=0, ) prev_actions_t = torch.from_numpy(prev_rtc[None]).to(device) pred_norm = model.predict_action_with_training_rtc_flow( observations=None, states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, prev_actions=prev_actions_t, inference_delay=rtc_delay, max_delay=int(rtc_max_delay), audios=[audio_clip], future_progress=future_progress_t, )[0].float().cpu().numpy() else: pred_norm = model.predict_action( observations=None, states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, audios=[audio_clip], future_progress=future_progress_t, )[0].float().cpu().numpy()
pred_norm_clipped = np.clip(np.asarray(pred_norm, dtype=np.float32), -1.0, 1.0) chunk_pred = np.asarray(maxmin.denormalize(pred_norm_clipped), dtype=np.float32)
if decode_textop_joint_from_delta: chunk_abs = recover_seed_abs_from_textop_action_with_joint_delta(chunk_pred, current_abs) else: chunk_abs = recover_seed_abs_from_textop_action(chunk_pred, current_abs)
prev_abs = np.concatenate([current_abs[None, :], chunk_abs[:-1]], axis=0) joint_delta = chunk_abs[:, :29] - prev_abs[:, :29] root_pos_delta = chunk_abs[:, 29:32] - prev_abs[:, 29:32] root_quat_delta = quat_mul_wxyz(quat_inv_wxyz(prev_abs[:, 32:36]), chunk_abs[:, 32:36]) chunk_delta = np.concatenate([joint_delta, root_pos_delta, root_quat_delta], axis=1)
chunk_abs = normalize_quaternion_rows(chunk_abs.astype(np.float32)) if decode_textop_joint_from_delta: chunk_pred_for_rtc = chunk_pred.copy() chunk_pred_for_rtc[:, :29] = chunk_abs[:, :29] prev_actions_norm = normalize_action_for_rtc(maxmin, chunk_pred_for_rtc) else: prev_actions_norm = pred_norm_clipped.copy()
take = min(exec_horizon, remaining_frames) if take <= 0: break executed_abs = chunk_abs[:take] executed_delta = chunk_delta[:take].astype(np.float32) current_abs = executed_abs[-1].copy() for frame_abs in executed_abs: state_history.append(frame_abs.astype(np.float32).copy()) state_history = state_history[-state_horizon:] all_abs.append(executed_abs) all_delta.append(executed_delta) remaining_frames -= take
pred_abs = np.concatenate(all_abs, axis=0)[:target_frames] pred_delta = np.concatenate(all_delta, axis=0)[:target_frames] pred_abs = normalize_quaternion_rows(pred_abs.astype(np.float32)) return pred_abs, pred_delta, num_chunks
def write_audio_info( path: Path, *, audio_config_key: str, source_motion_dir: Path, video_path: Path, initial_pose_source: str, frames: int, textop_actions: bool, num_past_frames: int, enable_rtc: bool, action_exec_horizon: int, num_inference_steps: int, audio_sampling_rate: int, audio_window_seconds: float, full_audio: bool, instruction: str,) -> None: lines = [ "Motion Information: seed_audio_to_motion_inference", "===================================================", "", f"audio_config_key: {audio_config_key}", f"source_motion_dir: {source_motion_dir}", f"video_path: {video_path}", f"instruction: {instruction}", f"initial_pose_source: {initial_pose_source}", f"target_fps: {TARGET_FPS}", f"num_inference_steps: {num_inference_steps}", f"trained_with_textop_actions: {textop_actions}", f"num_past_frames: {num_past_frames}", f"rtc_enabled: {enable_rtc}", f"action_exec_horizon: {action_exec_horizon}", f"audio_sampling_rate: {audio_sampling_rate}", f"full_audio: {full_audio}", f"audio_window_seconds: {audio_window_seconds}", "output_root_quaternion: wxyz", "output_joint_angles: 29D", "output_root_position: xyz", "", f"frames: {frames}", "", ] path.write_text("\n".join(lines), encoding="utf-8")
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Seed audio->motion offline inference exporter") parser.add_argument("--run-dir", type=str, required=True) parser.add_argument("--ckpt-step", type=str, default="latest", help="integer step, 'latest', or 'best'") parser.add_argument("--output-dir", type=str, required=True) parser.add_argument("--motion-dir", type=str, required=True) parser.add_argument("--video-path", type=str, default="") parser.add_argument( "--audio-config-key", type=str, default="audio", choices=("audio", "audio_command"), help="Which launch_config.data audio section to use", ) parser.add_argument("--prompt", type=str, default="", help="Optional text instruction paired with the audio") parser.add_argument("--num-output-frames", type=int, default=0, help="0 means source motion length") parser.add_argument("--num-inference-steps", type=int, default=10) parser.add_argument("--device", type=str, default="cuda:0") parser.add_argument("--seed", type=int, default=42) parser.add_argument("--export-delta", action="store_true", default=False) parser.add_argument("--disable-rtc", action="store_true", default=False) parser.add_argument("--no-align-start-hold", dest="align_start_hold", action="store_false") parser.set_defaults(align_start_hold=True) return parser.parse_args()
def main() -> None: args = parse_args()
run_dir = Path(args.run_dir) output_dir = Path(args.output_dir) output_dir.mkdir(parents=True, exist_ok=True)
cfg_template: LaunchConfig = parse_args_to_tyro_config(run_dir / "argv.txt") # type: ignore launch_config = cfg_template.model_validate_json((run_dir / "run_config.json").read_text()) seed_everything(launch_config.seed or args.seed)
ckpt_step = resolve_ckpt_step(run_dir, args.ckpt_step) model = Psi0Model.from_pretrained(run_dir, ckpt_step, launch_config, device=args.device) model.text_only = False model.audio_only = True model.video_only = False model.to(args.device) model.eval()
audio_cfg = audio_data_cfg(launch_config, args.audio_config_key) data_root = Path(cfg_get(audio_cfg, "root_dir")) video_root = Path(cfg_get(audio_cfg, "video_dir", "")) motion_dir = resolve_motion_dir(data_root, args.motion_dir) video_path = resolve_audio_path( resolve_video_path(video_root, motion_dir, args.video_path), str(cfg_get(audio_cfg, "audio_file_extensions", ".wav,.flac,.mp3,.m4a,.aac,.ogg")), ) if not motion_dir.exists(): raise FileNotFoundError(f"motion_dir does not exist: {motion_dir}") if not video_path.exists(): raise FileNotFoundError(f"video_path does not exist: {video_path}")
maxmin = launch_config.data.transform.field odim = int(launch_config.model.odim) textop_actions = bool(getattr(launch_config.data.transform.repack, "textop_actions", False)) decode_textop_joint_from_delta = textop_actions and should_decode_textop_joint_from_delta(launch_config) num_past_frames = int(getattr(launch_config.data.transform.repack, "num_past_frames", 0)) use_future_progress_embedding = bool(getattr(launch_config.model, "use_future_progress_embedding", False)) enable_rtc = bool(getattr(launch_config.model, "rtc", False)) and (not args.disable_rtc) action_exec_horizon = int(getattr(launch_config.model, "action_exec_horizon", int(model.action_horizon))) rtc_max_delay = int(getattr(launch_config.model, "max_delay", 0)) audio_sampling_rate = int(cfg_get(audio_cfg, "audio_sampling_rate", 16000)) audio_window_seconds = float(cfg_get(audio_cfg, "audio_window_seconds", 1.0)) audio_left_context_seconds = float(cfg_get(audio_cfg, "audio_left_context_seconds", 0.0)) full_audio = bool(cfg_get(audio_cfg, "full_audio", False))
audio = load_audio_array(video_path, audio_sampling_rate) instruction = args.prompt.strip() x0 = load_pose_from_motion_dir(motion_dir) source_frames = load_source_frame_count(motion_dir) target_frames = int(args.num_output_frames) if args.num_output_frames > 0 else int(source_frames or 0) start_hold_seconds = read_start_hold_seconds(motion_dir, bool(args.align_start_hold))
pred_abs, pred_delta, rollout_chunks = rollout_audio_motion( model=model, maxmin=maxmin, odim=odim, device=args.device, instruction=instruction, audio=audio, audio_sampling_rate=audio_sampling_rate, audio_window_seconds=audio_window_seconds, audio_left_context_seconds=audio_left_context_seconds, full_audio=full_audio, start_hold_seconds=start_hold_seconds, normalize_state=bool(getattr(maxmin, "normalize_state", False)), textop_actions=textop_actions, decode_textop_joint_from_delta=decode_textop_joint_from_delta, num_past_frames=num_past_frames, use_future_progress_embedding=use_future_progress_embedding, enable_rtc=enable_rtc, action_exec_horizon=action_exec_horizon, rtc_max_delay=rtc_max_delay, num_inference_steps=int(args.num_inference_steps), target_frames=target_frames, init_abs_state=x0, )
motion_name = sanitize_motion_name(motion_dir.name) sample_dir = output_dir / motion_name sample_dir.mkdir(parents=True, exist_ok=True)
joint_pos = pred_abs[:, :29] body_pos = pred_abs[:, 29:32] body_quat = pred_abs[:, 32:36]
dt = 1.0 / float(TARGET_FPS) joint_vel = finite_difference(joint_pos, dt) body_lin_vel = finite_difference(body_pos, dt) body_ang_vel = quaternion_angular_velocity(body_quat, dt)
write_csv(sample_dir / "joint_pos.csv", joint_pos, [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "joint_vel.csv", joint_vel, [f"joint_vel_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos.csv", body_pos, ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat.csv", body_quat, ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_lin_vel.csv", body_lin_vel, ["body_0_vel_x", "body_0_vel_y", "body_0_vel_z"]) write_csv(sample_dir / "body_ang_vel.csv", body_ang_vel, ["body_0_angvel_x", "body_0_angvel_y", "body_0_angvel_z"]) np.save(sample_dir / "motion.npy", pred_abs)
if args.export_delta: write_csv(sample_dir / "joint_pos_delta.csv", pred_delta[:, :29], [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos_delta.csv", pred_delta[:, 29:32], ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat_delta.csv", pred_delta[:, 32:36], ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) np.save(sample_dir / "motion_delta.npy", pred_delta)
write_metadata(sample_dir / "metadata.txt", motion_name, int(pred_abs.shape[0])) write_audio_info( sample_dir / "info.txt", audio_config_key=str(args.audio_config_key), source_motion_dir=motion_dir, video_path=video_path, initial_pose_source=str(motion_dir), frames=int(pred_abs.shape[0]), textop_actions=textop_actions, num_past_frames=int(num_past_frames), enable_rtc=enable_rtc, action_exec_horizon=int(action_exec_horizon), num_inference_steps=int(args.num_inference_steps), audio_sampling_rate=int(audio_sampling_rate), audio_window_seconds=float(audio_window_seconds), full_audio=bool(full_audio), instruction=instruction, )
for src_name, dst_name in (("info.txt", "info_source.txt"), ("metadata.txt", "metadata_source.txt")): src_path = motion_dir / src_name if src_path.exists(): shutil.copy2(src_path, sample_dir / dst_name)
sample_meta = { "run_dir": str(run_dir), "ckpt_step": ckpt_step, "audio_config_key": str(args.audio_config_key), "instruction": instruction, "source_motion_dir": str(motion_dir), "video_path": str(video_path), "output_dir": str(sample_dir), "num_output_frames": int(pred_abs.shape[0]), "rollout_chunks": int(rollout_chunks), "textop_actions": textop_actions, "decode_textop_joint_from_delta": decode_textop_joint_from_delta, "num_past_frames": int(num_past_frames), "enable_rtc": enable_rtc, "action_exec_horizon": int(action_exec_horizon), "audio_sampling_rate": int(audio_sampling_rate), "full_audio": bool(full_audio), "audio_window_seconds": float(audio_window_seconds), "audio_left_context_seconds": float(audio_left_context_seconds), "start_hold_seconds": float(start_hold_seconds), } (sample_dir / "infer_meta.json").write_text(json.dumps(sample_meta, ensure_ascii=False, indent=2), encoding="utf-8") (output_dir / "manifest.json").write_text( json.dumps({"samples": [sample_meta]}, ensure_ascii=False, indent=2), encoding="utf-8", ) print(f"[OK] audio sample -> {sample_dir}") print(f"[DONE] wrote manifest: {output_dir / 'manifest.json'}")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504#!/usr/bin/env python3from __future__ import annotations
import argparseimport jsonimport mathimport shutilfrom pathlib import Pathfrom typing import List
import numpy as npimport pandas as pdimport torchimport torch.nn as nnfrom safetensors import safe_open
from psi.config.config import LaunchConfigfrom psi.data.seed.motion_repr import ( build_seed_textop_action, quat_inv_wxyz, quat_mul_wxyz, recover_seed_abs_from_textop_action,)from psi.data.seed.progress import build_progress_conditionsfrom psi.models.motion_distill import MotionDistillPsi0Modelfrom psi.utils import parse_args_to_tyro_config, seed_everything
from seed_text_to_motion import ( TARGET_FPS, build_model_states_from_abs, finite_difference, load_source_frame_count, normalize_quaternion_rows, quaternion_angular_velocity, recover_seed_abs_from_textop_action_with_joint_delta, resolve_ckpt_step, sanitize_motion_name, should_decode_textop_joint_from_delta, write_csv, write_metadata,)
def resolve_checkpoint_dir(run_dir: Path, ckpt_step: int | str) -> Path: if str(ckpt_step) in {"best", "best_ckpt"}: ckpt_dir = run_dir / "checkpoints" / "best_ckpt" else: ckpt_dir = run_dir / "checkpoints" / f"ckpt_{ckpt_step}" if not ckpt_dir.exists(): root_ckpt_dir = run_dir / f"ckpt_{ckpt_step}" if root_ckpt_dir.exists(): ckpt_dir = root_ckpt_dir if not ckpt_dir.exists(): raise FileNotFoundError(f"Checkpoint dir does not exist: {ckpt_dir}") return ckpt_dir
def load_selected_checkpoint_state(ckpt_dir: Path, prefixes: tuple[str, ...]) -> dict[str, torch.Tensor]: model_path = ckpt_dir / "model.safetensors" index_path = ckpt_dir / "model.safetensors.index.json" shard_paths: list[Path]
if index_path.exists(): weight_map = json.loads(index_path.read_text()).get("weight_map", {}) shard_paths = sorted( {ckpt_dir / shard for key, shard in weight_map.items() if key.startswith(prefixes)} ) elif model_path.exists(): shard_paths = [model_path] else: raise FileNotFoundError(f"No safetensors checkpoint found under {ckpt_dir}")
state_dict: dict[str, torch.Tensor] = {} for shard_path in shard_paths: with safe_open(str(shard_path), framework="pt", device="cpu") as f: for key in f.keys(): if key.startswith(prefixes): state_dict[key] = f.get_tensor(key) return state_dict
def build_noise_scheduler(launch_config: LaunchConfig): if launch_config.model.noise_scheduler == "ddpm": from diffusers.schedulers.scheduling_ddim import DDIMScheduler
return DDIMScheduler( num_train_timesteps=launch_config.model.train_diffusion_steps, beta_start=0.0001, beta_end=0.02, beta_schedule="squaredcos_cap_v2", clip_sample=True, set_alpha_to_one=True, steps_offset=0, prediction_type="epsilon", ) if launch_config.model.noise_scheduler == "flow": from diffusers.schedulers.scheduling_flow_match_euler_discrete import FlowMatchEulerDiscreteScheduler
return FlowMatchEulerDiscreteScheduler( num_train_timesteps=launch_config.model.train_diffusion_steps, ) raise ValueError(f"Unsupported noise scheduler: {launch_config.model.noise_scheduler}")
def load_teacher_reconstruct_model( run_dir: Path, ckpt_step: int | str, launch_config: LaunchConfig, device: str,) -> MotionDistillPsi0Model: ckpt_dir = resolve_checkpoint_dir(run_dir, ckpt_step) state_dict = load_selected_checkpoint_state( ckpt_dir, prefixes=("action_header.", "motion_encoder."), ) model = MotionDistillPsi0Model( model_cfg=launch_config.model, vlm_model=nn.Module(), ) action_state = { key[len("action_header.") :]: value for key, value in state_dict.items() if key.startswith("action_header.") } motion_state = { key[len("motion_encoder.") :]: value for key, value in state_dict.items() if key.startswith("motion_encoder.") } if not action_state: raise ValueError(f"No action_header weights found in {ckpt_dir}") if not motion_state: raise ValueError(f"No motion_encoder weights found in {ckpt_dir}") model.action_header.load_state_dict(action_state, strict=True) model.motion_encoder.load_state_dict(motion_state, strict=True) model.noise_scheduler = build_noise_scheduler(launch_config) model.action_horizon = int(launch_config.model.action_chunk_size) model.action_dim = int(launch_config.model.action_dim) model.device = device return model.to(device)
def load_motion_abs(motion_dir: Path) -> np.ndarray: joint = pd.read_csv(motion_dir / "joint_pos.csv").to_numpy(dtype=np.float32) body_pos = pd.read_csv(motion_dir / "body_pos.csv").to_numpy(dtype=np.float32) body_quat = pd.read_csv(motion_dir / "body_quat.csv").to_numpy(dtype=np.float32) if not (len(joint) == len(body_pos) == len(body_quat)): raise ValueError(f"Motion csv length mismatch under {motion_dir}") return np.concatenate([joint, body_pos, body_quat], axis=1).astype(np.float32)
def build_abs_action_chunk( motion_abs: np.ndarray, frame_id: int, horizon: int, sample_stride: int = 1,) -> np.ndarray: total_frames = int(motion_abs.shape[0]) actions: List[np.ndarray] = [] for step in range(horizon): raw_index = frame_id + (step + 1) * sample_stride actions.append(motion_abs[min(raw_index, total_frames - 1)]) return np.stack(actions, axis=0).astype(np.float32)
def build_teacher_action_features( actions_abs: np.ndarray, current_abs: np.ndarray, *, textop_actions: bool, action_dim: int,) -> np.ndarray: if textop_actions: actions = build_seed_textop_action(actions_abs[:, :36], current_abs[:36]) else: actions = actions_abs[:, :action_dim]
if actions.shape[-1] < action_dim: pad = np.zeros((actions.shape[0], action_dim - actions.shape[-1]), dtype=np.float32) actions = np.concatenate([actions, pad], axis=-1) if actions.shape[-1] != action_dim: raise ValueError(f"Teacher action dim mismatch: built {actions.shape[-1]}, expected {action_dim}") return actions.astype(np.float32)
def normalize_action_only(maxmin, actions: np.ndarray) -> np.ndarray: action_min = np.asarray(maxmin.action_min, dtype=np.float32) action_max = np.asarray(maxmin.action_max, dtype=np.float32) ill_mask = np.abs(action_max - action_min) < 1e-4 * ( np.abs(action_max) + np.abs(action_min) + 1e-8 ) denom = action_max - action_min denom[ill_mask] = 1.0 actions_norm = np.where( ill_mask, actions, (actions - action_min) / denom * 2 - 1, ) if bool(getattr(maxmin, "use_norm_mask", False)): action_norm_masks = np.asarray(maxmin.action_norm_masks, dtype=bool) actions_norm = np.where(action_norm_masks, actions_norm, actions) return np.clip(actions_norm, -1.0, 1.0).astype(np.float32)
def decode_action_chunk( chunk_pred: np.ndarray, current_abs: np.ndarray, *, textop_actions: bool, decode_textop_joint_from_delta: bool,) -> tuple[np.ndarray, np.ndarray]: if textop_actions: if decode_textop_joint_from_delta: chunk_abs = recover_seed_abs_from_textop_action_with_joint_delta(chunk_pred, current_abs) else: chunk_abs = recover_seed_abs_from_textop_action(chunk_pred, current_abs) prev_abs = np.concatenate([current_abs[None, :], chunk_abs[:-1]], axis=0) joint_delta = chunk_abs[:, :29] - prev_abs[:, :29] root_pos_delta = chunk_abs[:, 29:32] - prev_abs[:, 29:32] root_quat_delta = quat_mul_wxyz(quat_inv_wxyz(prev_abs[:, 32:36]), chunk_abs[:, 32:36]) chunk_delta = np.concatenate([joint_delta, root_pos_delta, root_quat_delta], axis=1) else: chunk_abs = chunk_pred[:, :36] first_delta = chunk_abs[0] - current_abs if chunk_abs.shape[0] > 1: rest_delta = chunk_abs[1:] - chunk_abs[:-1] chunk_delta = np.concatenate([first_delta[None, :], rest_delta], axis=0) else: chunk_delta = first_delta[None, :]
return normalize_quaternion_rows(chunk_abs.astype(np.float32)), chunk_delta.astype(np.float32)
def reconstruct_teacher_motion( *, model: MotionDistillPsi0Model, maxmin, motion_abs: np.ndarray, odim: int, action_dim: int, device: str, normalize_state: bool, textop_actions: bool, decode_textop_joint_from_delta: bool, num_past_frames: int, use_future_progress_embedding: bool, num_inference_steps: int, target_frames: int,) -> tuple[np.ndarray, np.ndarray, dict[str, float]]: horizon = int(model.action_horizon) if target_frames <= 0: target_frames = max(1, int(motion_abs.shape[0]) - 1)
num_chunks = int(math.ceil(float(target_frames) / float(horizon))) all_abs: List[np.ndarray] = [] all_delta: List[np.ndarray] = [] remaining_frames = int(target_frames)
for chunk_id in range(num_chunks): frame_id = chunk_id * horizon current_abs = motion_abs[min(frame_id, motion_abs.shape[0] - 1)].astype(np.float32) state_indices = [ max(0, frame_id - (int(num_past_frames) - t)) for t in range(int(num_past_frames) + 1) ] states = build_model_states_from_abs( [motion_abs[min(i, motion_abs.shape[0] - 1)] for i in state_indices], textop_actions=textop_actions, odim=odim, ) if normalize_state: states = maxmin.normalize_state_func(states)
actions_abs = build_abs_action_chunk(motion_abs, frame_id, horizon) teacher_actions = build_teacher_action_features( actions_abs, current_abs, textop_actions=textop_actions, action_dim=action_dim, ) teacher_actions_norm = normalize_action_only(maxmin, teacher_actions)
with torch.inference_mode(): states_t = torch.from_numpy(states).unsqueeze(0).to(device) teacher_actions_t = torch.from_numpy(teacher_actions_norm).unsqueeze(0).to(device) hidden_states = model.encode_motion_hidden(teacher_actions_t)
future_progress_t = None if use_future_progress_embedding: _, future_progress = build_progress_conditions( frame_id=frame_id, total_frames=int(motion_abs.shape[0]), action_horizon=horizon, ) future_progress_t = torch.from_numpy(future_progress[None]).to(device)
action_samples = torch.randn(1, horizon, action_dim, device=device) model.noise_scheduler.set_timesteps(num_inference_steps) for timestep in model.noise_scheduler.timesteps: batched_timestep = timestep.expand(1).to(device) model_output = model.action_from_hidden( hidden_states=hidden_states, attention_mask=None, action_samples=action_samples, states=states_t, timestep=batched_timestep, traj2ds=None, future_progress=future_progress_t, return_dict=True, ) action_samples = model.noise_scheduler.step( model_output=model_output.action, timestep=timestep, sample=action_samples, ).prev_sample
pred_norm = action_samples[0].float().cpu().numpy() pred_norm_clipped = np.clip(np.asarray(pred_norm, dtype=np.float32), -1.0, 1.0) chunk_pred = np.asarray(maxmin.denormalize(pred_norm_clipped), dtype=np.float32) chunk_abs, chunk_delta = decode_action_chunk( chunk_pred, current_abs, textop_actions=textop_actions, decode_textop_joint_from_delta=decode_textop_joint_from_delta, )
take = min(horizon, remaining_frames) all_abs.append(chunk_abs[:take]) all_delta.append(chunk_delta[:take]) remaining_frames -= take
pred_abs = np.concatenate(all_abs, axis=0)[:target_frames] pred_delta = np.concatenate(all_delta, axis=0)[:target_frames] pred_abs = normalize_quaternion_rows(pred_abs.astype(np.float32))
ref_abs = motion_abs[1 : 1 + pred_abs.shape[0], :36] if ref_abs.shape[0] == pred_abs.shape[0]: diff = pred_abs - ref_abs metrics = { "joint_mse": float(np.mean(diff[:, :29] ** 2)), "root_pos_mse": float(np.mean(diff[:, 29:32] ** 2)), "all_abs_mse": float(np.mean(diff ** 2)), } else: metrics = {} return pred_abs, pred_delta, metrics
def write_teacher_info( path: Path, *, source_motion_dir: Path, frames: int, textop_actions: bool, num_past_frames: int, num_inference_steps: int, metrics: dict[str, float],) -> None: lines = [ "Motion Information: motion_distill_teacher_reconstruct", "======================================================", "", f"source_motion_dir: {source_motion_dir}", f"target_fps: {TARGET_FPS}", f"num_inference_steps: {num_inference_steps}", f"trained_with_textop_actions: {textop_actions}", f"num_past_frames: {num_past_frames}", "condition: motion_encoder(ground_truth_actions)", "output_root_quaternion: wxyz", "output_joint_angles: 29D", "output_root_position: xyz", "", f"frames: {frames}", "", ] for key, value in metrics.items(): lines.append(f"{key}: {value:.8f}") path.write_text("\n".join(lines), encoding="utf-8")
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Motion-distill teacher motion reconstruction exporter") parser.add_argument("--run-dir", type=str, required=True) parser.add_argument("--ckpt-step", type=str, default="best", help="integer step, 'latest', or 'best'") parser.add_argument("--output-dir", type=str, required=True) parser.add_argument("--motion-dir", type=str, required=True) parser.add_argument("--num-output-frames", type=int, default=0, help="0 means source motion length minus one") parser.add_argument("--num-inference-steps", type=int, default=10) parser.add_argument("--device", type=str, default="cuda:0") parser.add_argument("--seed", type=int, default=42) parser.add_argument("--export-delta", action="store_true", default=False) return parser.parse_args()
def main() -> None: args = parse_args() run_dir = Path(args.run_dir) output_dir = Path(args.output_dir) motion_dir = Path(args.motion_dir) output_dir.mkdir(parents=True, exist_ok=True)
cfg_template: LaunchConfig = parse_args_to_tyro_config(run_dir / "argv.txt") # type: ignore launch_config = cfg_template.model_validate_json((run_dir / "run_config.json").read_text()) seed_everything(launch_config.seed or args.seed)
ckpt_step = resolve_ckpt_step(run_dir, args.ckpt_step) model = load_teacher_reconstruct_model(run_dir, ckpt_step, launch_config, device=args.device) model.eval()
motion_abs = load_motion_abs(motion_dir) source_frames = load_source_frame_count(motion_dir) or int(motion_abs.shape[0]) target_frames = int(args.num_output_frames) if args.num_output_frames > 0 else max(1, source_frames - 1)
maxmin = launch_config.data.transform.field odim = int(launch_config.model.odim) action_dim = int(getattr(launch_config.model, "action_dim", getattr(model, "action_dim", 39))) textop_actions = bool(getattr(launch_config.data.transform.repack, "textop_actions", False)) decode_textop_joint_from_delta = textop_actions and should_decode_textop_joint_from_delta(launch_config) num_past_frames = int(getattr(launch_config.data.transform.repack, "num_past_frames", 0)) use_future_progress_embedding = bool(getattr(launch_config.model, "use_future_progress_embedding", False))
pred_abs, pred_delta, metrics = reconstruct_teacher_motion( model=model, maxmin=maxmin, motion_abs=motion_abs, odim=odim, action_dim=action_dim, device=args.device, normalize_state=bool(getattr(maxmin, "normalize_state", False)), textop_actions=textop_actions, decode_textop_joint_from_delta=decode_textop_joint_from_delta, num_past_frames=num_past_frames, use_future_progress_embedding=use_future_progress_embedding, num_inference_steps=int(args.num_inference_steps), target_frames=target_frames, )
motion_name = sanitize_motion_name(motion_dir.name) sample_dir = output_dir / motion_name sample_dir.mkdir(parents=True, exist_ok=True)
joint_pos = pred_abs[:, :29] body_pos = pred_abs[:, 29:32] body_quat = pred_abs[:, 32:36]
dt = 1.0 / float(TARGET_FPS) joint_vel = finite_difference(joint_pos, dt) body_lin_vel = finite_difference(body_pos, dt) body_ang_vel = quaternion_angular_velocity(body_quat, dt)
write_csv(sample_dir / "joint_pos.csv", joint_pos, [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "joint_vel.csv", joint_vel, [f"joint_vel_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos.csv", body_pos, ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat.csv", body_quat, ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_lin_vel.csv", body_lin_vel, ["body_0_vel_x", "body_0_vel_y", "body_0_vel_z"]) write_csv(sample_dir / "body_ang_vel.csv", body_ang_vel, ["body_0_angvel_x", "body_0_angvel_y", "body_0_angvel_z"]) np.save(sample_dir / "motion.npy", pred_abs)
if args.export_delta: write_csv(sample_dir / "joint_pos_delta.csv", pred_delta[:, :29], [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos_delta.csv", pred_delta[:, 29:32], ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat_delta.csv", pred_delta[:, 32:36], ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) np.save(sample_dir / "motion_delta.npy", pred_delta)
write_metadata(sample_dir / "metadata.txt", motion_name, int(pred_abs.shape[0])) write_teacher_info( sample_dir / "info.txt", source_motion_dir=motion_dir, frames=int(pred_abs.shape[0]), textop_actions=textop_actions, num_past_frames=num_past_frames, num_inference_steps=int(args.num_inference_steps), metrics=metrics, )
for src_name, dst_name in (("info.txt", "info_source.txt"), ("metadata.txt", "metadata_source.txt")): src_path = motion_dir / src_name if src_path.exists(): shutil.copy2(src_path, sample_dir / dst_name)
sample_meta = { "run_dir": str(run_dir), "ckpt_step": ckpt_step, "source_motion_dir": str(motion_dir), "output_dir": str(sample_dir), "num_output_frames": int(pred_abs.shape[0]), "textop_actions": textop_actions, "decode_textop_joint_from_delta": decode_textop_joint_from_delta, "num_past_frames": int(num_past_frames), "num_inference_steps": int(args.num_inference_steps), "metrics": metrics, } (sample_dir / "infer_meta.json").write_text(json.dumps(sample_meta, ensure_ascii=False, indent=2), encoding="utf-8") (output_dir / "manifest.json").write_text( json.dumps({"samples": [sample_meta]}, ensure_ascii=False, indent=2), encoding="utf-8", ) print(f"[OK] teacher reconstruction -> {sample_dir}") if metrics: print("[METRICS] " + json.dumps(metrics, ensure_ascii=False))
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873#!/usr/bin/env python3from __future__ import annotations
import argparseimport jsonimport mathimport shutilfrom pathlib import Pathfrom typing import List
import numpy as npimport pandas as pdimport torch
from psi.config.config import LaunchConfigfrom psi.data.seed.motion_repr import ( SEED_ABS_DIM, SEED_TEXTOP_ACTION_DIM, TEXTOP_JOINT_DELTA, TEXTOP_ROOT_DELTA_LOCAL, TEXTOP_ROOT_HEIGHT, TEXTOP_ROOT_ROT6D_DELTA, quat_inv_wxyz, quat_mul_wxyz, build_seed_textop_state, recover_seed_abs_from_textop_action, rot6d_delta_to_quat, world_delta_from_local,)from psi.data.seed.progress import build_progress_conditionsfrom psi.data.seed.text_prompt import ( DEFAULT_SEED_TEXT_FIELDS, compose_seed_motion_prompt, compose_seed_motion_prompt_from_row,)from psi.models.psi0 import Psi0Modelfrom psi.utils import parse_args_to_tyro_config, seed_everything
DEFAULT_TEXT_FIELDS: List[str] = list(DEFAULT_SEED_TEXT_FIELDS)
TARGET_FPS = 50
def compose_instruction(row: pd.Series, text_fields: List[str]) -> str: return compose_seed_motion_prompt_from_row(row, text_fields)
def map_motion_dir(root_dir: Path, move_g1_path: str) -> Path: rel = str(move_g1_path).strip().replace("\\", "/") rel = rel.replace("g1/csv/", "g1/csv_sonic/") rel = rel.replace("/csv/", "/csv_sonic/") if rel.endswith(".csv"): rel = rel[:-4]
if rel.startswith("dataset/seed/"): rel = rel[len("dataset/seed/") :] if rel.startswith("seed/"): rel = rel[len("seed/") :]
p = Path(rel) if p.is_absolute(): return p return root_dir / p
def sanitize_motion_name(name: str) -> str: out = "".join(ch if (ch.isalnum() or ch in {"_", "-", "."}) else "_" for ch in name.strip()) out = out.strip("._") return out or "manual_prompt"
def normalize_quaternion_rows(motion_abs: np.ndarray) -> np.ndarray: if motion_abs.shape[1] < 36: return motion_abs q = motion_abs[:, 32:36] norm = np.linalg.norm(q, axis=1, keepdims=True) norm = np.where(norm < 1e-8, 1.0, norm) motion_abs[:, 32:36] = q / norm return motion_abs
def quat_multiply(q1: np.ndarray, q2: np.ndarray) -> np.ndarray: w1, x1, y1, z1 = q1 w2, x2, y2, z2 = q2 return np.array( [ w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2, w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2, w1 * y2 - x1 * z2 + y1 * w2 + z1 * x2, w1 * z2 + x1 * y2 - y1 * x2 + z1 * w2, ], dtype=np.float64, )
def quat_conjugate(q: np.ndarray) -> np.ndarray: return np.array([q[0], -q[1], -q[2], -q[3]], dtype=np.float64)
def quat_to_rotvec(q: np.ndarray) -> np.ndarray: q = q / max(np.linalg.norm(q), 1e-12) if q[0] < 0.0: q = -q vec = q[1:] sin_half = np.linalg.norm(vec) if sin_half < 1e-10: return np.zeros(3, dtype=np.float64) axis = vec / sin_half angle = 2.0 * np.arctan2(sin_half, q[0]) return axis * angle
def finite_difference(data: np.ndarray, dt: float) -> np.ndarray: if data.shape[0] < 2: return np.zeros_like(data, dtype=np.float64) edge_order = 2 if data.shape[0] > 2 else 1 return np.gradient(data, dt, axis=0, edge_order=edge_order)
def quaternion_angular_velocity(quat_wxyz: np.ndarray, dt: float) -> np.ndarray: ang_vel = np.zeros((quat_wxyz.shape[0], 3), dtype=np.float64) if quat_wxyz.shape[0] < 2: return ang_vel
for i in range(quat_wxyz.shape[0] - 1): dq = quat_multiply(quat_wxyz[i + 1], quat_conjugate(quat_wxyz[i])) ang_vel[i] = quat_to_rotvec(dq) / dt
ang_vel[-1] = ang_vel[-2] return ang_vel
def write_csv(path: Path, array: np.ndarray, headers: List[str]) -> None: np.savetxt( path, np.asarray(array, dtype=np.float64), delimiter=",", header=",".join(headers), comments="", fmt="%.6f", )
def write_metadata(path: Path, motion_name: str, timesteps: int) -> None: path.write_text( "\n".join( [ f"Metadata for: {motion_name}", "==============================", "", "Body part indexes:", "[0]", "", f"Total timesteps: {timesteps}", "", ] ), encoding="utf-8", )
def write_info( path: Path, *, source_path: str, initial_pose_source: str, frames: int, use_delta_actions: bool, root_delta_actions: bool, textop_actions: bool, num_past_frames: int, enable_rtc: bool, action_exec_horizon: int, num_inference_steps: int,) -> None: lines = [ "Motion Information: seed_text_to_motion_inference", "==================================================", "", f"source_path: {source_path}", f"initial_pose_source: {initial_pose_source}", f"target_fps: {TARGET_FPS}", f"num_inference_steps: {num_inference_steps}", f"trained_with_delta_actions: {use_delta_actions}", f"trained_with_root_delta_actions: {root_delta_actions}", f"trained_with_textop_actions: {textop_actions}", f"num_past_frames: {num_past_frames}", f"rtc_enabled: {enable_rtc}", f"action_exec_horizon: {action_exec_horizon}", "output_root_quaternion: wxyz", "output_joint_angles: 29D", "output_root_position: xyz", "", f"frames: {frames}", "", ] path.write_text("\n".join(lines), encoding="utf-8")
def load_pose_from_motion_dir(motion_dir: Path) -> np.ndarray: joint = pd.read_csv(motion_dir / "joint_pos.csv").to_numpy(dtype=np.float32) body_pos = pd.read_csv(motion_dir / "body_pos.csv").to_numpy(dtype=np.float32) body_quat = pd.read_csv(motion_dir / "body_quat.csv").to_numpy(dtype=np.float32) return np.concatenate([joint[0], body_pos[0], body_quat[0]], axis=0).astype(np.float32)
def load_pose_from_npy(path: Path) -> np.ndarray: pose = np.load(path).astype(np.float32) if pose.ndim == 2: pose = pose[0] if pose.shape != (36,): raise ValueError(f"Expected init pose shape (36,) or (T,36), got {pose.shape} from {path}") return pose.astype(np.float32)
def resolve_motion_dir(data_root: Path, motion_dir_arg: str) -> Path: motion_dir = Path(motion_dir_arg).expanduser() if motion_dir.is_absolute(): return motion_dir return data_root / motion_dir
def load_initial_pose(root_dir: Path, row: pd.Series, restore_from_data: bool, strict: bool = False) -> np.ndarray: if not restore_from_data: if strict: # <modify_jerk> root-delta也必须有真实首帧,否则root轨迹会从zero累加跑偏。 raise ValueError("Delta/root-delta inference requires a real initial pose. Do not use --no-restore-from-data.") return np.zeros((36,), dtype=np.float32)
try: motion_dir = map_motion_dir(root_dir, str(row["move_g1_path"])) return load_pose_from_motion_dir(motion_dir) except Exception as exc: if strict: raise RuntimeError(f"Failed to load initial pose from metadata row: {exc}") from exc return np.zeros((36,), dtype=np.float32)
def load_source_frame_count(source_motion_dir: Path) -> int | None: try: joint = pd.read_csv(source_motion_dir / "joint_pos.csv") frames = int(len(joint)) if frames > 0: return frames except Exception: pass return None
def build_model_states_from_abs( state_history_abs: List[np.ndarray], *, textop_actions: bool, odim: int,) -> np.ndarray: states_abs = np.stack(state_history_abs, axis=0).astype(np.float32) states = build_seed_textop_state(states_abs[:, :SEED_ABS_DIM]) if textop_actions else states_abs if states.shape[-1] < odim: pad = np.zeros((states.shape[0], odim - states.shape[-1]), dtype=np.float32) states = np.concatenate([states, pad], axis=-1) if states.shape[-1] != odim: raise ValueError(f"Infer state dim mismatch: built {states.shape[-1]}D, model odim={odim}") return states.astype(np.float32)
def should_decode_textop_joint_from_delta(launch_config: LaunchConfig) -> bool: if SEED_TEXTOP_ACTION_DIM == 39: return False group_weight = getattr(getattr(launch_config, "train", None), "loss_group_weight", None) if group_weight is None: return False joint_abs_weight = float(getattr(group_weight, "joint_abs", 1.0)) joint_delta_weight = float(getattr(group_weight, "joint_delta", 1.0)) return joint_abs_weight == 0.0 and joint_delta_weight != 0.0
def recover_seed_abs_from_textop_action_with_joint_delta( features: np.ndarray, current_abs: np.ndarray,) -> np.ndarray: # breakpoint() # 当joint_abs不参与训练时,推理侧也改成用joint_delta递推关节,避免使用未监督的joint_abs通道。 features = np.asarray(features, dtype=np.float32) current_abs = np.asarray(current_abs, dtype=np.float32).copy() if features.shape[-1] != SEED_TEXTOP_ACTION_DIM: raise ValueError(f"Expected textop action dim {SEED_TEXTOP_ACTION_DIM}, got {features.shape[-1]}") if current_abs.shape[-1] != SEED_ABS_DIM: raise ValueError(f"Expected current_abs dim {SEED_ABS_DIM}, got {current_abs.shape[-1]}") if TEXTOP_JOINT_DELTA.stop == TEXTOP_JOINT_DELTA.start: return recover_seed_abs_from_textop_action(features, current_abs)
frames = [] prev_abs = current_abs.copy() for feat in features: joint_delta = feat[TEXTOP_JOINT_DELTA] root_delta_local = feat[TEXTOP_ROOT_DELTA_LOCAL] root_rot_delta = feat[TEXTOP_ROOT_ROT6D_DELTA] root_height = feat[TEXTOP_ROOT_HEIGHT][0]
joint_abs = prev_abs[:29] + joint_delta root_pos = prev_abs[29:32] + world_delta_from_local(prev_abs[32:36], root_delta_local) root_pos[2] = root_height rel_quat = rot6d_delta_to_quat(root_rot_delta) root_quat = quat_mul_wxyz(prev_abs[32:36], rel_quat)
frame = np.concatenate([joint_abs, root_pos.astype(np.float32), root_quat.astype(np.float32)], axis=0) frame = frame.astype(np.float32) frames.append(frame) prev_abs = frame
return np.stack(frames, axis=0).astype(np.float32)
def resolve_metadata_csv(data_root: Path, launch_config: LaunchConfig, metadata_csv_arg: str) -> Path | None: if metadata_csv_arg: metadata_csv = Path(metadata_csv_arg) elif hasattr(launch_config.data, "metadata_csv"): metadata_csv = Path(launch_config.data.metadata_csv) elif hasattr(launch_config.data, "text"): text_cfg = launch_config.data.text metadata_csv_value = text_cfg.get("metadata_csv") if isinstance(text_cfg, dict) else getattr(text_cfg, "metadata_csv", None) if metadata_csv_value is None: return None metadata_csv = Path(metadata_csv_value) else: return None if not metadata_csv.is_absolute(): metadata_csv = data_root / metadata_csv return metadata_csv
def resolve_text_data_root(launch_config: LaunchConfig) -> Path: if hasattr(launch_config.data, "root_dir"): return Path(launch_config.data.root_dir) if hasattr(launch_config.data, "text"): text_cfg = launch_config.data.text root_dir = text_cfg.get("root_dir") if isinstance(text_cfg, dict) else getattr(text_cfg, "root_dir", None) if root_dir: return Path(root_dir) raise AttributeError("run config has neither data.root_dir nor data.text.root_dir")
def load_prompt_initial_pose( *, args: argparse.Namespace, data_root: Path, metadata_csv: Path | None, use_delta_actions: bool, root_delta_actions: bool, textop_actions: bool,) -> tuple[np.ndarray, str]: if args.init_pose_npy: # <modify> 允许prompt模式显式指定36D初始姿态,避免delta模型从zero起步 init_path = Path(args.init_pose_npy).expanduser() if not init_path.is_absolute(): cwd_path = Path.cwd() / init_path data_path = data_root / init_path init_path = cwd_path if cwd_path.exists() else data_path return load_pose_from_npy(init_path), str(init_path)
if args.init_motion_dir: # <modify> 允许prompt模式显式指定SEED动作目录,用该动作第一帧作为初始姿态 motion_dir = resolve_motion_dir(data_root, args.init_motion_dir) return load_pose_from_motion_dir(motion_dir), str(motion_dir)
if args.restore_from_data: # <modify> 默认从metadata的start-index动作取真实首帧,不再静默使用zero if metadata_csv is None: raise ValueError( "Prompt inference needs an initial pose. Use --init-motion-dir or --init-pose-npy " "when the run config has no metadata_csv." ) prompt_metadata = pd.read_csv(metadata_csv) if len(prompt_metadata) == 0: raise ValueError(f"Empty metadata csv: {metadata_csv}") ref_index = min(max(0, int(args.start_index)), len(prompt_metadata) - 1) ref_row = prompt_metadata.iloc[ref_index] motion_dir = map_motion_dir(data_root, str(ref_row["move_g1_path"])) return load_pose_from_motion_dir(motion_dir), f"{motion_dir} (metadata index {ref_index})"
# <modify_jerk> hybrid root-delta prompt推理同样需要真实初始root。 if use_delta_actions or root_delta_actions or textop_actions: raise ValueError( "Delta/root-delta/TextOp prompt inference requires a real initial pose. " "Use --init-motion-dir, --init-pose-npy, or keep --restore-from-data." )
return np.zeros((36,), dtype=np.float32), "zero"
def rollout_motion( *, model: Psi0Model, maxmin, odim: int, device: str, instruction: str, text_only: bool, normalize_state: bool, use_delta_actions: bool, root_delta_actions: bool, textop_actions: bool, decode_textop_joint_from_delta: bool, num_past_frames: int, use_future_progress_embedding: bool, enable_rtc: bool, action_exec_horizon: int, rtc_max_delay: int, num_inference_steps: int, target_frames: int, init_abs_state: np.ndarray,) -> tuple[np.ndarray, np.ndarray, int]: horizon = int(model.action_horizon) exec_horizon = int(action_exec_horizon) if enable_rtc else horizon if exec_horizon <= 0 or exec_horizon > horizon: raise ValueError(f"Invalid action_exec_horizon={exec_horizon}, action_horizon={horizon}") rtc_delay = horizon - exec_horizon if enable_rtc and rtc_delay > 0 and rtc_delay >= int(rtc_max_delay): raise ValueError( f"RTC requires action_horizon - action_exec_horizon < max_delay, " f"got {horizon} - {exec_horizon} = {rtc_delay}, max_delay={rtc_max_delay}" ) if target_frames <= 0: target_frames = exec_horizon # <modify> RTC推理按exec_horizon滚动;普通推理仍按完整action_horizon滚动 # 原逻辑:num_chunks = int(math.ceil(float(target_frames) / float(horizon))) num_chunks = int(math.ceil(float(target_frames) / float(exec_horizon)))
current_abs = np.asarray(init_abs_state, dtype=np.float32).copy() # <modify_states> 推理时维护和训练一致的多帧state历史,首个chunk用初始姿态重复填充。 state_horizon = int(num_past_frames) + 1 state_history: List[np.ndarray] = [current_abs.copy() for _ in range(state_horizon)] all_abs: List[np.ndarray] = [] all_delta: List[np.ndarray] = [] prev_actions_norm: np.ndarray | None = None remaining_frames = int(target_frames)
for _ in range(num_chunks): generated_frames = int(target_frames - remaining_frames) # <modify_states> 使用最近To帧state作为输入;保持shape(B, To, Ds)。 # 原逻辑: # states = current_abs.reshape(1, odim).astype(np.float32) states = build_model_states_from_abs( state_history[-state_horizon:], textop_actions=textop_actions, odim=odim, ) if normalize_state: states = maxmin.normalize_state_func(states) states_t = torch.from_numpy(states).unsqueeze(0).to(device) future_progress_t = None if use_future_progress_embedding: _, future_progress = build_progress_conditions( frame_id=generated_frames, total_frames=target_frames, action_horizon=horizon, ) future_progress_t = torch.from_numpy(future_progress[None]).to(device)
with torch.inference_mode(): if enable_rtc and prev_actions_norm is not None and rtc_delay > 0: # <modify> RTC推理把上一chunk尚未执行的尾部动作作为下一chunk的prefix条件 prev_rtc = np.concatenate( [ prev_actions_norm[exec_horizon:, :], np.zeros((exec_horizon, prev_actions_norm.shape[1]), dtype=np.float32), ], axis=0, ) prev_actions_t = torch.from_numpy(prev_rtc[None]).to(device) pred_norm = model.predict_action_with_training_rtc_flow( observations=None if text_only else [[]], states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, prev_actions=prev_actions_t, inference_delay=rtc_delay, max_delay=int(rtc_max_delay), future_progress=future_progress_t, )[0].float().cpu().numpy() else: pred_norm = model.predict_action( observations=None if text_only else [[]], states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, future_progress=future_progress_t, )[0].float().cpu().numpy()
# <modify> 训练侧ActionStateTransform会把normalized action裁剪到[-1,1],推理反归一化前也要保持同一范围。 # 原逻辑:chunk_pred = np.asarray(maxmin.denormalize(pred_norm), dtype=np.float32) pred_norm_clipped = np.clip(np.asarray(pred_norm, dtype=np.float32), -1.0, 1.0) chunk_pred = np.asarray(maxmin.denormalize(pred_norm_clipped), dtype=np.float32)
# <modify_textop_repr> TextOp训练目标先恢复到36D绝对姿态;root旋转delta在helper里按相对旋转6D解码。 if textop_actions: if decode_textop_joint_from_delta: chunk_abs = recover_seed_abs_from_textop_action_with_joint_delta(chunk_pred, current_abs) else: chunk_abs = recover_seed_abs_from_textop_action(chunk_pred, current_abs) prev_abs = np.concatenate([current_abs[None, :], chunk_abs[:-1]], axis=0) joint_delta = chunk_abs[:, :29] - prev_abs[:, :29] root_pos_delta = chunk_abs[:, 29:32] - prev_abs[:, 29:32] root_quat_delta = quat_mul_wxyz(quat_inv_wxyz(prev_abs[:, 32:36]), chunk_abs[:, 32:36]) chunk_delta = np.concatenate([joint_delta, root_pos_delta, root_quat_delta], axis=1) elif use_delta_actions: # <modify> delta action需要从current_abs累加成绝对姿态,支持多chunk滚动 # 原逻辑:把chunk_pred直接当绝对姿态,和delta训练目标不一致 chunk_delta = chunk_pred chunk_abs = np.cumsum(chunk_delta, axis=0) + current_abs[None, :] elif root_delta_actions: # <modify_jerk> hybrid action:关节直接用绝对预测,root 7维从当前姿态逐帧累加。 chunk_abs = chunk_pred.copy() root_abs = current_abs[29:36].astype(np.float32).copy() root_abs_seq = [] for root_delta in chunk_pred[:, 29:36]: root_abs = root_abs + root_delta quat_norm = np.linalg.norm(root_abs[3:7]) if quat_norm > 1e-8: root_abs[3:7] = root_abs[3:7] / quat_norm root_abs_seq.append(root_abs.copy()) chunk_abs[:, 29:36] = np.stack(root_abs_seq, axis=0)
first_joint_delta = chunk_abs[0, :29] - current_abs[:29] if chunk_abs.shape[0] > 1: rest_joint_delta = chunk_abs[1:, :29] - chunk_abs[:-1, :29] joint_delta = np.concatenate([first_joint_delta[None, :], rest_joint_delta], axis=0) else: joint_delta = first_joint_delta[None, :] chunk_delta = np.concatenate([joint_delta, chunk_pred[:, 29:36]], axis=1) else: chunk_abs = chunk_pred first_delta = chunk_abs[0] - current_abs if chunk_abs.shape[0] > 1: rest_delta = chunk_abs[1:] - chunk_abs[:-1] chunk_delta = np.concatenate([first_delta[None, :], rest_delta], axis=0) else: chunk_delta = first_delta[None, :]
chunk_abs = normalize_quaternion_rows(chunk_abs.astype(np.float32)) # <modify> TextOp且joint_abs未监督时,RTC prefix不能继续使用模型预测的joint_abs通道。 # 原逻辑:prev_actions_norm = np.asarray(pred_norm, dtype=np.float32).copy() # 这里用joint_delta还原后的关节绝对值回填0:29,再重新normalize,避免坏joint_abs污染下一chunk。 if textop_actions and decode_textop_joint_from_delta: chunk_pred_for_rtc = chunk_pred.copy() chunk_pred_for_rtc[:, :29] = chunk_abs[:, :29] # <modify> 这里不能直接调用maxmin.normalize,因为当前配置normalize_state=True时会要求data里有states。 action_min = np.asarray(maxmin.action_min, dtype=np.float32) action_max = np.asarray(maxmin.action_max, dtype=np.float32) ill_mask = np.abs(action_max - action_min) < 1e-4 * (np.abs(action_max) + np.abs(action_min) + 1e-8) action_max = action_max.copy() action_max[ill_mask] = 1.0 chunk_pred_for_rtc_norm = np.where( ill_mask, chunk_pred_for_rtc, (chunk_pred_for_rtc - action_min) / (action_max - action_min) * 2 - 1, ) if bool(getattr(maxmin, "use_norm_mask", False)): action_norm_masks = np.asarray(maxmin.action_norm_masks, dtype=bool) chunk_pred_for_rtc_norm = np.where(action_norm_masks, chunk_pred_for_rtc_norm, chunk_pred_for_rtc) prev_actions_norm = np.clip(chunk_pred_for_rtc_norm, -1, 1).astype(np.float32).copy() else: # <modify> RTC prefix也使用裁剪后的normalized action,避免把越界预测作为clean prefix条件。 # 原逻辑:prev_actions_norm = np.asarray(pred_norm, dtype=np.float32).copy() prev_actions_norm = pred_norm_clipped.copy() # <modify> RTC只导出本轮实际执行的前exec_horizon帧;普通模式exec_horizon等于horizon take = min(exec_horizon, remaining_frames) if take <= 0: break executed_abs = chunk_abs[:take] executed_delta = chunk_delta[:take].astype(np.float32) current_abs = executed_abs[-1].copy() # <modify_states> 每执行一步都推进state历史,下一chunk看到的是真实rollout历史而不是单帧。 for frame_abs in executed_abs: state_history.append(frame_abs.astype(np.float32).copy()) state_history = state_history[-state_horizon:] all_abs.append(executed_abs) all_delta.append(executed_delta) remaining_frames -= take
pred_abs = np.concatenate(all_abs, axis=0)[:target_frames] pred_delta = np.concatenate(all_delta, axis=0)[:target_frames] pred_abs = normalize_quaternion_rows(pred_abs.astype(np.float32)) return pred_abs, pred_delta, num_chunks
def resolve_ckpt_step(run_dir: Path, ckpt_step: str) -> int | str: if ckpt_step == "best": # <modify> 支持--ckpt-step best,直接读取checkpoints/best_ckpt目录。 best_ckpt = run_dir / "checkpoints" / "best_ckpt" if not best_ckpt.exists(): raise RuntimeError(f"No best_ckpt found under {run_dir / 'checkpoints'}") return "best_ckpt"
if ckpt_step != "latest": return int(ckpt_step)
ckpt_root = run_dir / "checkpoints" candidates = [] for p in ckpt_root.iterdir(): if p.is_dir() and p.name.startswith("ckpt_"): try: candidates.append(int(p.name.split("_")[-1])) except ValueError: continue if not candidates: raise RuntimeError(f"No ckpt_* found under {ckpt_root}") return max(candidates)
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Seed text->motion offline inference exporter") parser.add_argument("--run-dir", type=str, required=True) parser.add_argument("--ckpt-step", type=str, default="latest", help="integer step, 'latest', or 'best'") parser.add_argument("--output-dir", type=str, required=True) parser.add_argument("--num-samples", type=int, default=1) parser.add_argument("--start-index", type=int, default=0) parser.add_argument("--num-inference-steps", type=int, default=10) parser.add_argument("--device", type=str, default="cuda:0") parser.add_argument("--metadata-csv", type=str, default="") parser.add_argument("--prompt", type=str, default="", help="Direct text prompt for manual inference") parser.add_argument("--prompt-motion-name", type=str, default="manual_prompt") parser.add_argument("--init-motion-dir", type=str, default="", help="SEED csv_sonic motion dir used for prompt initial pose") parser.add_argument("--init-pose-npy", type=str, default="", help="36D pose npy, or Tx36 motion npy, used for prompt initial pose") parser.add_argument("--num-output-frames", type=int, default=0, help="0 means auto length") parser.add_argument("--seed", type=int, default=42) parser.add_argument("--restore-from-data", action="store_true", default=True) parser.add_argument("--no-restore-from-data", dest="restore_from_data", action="store_false") parser.add_argument("--export-delta", action="store_true", default=False) parser.add_argument("--disable-rtc", action="store_true", default=False) parser.add_argument( "--force-text-only", action="store_true", default=False, help="Use the same checkpoint but force text-only VLM inputs, even if run_config is audio-only.", ) return parser.parse_args()
def main() -> None: args = parse_args()
run_dir = Path(args.run_dir) output_dir = Path(args.output_dir) output_dir.mkdir(parents=True, exist_ok=True)
cfg_template: LaunchConfig = parse_args_to_tyro_config(run_dir / "argv.txt") # type: ignore launch_config = cfg_template.model_validate_json((run_dir / "run_config.json").read_text())
seed_everything(launch_config.seed or args.seed)
# 找到指定ckpt ckpt_step = resolve_ckpt_step(run_dir, args.ckpt_step) model = Psi0Model.from_pretrained(run_dir, ckpt_step, launch_config, device=args.device) if args.force_text_only: model.text_only = True model.audio_only = False model.video_only = False model.to(args.device) model.eval()
data_root = resolve_text_data_root(launch_config) prompt_mode = bool(args.prompt.strip()) use_delta_actions = bool(getattr(launch_config.data.transform.repack, "use_delta_actions", False)) # <modify_jerk> run_config里记录hybrid action模式:关节绝对,root delta。 root_delta_actions = bool(getattr(launch_config.data.transform.repack, "root_delta_actions", False)) # TextOp模式下训练目标是39D action/state;推理端用同一个decoder恢复为36D绝对动作。 textop_actions = bool(getattr(launch_config.data.transform.repack, "textop_actions", False)) decode_textop_joint_from_delta = textop_actions and should_decode_textop_joint_from_delta(launch_config) # <modify_states> 从run_config读取SEED多帧state配置;旧checkpoint默认退化为单帧state。 num_past_frames = int(getattr(launch_config.data.transform.repack, "num_past_frames", 0)) # <modify> run_config里model.rtc=True时默认使用RTC滚动推理;可用--disable-rtc关闭 enable_rtc = bool(getattr(launch_config.model, "rtc", False)) and (not args.disable_rtc) use_future_progress_embedding = bool(getattr(launch_config.model, "use_future_progress_embedding", False)) action_exec_horizon = int(getattr(launch_config.model, "action_exec_horizon", int(model.action_horizon))) rtc_max_delay = int(getattr(launch_config.model, "max_delay", 0)) metadata_csv = resolve_metadata_csv(data_root, launch_config, args.metadata_csv)
metadata = None if not prompt_mode: metadata = pd.read_csv(metadata_csv) start = max(0, args.start_index) end = min(len(metadata), start + max(0, args.num_samples)) if start >= end: raise ValueError(f"Empty sampling range: start={start}, end={end}, metadata_size={len(metadata)}") sample_indices = list(range(start, end)) else: sample_indices = [0]
text_only = bool(args.force_text_only) or bool(getattr(launch_config.data.transform.model, "text_only", False)) maxmin = launch_config.data.transform.field odim = int(launch_config.model.odim) action_dim = int(getattr(launch_config.model, "action_dim", getattr(model, "action_dim", SEED_TEXTOP_ACTION_DIM))) if textop_actions and (action_dim != SEED_TEXTOP_ACTION_DIM or odim != SEED_TEXTOP_ACTION_DIM): raise ValueError( f"TextOp infer/train dim mismatch: action_dim={action_dim}, odim={odim}, expected={SEED_TEXTOP_ACTION_DIM}" )
manifest = { "run_dir": str(run_dir), "ckpt_step": ckpt_step, "metadata_csv": str(metadata_csv) if metadata_csv is not None else "", "mode": "prompt" if prompt_mode else "metadata", "text_only": text_only, "action_dim": int(action_dim), "state_dim": int(odim), "use_delta_actions": use_delta_actions, "root_delta_actions": root_delta_actions, "textop_actions": textop_actions, "decode_textop_joint_from_delta": decode_textop_joint_from_delta, "num_past_frames": int(num_past_frames), "use_future_progress_embedding": bool(use_future_progress_embedding), "enable_rtc": enable_rtc, "action_exec_horizon": int(action_exec_horizon), "rtc_max_delay": int(rtc_max_delay), "num_inference_steps": int(args.num_inference_steps), "num_output_frames": int(args.num_output_frames), "export_delta": bool(args.export_delta), "samples": [], }
for idx in sample_indices: if prompt_mode: raw_instruction = args.prompt.strip() instruction = compose_seed_motion_prompt(raw_instruction) source_motion_dir = Path("manual_prompt") # <modify> prompt模式下delta推理不能再用zero初始姿态,默认从metadata的start-index动作取真实首帧 # 原逻辑:x0 = np.zeros((36,), dtype=np.float32) x0, initial_pose_source = load_prompt_initial_pose( args=args, data_root=data_root, metadata_csv=metadata_csv, use_delta_actions=use_delta_actions, root_delta_actions=root_delta_actions, textop_actions=textop_actions, ) auto_frames = max(int(model.action_horizon), 300) target_frames = int(args.num_output_frames) if args.num_output_frames > 0 else auto_frames motion_name = sanitize_motion_name(args.prompt_motion_name) sample_dir = output_dir / "g1" / "csv_sonic" / "manual" / motion_name else: assert metadata is not None row = metadata.iloc[idx] raw_instruction = "" instruction = compose_instruction(row, DEFAULT_TEXT_FIELDS) source_motion_dir = map_motion_dir(data_root, str(row.get("move_g1_path", ""))) # <modify> delta推理加载初始姿态失败时直接报错,避免静默退回zero x0 = load_initial_pose( data_root, row, restore_from_data=args.restore_from_data, strict=(use_delta_actions or root_delta_actions or textop_actions), ) initial_pose_source = str(source_motion_dir) if args.restore_from_data else "zero" source_frames = load_source_frame_count(source_motion_dir) if args.num_output_frames > 0: target_frames = int(args.num_output_frames) elif source_frames is not None: target_frames = source_frames else: target_frames = int(model.action_horizon) # Output folder keeps the same relative hierarchy as csv_sonic try: rel_dir = source_motion_dir.relative_to(data_root) except Exception: rel_dir = Path(f"sample_{idx:04d}") sample_dir = output_dir / rel_dir motion_name = source_motion_dir.name if source_motion_dir.name else f"sample_{idx:04d}"
pred_abs, pred_delta, rollout_chunks = rollout_motion( model=model, maxmin=maxmin, odim=odim, device=args.device, instruction=instruction, text_only=text_only, normalize_state=bool(getattr(maxmin, "normalize_state", False)), use_delta_actions=use_delta_actions, root_delta_actions=root_delta_actions, textop_actions=textop_actions, decode_textop_joint_from_delta=decode_textop_joint_from_delta, num_past_frames=num_past_frames, use_future_progress_embedding=use_future_progress_embedding, enable_rtc=enable_rtc, action_exec_horizon=action_exec_horizon, rtc_max_delay=rtc_max_delay, num_inference_steps=int(args.num_inference_steps), target_frames=target_frames, init_abs_state=x0, )
sample_dir.mkdir(parents=True, exist_ok=True)
joint_pos = pred_abs[:, :29] body_pos = pred_abs[:, 29:32] body_quat = pred_abs[:, 32:36]
dt = 1.0 / float(TARGET_FPS) joint_vel = finite_difference(joint_pos, dt) body_lin_vel = finite_difference(body_pos, dt) body_ang_vel = quaternion_angular_velocity(body_quat, dt)
# Main outputs: match csv_sonic naming/headers write_csv(sample_dir / "joint_pos.csv", joint_pos, [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "joint_vel.csv", joint_vel, [f"joint_vel_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos.csv", body_pos, ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat.csv", body_quat, ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_lin_vel.csv", body_lin_vel, ["body_0_vel_x", "body_0_vel_y", "body_0_vel_z"]) write_csv(sample_dir / "body_ang_vel.csv", body_ang_vel, ["body_0_angvel_x", "body_0_angvel_y", "body_0_angvel_z"])
np.save(sample_dir / "motion.npy", pred_abs)
# Optional delta outputs if args.export_delta: write_csv(sample_dir / "joint_pos_delta.csv", pred_delta[:, :29], [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos_delta.csv", pred_delta[:, 29:32], ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat_delta.csv", pred_delta[:, 32:36], ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) np.save(sample_dir / "motion_delta.npy", pred_delta)
write_metadata(sample_dir / "metadata.txt", motion_name, int(pred_abs.shape[0])) write_info( sample_dir / "info.txt", source_path=str(source_motion_dir), initial_pose_source=initial_pose_source, frames=int(pred_abs.shape[0]), use_delta_actions=use_delta_actions, root_delta_actions=root_delta_actions, textop_actions=textop_actions, num_past_frames=int(num_past_frames), enable_rtc=enable_rtc, action_exec_horizon=int(action_exec_horizon), num_inference_steps=int(args.num_inference_steps), )
# Keep source references if existing if not prompt_mode: src_info = source_motion_dir / "info.txt" src_meta = source_motion_dir / "metadata.txt" if src_info.exists(): shutil.copy2(src_info, sample_dir / "info_source.txt") if src_meta.exists(): shutil.copy2(src_meta, sample_dir / "metadata_source.txt")
sample_meta = { "sample_index": int(idx), "instruction": instruction, "raw_instruction": raw_instruction, "move_g1_path": "" if prompt_mode else str(metadata.iloc[idx].get("move_g1_path", "")), "source_motion_dir": str(source_motion_dir), "initial_pose_source": initial_pose_source, "num_past_frames": int(num_past_frames), "root_delta_actions": root_delta_actions, "textop_actions": textop_actions, "decode_textop_joint_from_delta": decode_textop_joint_from_delta, "enable_rtc": enable_rtc, "action_exec_horizon": int(action_exec_horizon), "output_dir": str(sample_dir), "num_output_frames": int(pred_abs.shape[0]), "rollout_chunks": int(rollout_chunks), } (sample_dir / "infer_meta.json").write_text(json.dumps(sample_meta, ensure_ascii=False, indent=2)) manifest["samples"].append(sample_meta) print(f"[OK] sample={idx} -> {sample_dir}")
(output_dir / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2)) print(f"[DONE] wrote manifest: {output_dir / 'manifest.json'}")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548#!/usr/bin/env python3from __future__ import annotations
import argparseimport jsonimport mathimport shutilfrom pathlib import Pathfrom typing import List
import numpy as npimport torch
from psi.config.config import LaunchConfigfrom psi.data.seed.motion_repr import quat_inv_wxyz, quat_mul_wxyz, recover_seed_abs_from_textop_actionfrom psi.data.seed.progress import build_progress_conditionsfrom psi.data.seed.seed_video_motion_dataset import ( _probe_video, load_video_array, load_video_clip_array, load_video_embed_cache, video_embed_cache_path,)from psi.models.motion_distill import MotionDistillPsi0Modelfrom psi.models.psi0 import Psi0Modelfrom psi.utils import parse_args_to_tyro_config, seed_everything
from seed_audio_to_motion import resolve_motion_dir, resolve_video_pathfrom seed_text_to_motion import ( TARGET_FPS, build_model_states_from_abs, finite_difference, load_pose_from_motion_dir, load_source_frame_count, normalize_quaternion_rows, quaternion_angular_velocity, recover_seed_abs_from_textop_action_with_joint_delta, resolve_ckpt_step, sanitize_motion_name, should_decode_textop_joint_from_delta, write_csv, write_metadata,)
def cfg_get(obj, key: str, default=None): if isinstance(obj, dict): return obj.get(key, default) return getattr(obj, key, default)
def video_data_cfg(launch_config: LaunchConfig, config_key: str = "video"): return cfg_get(launch_config.data, config_key, cfg_get(launch_config.data, "video", launch_config.data))
def rollout_video_motion( *, model: Psi0Model, maxmin, odim: int, device: str, video: np.ndarray | None, video_embed: dict | None, video_path: Path, instruction: str, video_size_pixels: int, video_sample_fps: float, video_decoder: str, video_pixel_cache_dtype: str, video_clip_mode: bool, video_clip_motion_fps: float, normalize_state: bool, textop_actions: bool, decode_textop_joint_from_delta: bool, num_past_frames: int, use_future_progress_embedding: bool, enable_rtc: bool, action_exec_horizon: int, rtc_max_delay: int, num_inference_steps: int, target_frames: int, init_abs_state: np.ndarray,) -> tuple[np.ndarray, np.ndarray, int]: horizon = int(model.action_horizon) exec_horizon = int(action_exec_horizon) if enable_rtc else horizon if exec_horizon <= 0 or exec_horizon > horizon: raise ValueError(f"Invalid action_exec_horizon={exec_horizon}, action_horizon={horizon}") rtc_delay = horizon - exec_horizon if enable_rtc and rtc_delay > 0 and rtc_delay >= int(rtc_max_delay): raise ValueError( f"RTC requires action_horizon - action_exec_horizon < max_delay, " f"got {horizon} - {exec_horizon} = {rtc_delay}, max_delay={rtc_max_delay}" ) if not textop_actions: raise ValueError("This video inference path is for the 39D TextOp action checkpoint.") if target_frames <= 0: target_frames = exec_horizon
num_chunks = int(math.ceil(float(target_frames) / float(exec_horizon))) current_abs = np.asarray(init_abs_state, dtype=np.float32).copy() state_horizon = int(num_past_frames) + 1 state_history: List[np.ndarray] = [current_abs.copy() for _ in range(state_horizon)] all_abs: List[np.ndarray] = [] all_delta: List[np.ndarray] = [] prev_actions_norm: np.ndarray | None = None remaining_frames = int(target_frames)
for _ in range(num_chunks): if video_clip_mode: chunk_index = len(all_abs) video_clip_start_sec = float(chunk_index * exec_horizon) / float(video_clip_motion_fps) video_clip_duration_sec = float(horizon) / float(video_clip_motion_fps) chunk_video, _, _ = load_video_clip_array( video_path, start_sec=video_clip_start_sec, duration_sec=video_clip_duration_sec, video_sample_fps=video_sample_fps, video_size_pixels=video_size_pixels, video_decoder=video_decoder, ) chunk_video_embed = None else: chunk_video = video chunk_video_embed = video_embed
frame_cursor = target_frames - remaining_frames states = build_model_states_from_abs( state_history[-state_horizon:], textop_actions=textop_actions, odim=odim, ) if normalize_state: states = maxmin.normalize_state_func(states) states_t = torch.from_numpy(states).unsqueeze(0).to(device) future_progress_t = None if use_future_progress_embedding: if video_clip_mode: # Training video_clip samples are cropped to one local horizon: # state frame 0 plus action frames 1..horizon. Keep progress local # at inference so action-token positions match the training distribution. progress_frame_id = 0 progress_total_frames = horizon + 1 else: progress_frame_id = frame_cursor progress_total_frames = target_frames _, future_progress = build_progress_conditions( frame_id=progress_frame_id, total_frames=progress_total_frames, action_horizon=horizon, ) future_progress_t = torch.from_numpy(future_progress[None]).to(device)
with torch.inference_mode(): if enable_rtc and prev_actions_norm is not None and rtc_delay > 0: prev_rtc = np.concatenate( [ prev_actions_norm[exec_horizon:, :], np.zeros((exec_horizon, prev_actions_norm.shape[1]), dtype=np.float32), ], axis=0, ) prev_actions_t = torch.from_numpy(prev_rtc[None]).to(device) pred_norm = model.predict_action_with_training_rtc_flow( observations=None, states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, prev_actions=prev_actions_t, inference_delay=rtc_delay, max_delay=int(rtc_max_delay), videos=[chunk_video] if chunk_video_embed is None else None, video_embeds=[chunk_video_embed] if chunk_video_embed is not None else None, video_paths=[str(video_path)], video_size_pixels=int(video_size_pixels), video_sample_fps=float(video_sample_fps), video_pixel_cache_dtype=video_pixel_cache_dtype, future_progress=future_progress_t, )[0].float().cpu().numpy() else: pred_norm = model.predict_action( observations=None, states=states_t, instructions=[instruction], num_inference_steps=num_inference_steps, traj2ds=None, videos=[chunk_video] if chunk_video_embed is None else None, video_embeds=[chunk_video_embed] if chunk_video_embed is not None else None, video_paths=[str(video_path)], video_size_pixels=int(video_size_pixels), video_sample_fps=float(video_sample_fps), video_pixel_cache_dtype=video_pixel_cache_dtype, future_progress=future_progress_t, )[0].float().cpu().numpy()
pred_norm_clipped = np.clip(np.asarray(pred_norm, dtype=np.float32), -1.0, 1.0) chunk_pred = np.asarray(maxmin.denormalize(pred_norm_clipped), dtype=np.float32)
if decode_textop_joint_from_delta: chunk_abs = recover_seed_abs_from_textop_action_with_joint_delta(chunk_pred, current_abs) else: chunk_abs = recover_seed_abs_from_textop_action(chunk_pred, current_abs)
prev_abs = np.concatenate([current_abs[None, :], chunk_abs[:-1]], axis=0) joint_delta = chunk_abs[:, :29] - prev_abs[:, :29] root_pos_delta = chunk_abs[:, 29:32] - prev_abs[:, 29:32] root_quat_delta = quat_mul_wxyz(quat_inv_wxyz(prev_abs[:, 32:36]), chunk_abs[:, 32:36]) chunk_delta = np.concatenate([joint_delta, root_pos_delta, root_quat_delta], axis=1)
chunk_abs = normalize_quaternion_rows(chunk_abs.astype(np.float32)) if decode_textop_joint_from_delta: chunk_pred_for_rtc = chunk_pred.copy() chunk_pred_for_rtc[:, :29] = chunk_abs[:, :29] from seed_audio_to_motion import normalize_action_for_rtc prev_actions_norm = normalize_action_for_rtc(maxmin, chunk_pred_for_rtc) else: prev_actions_norm = pred_norm_clipped.copy()
take = min(exec_horizon, remaining_frames) if take <= 0: break executed_abs = chunk_abs[:take] executed_delta = chunk_delta[:take].astype(np.float32) current_abs = executed_abs[-1].copy() for frame_abs in executed_abs: state_history.append(frame_abs.astype(np.float32).copy()) state_history = state_history[-state_horizon:] all_abs.append(executed_abs) all_delta.append(executed_delta) remaining_frames -= take
pred_abs = np.concatenate(all_abs, axis=0)[:target_frames] pred_delta = np.concatenate(all_delta, axis=0)[:target_frames] pred_abs = normalize_quaternion_rows(pred_abs.astype(np.float32)) return pred_abs, pred_delta, num_chunks
def write_video_info( path: Path, *, video_decoder: str, source_motion_dir: Path, video_path: Path, instruction: str, initial_pose_source: str, frames: int, textop_actions: bool, num_past_frames: int, enable_rtc: bool, action_exec_horizon: int, num_inference_steps: int, video_sample_fps: float, video_size_pixels: int, video_pixel_cache_dtype: str, video_embed_path: str, source_video_fps: float, video_duration_sec: float, full_video: bool, video_config_key: str, video_clip_motion_fps: float,) -> None: lines = [ "Motion Information: seed_video_to_motion_inference", "===================================================", "", f"video_decoder: {video_decoder}", f"video_config_key: {video_config_key}", f"source_motion_dir: {source_motion_dir}", f"video_path: {video_path}", f"instruction: {instruction}", f"initial_pose_source: {initial_pose_source}", f"target_fps: {TARGET_FPS}", f"num_inference_steps: {num_inference_steps}", f"trained_with_textop_actions: {textop_actions}", f"num_past_frames: {num_past_frames}", f"rtc_enabled: {enable_rtc}", f"action_exec_horizon: {action_exec_horizon}", f"video_sample_fps: {video_sample_fps}", f"video_size_pixels: {video_size_pixels}", f"video_pixel_cache_dtype: {video_pixel_cache_dtype}", f"video_embed_path: {video_embed_path}", f"source_video_fps: {source_video_fps}", f"video_duration_sec: {video_duration_sec}", f"full_video: {full_video}", f"video_clip_motion_fps: {video_clip_motion_fps}", "use_audio_in_video: False", "output_root_quaternion: wxyz", "output_joint_angles: 29D", "output_root_position: xyz", "", f"frames: {frames}", "", ] path.write_text("\n".join(lines), encoding="utf-8")
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Seed video->motion offline inference exporter") parser.add_argument("--run-dir", type=str, required=True) parser.add_argument("--ckpt-step", type=str, default="latest", help="integer step, 'latest', or 'best'") parser.add_argument("--output-dir", type=str, required=True) parser.add_argument("--motion-dir", type=str, required=True) parser.add_argument("--video-path", type=str, default="") parser.add_argument("--num-output-frames", type=int, default=0, help="0 means source motion length") parser.add_argument("--num-inference-steps", type=int, default=10) parser.add_argument("--device", type=str, default="cuda:0") parser.add_argument("--seed", type=int, default=42) parser.add_argument("--prompt", type=str, default="", help="Optional text instruction paired with the video") parser.add_argument("--export-delta", action="store_true", default=False) parser.add_argument("--disable-rtc", action="store_true", default=False) parser.add_argument("--video-config-key", type=str, default="video", help="data config key: video or video_clip") parser.add_argument("--video-clip", action="store_true", default=False, help="Use one aligned video clip per rollout chunk") parser.add_argument( "--video-pixel-cache-dtype", choices=("auto", "none", "fp16", "bf16"), default="auto", help="Match cached Qwen pixel-value quantization; auto uses fp16 for cached video_clip runs.", ) parser.add_argument( "--video-clip-motion-fps", type=float, default=0.0, help="Override motion fps used to align rollout chunks to video clips; <=0 infers it from source motion/video.", ) return parser.parse_args()
def main() -> None: args = parse_args()
run_dir = Path(args.run_dir) output_dir = Path(args.output_dir) output_dir.mkdir(parents=True, exist_ok=True)
cfg_template: LaunchConfig = parse_args_to_tyro_config(run_dir / "argv.txt") # type: ignore launch_config = cfg_template.model_validate_json((run_dir / "run_config.json").read_text()) seed_everything(launch_config.seed or args.seed)
ckpt_step = resolve_ckpt_step(run_dir, args.ckpt_step) model_cls = ( MotionDistillPsi0Model if hasattr(launch_config.model, "motion_distill_stage") else Psi0Model ) model = model_cls.from_pretrained(run_dir, ckpt_step, launch_config, device=args.device) model.text_only = False model.audio_only = False model.video_only = True model.to(args.device) model.eval()
video_cfg = video_data_cfg(launch_config, args.video_config_key) data_root = Path(cfg_get(video_cfg, "root_dir")) video_root = Path(cfg_get(video_cfg, "video_dir", "")) motion_dir = resolve_motion_dir(data_root, args.motion_dir) video_path = resolve_video_path(video_root, motion_dir, args.video_path) if not motion_dir.exists(): raise FileNotFoundError(f"motion_dir does not exist: {motion_dir}") if not video_path.exists(): raise FileNotFoundError(f"video_path does not exist: {video_path}")
maxmin = launch_config.data.transform.field odim = int(launch_config.model.odim) textop_actions = bool(getattr(launch_config.data.transform.repack, "textop_actions", False)) decode_textop_joint_from_delta = textop_actions and should_decode_textop_joint_from_delta(launch_config) num_past_frames = int(getattr(launch_config.data.transform.repack, "num_past_frames", 0)) use_future_progress_embedding = bool(getattr(launch_config.model, "use_future_progress_embedding", False)) enable_rtc = bool(getattr(launch_config.model, "rtc", False)) and (not args.disable_rtc) action_exec_horizon = int(getattr(launch_config.model, "action_exec_horizon", int(model.action_horizon))) rtc_max_delay = int(getattr(launch_config.model, "max_delay", 0)) video_sample_fps = float(cfg_get(video_cfg, "video_sample_fps", 1.0)) video_size_pixels = int(cfg_get(video_cfg, "video_size_pixels", 50176)) video_decoder = str(cfg_get(video_cfg, "video_decoder", "opencv")) if args.video_pixel_cache_dtype == "auto": video_pixel_cache_dtype = ( "fp16" if args.video_clip and bool(cfg_get(video_cfg, "use_omni_hidden_cache", False)) else "none" ) else: video_pixel_cache_dtype = str(args.video_pixel_cache_dtype) video_cfg_motion_fps = float(cfg_get(video_cfg, "motion_fps", TARGET_FPS)) video_embed_dir = "" if args.video_clip else str(cfg_get(video_cfg, "video_embed_dir", "")) instruction = args.prompt.strip()
video_embed = None video_embed_path = "" if (not args.video_clip) and video_embed_dir.strip(): cache_path = video_embed_cache_path( video_path, video_embed_dir, video_sample_fps=video_sample_fps, video_size_pixels=video_size_pixels, ) if cache_path.exists(): video_embed = load_video_embed_cache(cache_path) video_embed_path = str(cache_path)
if args.video_clip: _, _, source_video_fps, video_duration_sec = _probe_video(video_path) video = None elif video_embed is None: video, source_video_fps, video_duration_sec = load_video_array( video_path, video_sample_fps=video_sample_fps, video_size_pixels=video_size_pixels, video_decoder=video_decoder, ) else: video = None source_video_fps = float(video_embed["source_video_fps"]) video_duration_sec = float(video_embed["video_duration_sec"])
x0 = load_pose_from_motion_dir(motion_dir) source_frames = load_source_frame_count(motion_dir) target_frames = int(args.num_output_frames) if args.num_output_frames > 0 else int(source_frames or 0) if args.video_clip and float(args.video_clip_motion_fps) > 0: video_clip_motion_fps = float(args.video_clip_motion_fps) elif args.video_clip and video_cfg_motion_fps > 0: video_clip_motion_fps = float(video_cfg_motion_fps) elif args.video_clip and source_frames > 0 and video_duration_sec > 0: video_clip_motion_fps = float(source_frames) / float(video_duration_sec) else: video_clip_motion_fps = float(TARGET_FPS)
pred_abs, pred_delta, rollout_chunks = rollout_video_motion( model=model, maxmin=maxmin, odim=odim, device=args.device, video=video, video_embed=video_embed, video_path=video_path, instruction=instruction, video_size_pixels=video_size_pixels, video_sample_fps=video_sample_fps, video_decoder=video_decoder, video_pixel_cache_dtype=video_pixel_cache_dtype, video_clip_mode=bool(args.video_clip), video_clip_motion_fps=float(video_clip_motion_fps), normalize_state=bool(getattr(maxmin, "normalize_state", False)), textop_actions=textop_actions, decode_textop_joint_from_delta=decode_textop_joint_from_delta, num_past_frames=num_past_frames, use_future_progress_embedding=use_future_progress_embedding, enable_rtc=enable_rtc, action_exec_horizon=action_exec_horizon, rtc_max_delay=rtc_max_delay, num_inference_steps=int(args.num_inference_steps), target_frames=target_frames, init_abs_state=x0, )
motion_name = sanitize_motion_name(motion_dir.name) sample_dir = output_dir / motion_name sample_dir.mkdir(parents=True, exist_ok=True)
joint_pos = pred_abs[:, :29] body_pos = pred_abs[:, 29:32] body_quat = pred_abs[:, 32:36]
dt = 1.0 / float(TARGET_FPS) joint_vel = finite_difference(joint_pos, dt) body_lin_vel = finite_difference(body_pos, dt) body_ang_vel = quaternion_angular_velocity(body_quat, dt)
write_csv(sample_dir / "joint_pos.csv", joint_pos, [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "joint_vel.csv", joint_vel, [f"joint_vel_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos.csv", body_pos, ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat.csv", body_quat, ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_lin_vel.csv", body_lin_vel, ["body_0_vel_x", "body_0_vel_y", "body_0_vel_z"]) write_csv(sample_dir / "body_ang_vel.csv", body_ang_vel, ["body_0_angvel_x", "body_0_angvel_y", "body_0_angvel_z"]) np.save(sample_dir / "motion.npy", pred_abs)
if args.export_delta: write_csv(sample_dir / "joint_pos_delta.csv", pred_delta[:, :29], [f"joint_{i}" for i in range(29)]) write_csv(sample_dir / "body_pos_delta.csv", pred_delta[:, 29:32], ["body_0_x", "body_0_y", "body_0_z"]) write_csv(sample_dir / "body_quat_delta.csv", pred_delta[:, 32:36], ["body_0_w", "body_0_x", "body_0_y", "body_0_z"]) np.save(sample_dir / "motion_delta.npy", pred_delta)
write_metadata(sample_dir / "metadata.txt", motion_name, int(pred_abs.shape[0])) write_video_info( sample_dir / "info.txt", video_decoder=video_decoder, source_motion_dir=motion_dir, video_path=video_path, instruction=instruction, initial_pose_source=str(motion_dir), frames=int(pred_abs.shape[0]), textop_actions=textop_actions, num_past_frames=int(num_past_frames), enable_rtc=enable_rtc, action_exec_horizon=int(action_exec_horizon), num_inference_steps=int(args.num_inference_steps), video_sample_fps=float(video_sample_fps), video_size_pixels=int(video_size_pixels), video_pixel_cache_dtype=video_pixel_cache_dtype, video_embed_path=video_embed_path, source_video_fps=float(source_video_fps), video_duration_sec=float(video_duration_sec), full_video=not bool(args.video_clip), video_config_key=str(args.video_config_key), video_clip_motion_fps=float(video_clip_motion_fps), )
for src_name, dst_name in (("info.txt", "info_source.txt"), ("metadata.txt", "metadata_source.txt")): src_path = motion_dir / src_name if src_path.exists(): shutil.copy2(src_path, sample_dir / dst_name)
sample_meta = { "run_dir": str(run_dir), "ckpt_step": ckpt_step, "source_motion_dir": str(motion_dir), "video_path": str(video_path), "instruction": instruction, "output_dir": str(sample_dir), "num_output_frames": int(pred_abs.shape[0]), "rollout_chunks": int(rollout_chunks), "textop_actions": textop_actions, "decode_textop_joint_from_delta": decode_textop_joint_from_delta, "num_past_frames": int(num_past_frames), "enable_rtc": enable_rtc, "action_exec_horizon": int(action_exec_horizon), "video_sample_fps": float(video_sample_fps), "video_size_pixels": int(video_size_pixels), "video_pixel_cache_dtype": video_pixel_cache_dtype, "video_decoder": video_decoder, "video_embed_path": video_embed_path, "source_video_fps": float(source_video_fps), "video_duration_sec": float(video_duration_sec), "full_video": not bool(args.video_clip), "video_config_key": str(args.video_config_key), "video_clip_motion_fps": float(video_clip_motion_fps), "use_video_instruction": bool(cfg_get(video_cfg, "use_video_instruction", False)), "use_audio_in_video": False, } (sample_dir / "infer_meta.json").write_text(json.dumps(sample_meta, ensure_ascii=False, indent=2), encoding="utf-8") (output_dir / "manifest.json").write_text( json.dumps({"samples": [sample_meta]}, ensure_ascii=False, indent=2), encoding="utf-8", ) print(f"[OK] video sample -> {sample_dir}") print(f"[DONE] wrote manifest: {output_dir / 'manifest.json'}")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434#!/usr/bin/env python3"""Fixed train-only, closed-loop probes with durable prediction evidence.
Called synchronously at a source boundary by the third-party trainer. No GTpose after frame zero is fed to the model; no input waveform is re-mixed."""from __future__ import annotations
import argparseimport contextlibimport copyimport hashlibimport jsonimport osfrom pathlib import Pathimport randomimport shutilimport subprocessimport sysimport timeimport tracebackfrom typing import Any, Iterator, Sequenceimport wave
import numpy as npimport torch
PROJECT_ROOT = Path(__file__).resolve().parents[2]FPS = 50RATE = 16000PREVIEW_FPS = 25PREVIEW_WIDTH = 320PREVIEW_HEIGHT = 240PREVIEW_CPU_THREADS = 4PROFILES = ("single_short", "multi_single", "multi_babble", "mixed_short", "continuous", "same_voice_aside")
def _sha256(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(1024 * 1024), b""): digest.update(chunk) return digest.hexdigest()
def _write_json(path: Path, value: Any) -> None: temporary = path.with_suffix(path.suffix + ".tmp") temporary.write_text(json.dumps(value, indent=2, ensure_ascii=False, allow_nan=False) + "\n", encoding="utf-8") os.replace(temporary, path)
def validate_probe_recipes(recipes: Sequence[dict[str, Any]], *, probe_scope: str = "checkpoint") -> None: ids = [str(row["session_id"]) for row in recipes] if probe_scope not in {"checkpoint", "smoke"}: raise ValueError("Unknown probe scope") if any(row.get("split") != "train" for row in recipes): raise ValueError("Checkpoint probes may only use the selected training sessions") if probe_scope == "smoke": if not 1 <= len(ids) <= 12 or len(set(ids)) != len(ids): raise ValueError("Smoke probes require 1–12 distinct train sessions") if any(row.get("session_type") not in PROFILES for row in recipes): raise ValueError("Unknown third-party smoke profile") return if len(ids) != 12 or len(set(ids)) != 12: raise ValueError("Checkpoint probes require 12 distinct fixed train sessions") for profile in PROFILES: rows = [row for row in recipes if row.get("session_type") == profile] if len(rows) != 2: raise ValueError(f"Checkpoint probes require exactly two sessions for {profile}") languages = {row["background_assignment"]["language"] for row in rows} if languages != {"zh", "en"}: raise ValueError(f"Checkpoint probes need zh/en backgrounds for {profile}")
def load_frozen_probe(production_root: Path, recipe: dict[str, Any]) -> tuple[ np.ndarray, dict[str, np.ndarray], Path]: """Hash-verify and decode PCM directly; never normalize or re-sample.""" audio_path = (production_root / recipe["audio"]["path"]).resolve() timeline_path = (production_root / recipe["timeline"]["path"]).resolve() for path, expected in ((audio_path, recipe["audio"]["sha256"]), (timeline_path, recipe["timeline"]["file_sha256"])): if _sha256(path) != expected: raise RuntimeError(f"Frozen probe input hash changed: {path}") with wave.open(str(audio_path), "rb") as source: if (source.getnchannels(), source.getsampwidth(), source.getframerate()) != (1, 2, RATE): raise ValueError("Frozen probe audio must be mono 16 kHz PCM16") if source.getnframes() != int(recipe["audio"]["sample_count"]): raise ValueError("Frozen audio length no longer matches its recipe") waveform = np.frombuffer(source.readframes(source.getnframes()), dtype="<i2").astype(np.float32) waveform /= np.float32(32768.0) with np.load(timeline_path, allow_pickle=False) as stored: timeline = {key: stored[key].copy() for key in ("states", "control_label")} states, labels = timeline["states"], timeline["control_label"] if states.ndim != 2 or states.shape[1] != 36 or len(states) < 2: raise ValueError("Invalid frozen GT states") if labels.shape != (len(states),) or not np.isin(labels, (0, 1, 2)).all(): raise ValueError("Invalid frozen GT control labels") if not np.isfinite(states).all(): raise ValueError("Non-finite frozen GT states") return waveform, timeline, audio_path
def score_prediction(motion: np.ndarray, metadata: dict[str, Any], timeline: dict[str, np.ndarray], recipe: dict[str, Any]) -> dict[str, Any]: """Report pose errors and control decisions separately, with explicit alignment.""" predicted = np.asarray(motion, dtype=np.float64) states = np.asarray(timeline["states"], dtype=np.float64) labels = np.asarray(timeline["control_label"], dtype=np.int64) if predicted.ndim != 2 or predicted.shape[1] != 36 or not np.isfinite(predicted).all(): raise ValueError("Non-finite or malformed model prediction") pose_count = min(len(predicted), len(states) - 1) if pose_count <= 0: raise ValueError("No aligned predicted/GT poses") # Training actions at t predict t+1, while compact states store t. delta = predicted[:pose_count] - states[1:pose_count + 1] pred_quat = predicted[:pose_count, 32:36] gt_quat = states[1:pose_count + 1, 32:36] pred_norm = np.linalg.norm(pred_quat, axis=1) gt_norm = np.linalg.norm(gt_quat, axis=1) if np.any(pred_norm <= 1e-8) or np.any(gt_norm <= 1e-8): raise ValueError("Zero root quaternion in predicted/GT pose") quat_similarity = np.abs(np.sum(pred_quat * gt_quat, axis=1) / (pred_norm * gt_norm)) count = min(len(predicted), len(labels)) controls = np.full(len(predicted), -1, dtype=np.int64) events = metadata["control_events"] for index, event in enumerate(events): start = int(event["output_frame"]) end = int(events[index + 1]["output_frame"]) if index + 1 < len(events) else len(predicted) control_id = int(event["predicted_id"]) if not 0 <= start < end <= len(predicted) or control_id not in (0, 1, 2): raise ValueError("Invalid prediction control timeline") controls[start:end] = control_id if np.any(controls < 0): raise ValueError("Prediction control events do not cover the trajectory") controls = controls[:count] gt = labels[:count] confusion = np.zeros((3, 3), dtype=np.int64) np.add.at(confusion, (gt, controls), 1) # Background-only is NOT synonymous with idle: a valid earlier command can # still be executing. False activation is scored only when GT is non-motion. sample_starts = np.arange(count) * (RATE // FPS) background = np.zeros(count, dtype=bool) target = np.zeros(count, dtype=bool) for event in recipe.get("interference_events", []): background |= ((sample_starts < int(event["end_sample"])) & (sample_starts + RATE // FPS > int(event["start_sample"]))) for event in recipe.get("target_speech_events", []): target |= ((sample_starts < int(event["end_sample"])) & (sample_starts + RATE // FPS > int(event["start_sample"]))) background_nonmotion = background & ~target & (gt != 1) no_motion = gt != 1 motion_gt = gt == 1 def rate(values: np.ndarray, mask: np.ndarray) -> float | None: return float(values[mask].mean()) if mask.any() else None return { "pose_alignment": "predicted[t] compared with frozen state[t+1]; no DTW/realignment", "control_alignment": "control predicted at t compared with frozen control_label[t]", "pose_scored_frames": pose_count, "control_scored_frames": count, "prediction_frames": len(predicted), "unscored_prediction_tail_frames": len(predicted) - pose_count, "joint_mae_radians": float(np.abs(delta[:, :29]).mean()), "root_position_rmse_metres": float(np.sqrt(np.square(delta[:, 29:32]).sum(axis=1).mean())), "root_rotation_mae_radians": float((2 * np.arccos(np.clip(quat_similarity, 0, 1))).mean()), "control_accuracy": float((controls == gt).mean()), "control_confusion_rows_gt_columns_prediction": confusion.tolist(), "control_order": ["listen", "motion", "idle"], "nonmotion_gt_frames": int(no_motion.sum()), "false_motion_rate": rate(controls == 1, no_motion), "motion_gt_frames": int(motion_gt.sum()), "missed_motion_rate": rate(controls != 1, motion_gt), "background_only_nonmotion_gt_frames": int(background_nonmotion.sum()), "background_only_false_motion_rate": rate(controls == 1, background_nonmotion), "root_height_min_metres": float(predicted[:, 31].min()), "root_height_max_metres": float(predicted[:, 31].max()), "joint_step_rms_radians": float(np.sqrt(np.square(np.diff(predicted[:, :29], axis=0)).mean())), "interpretation": "Train memorization/robustness diagnostic, not held-out generalization or physics success.", }
@contextlib.contextmanagerdef preserve_training_state(model: Any, seed: int) -> Iterator[None]: """Probe must not alter dropout flags, RNG streams, or training scheduler.""" module_flags = [(module, module.training) for module in model.modules()] python_rng, numpy_rng = random.getstate(), np.random.get_state() torch_rng = torch.get_rng_state() cuda_rng = torch.cuda.get_rng_state_all() if torch.cuda.is_initialized() else None old_scheduler = getattr(model, "noise_scheduler", None) try: if old_scheduler is not None: model.noise_scheduler = copy.deepcopy(old_scheduler) random.seed(seed) np.random.seed(seed % (2 ** 32)) torch.manual_seed(seed) model.eval() with torch.inference_mode(): yield finally: for module, training in module_flags: module.training = training if old_scheduler is not None: model.noise_scheduler = old_scheduler random.setstate(python_rng) np.random.set_state(numpy_rng) torch.set_rng_state(torch_rng) if cuda_rng is not None: torch.cuda.set_rng_state_all(cuda_rng)
@contextlib.contextmanagerdef inference_bindings(model: Any, launch_config: Any, vlm_processor: Any) -> Iterator[None]: """Training keeps processor/scheduler on the trainer, unlike loaded inference.""" from diffusers.schedulers.scheduling_flow_match_euler_discrete import FlowMatchEulerDiscreteScheduler
missing = object() names = ("device", "vlm_processor", "noise_scheduler") previous = {name: getattr(model, name, missing) for name in names} cfg = getattr(launch_config, "model", None) if str(getattr(cfg, "noise_scheduler", "flow")) != "flow": raise ValueError("Closed-loop third-party probes require the flow scheduler") processor = vlm_processor if vlm_processor is not None else getattr(model, "vlm_processor", None) if processor is None: raise ValueError("In-process checkpoint probe requires trainer.vlm_processor") try: model.device = next(model.parameters()).device model.vlm_processor = processor model.noise_scheduler = FlowMatchEulerDiscreteScheduler( num_train_timesteps=int(getattr(cfg, "train_diffusion_steps", 1000))) yield finally: for name, value in previous.items(): if value is missing: if hasattr(model, name): delattr(model, name) else: setattr(model, name, value)
def _run(command: Sequence[str], log: Path, **kwargs: Any) -> None: with log.open("a", encoding="utf-8") as handle: result = subprocess.run(list(command), stdout=handle, stderr=subprocess.STDOUT, check=False, timeout=1800, **kwargs) if result.returncode: raise RuntimeError(f"Probe render failed (exit {result.returncode}); see {log}")
def render_prediction(sample_dir: Path, audio_path: Path) -> Path: """Low-cost CPU review video; the underlying predicted CSV remains 50 Hz.""" from scripts.data.render_hfd_third_party_gt import ( GMR_PYTHON, GMR_XML, RENDER_ROOT, _render_environment, ) from scripts.infer.mux_full_duplex_audio import probe as probe_media, stream from scripts.third_party_temp import project_temp_directory
environment = _render_environment("cpu", cpu_threads=PREVIEW_CPU_THREADS) scratch = str(project_temp_directory(PROJECT_ROOT)) environment.update({name: scratch for name in ("TMPDIR", "TMP", "TEMP", "SONIC_RENDER_TMPDIR")}) meta_path = sample_dir / "infer_meta.json" metadata = json.loads(meta_path.read_text(encoding="utf-8")) metadata["review_render"] = { "motion_fps": FPS, "video_fps": PREVIEW_FPS, "width": PREVIEW_WIDTH, "height": PREVIEW_HEIGHT, "cpu_threads": PREVIEW_CPU_THREADS, "purpose": "Checkpoint screening preview; full 50Hz predicted poses and metrics retained", "audio_policy": "Complete original mixed WAV, no time stretch or offset", } _write_json(meta_path, metadata) log = sample_dir / "render.log" _run([str(GMR_PYTHON), str(RENDER_ROOT / "scripts/batch_render_reference_motion_mujoco.py"), "--motion-dir", str(sample_dir), "--xml-path", str(GMR_XML), "--source-fps", str(FPS), "--target-fps", str(PREVIEW_FPS), "--width", str(PREVIEW_WIDTH), "--height", str(PREVIEW_HEIGHT), "--dof-order", "isaaclab", "--camera-distance", "2.5"], log, cwd=sample_dir, env=environment) # The shared renderer calls every CSV input 'reference'; rename it here so # users do not confuse the actual model prediction with the dataset's GT. silent = sample_dir / "prediction_silent.mp4" (sample_dir / "reference_motion.mp4").replace(silent) media = probe_media(silent) video_stream = stream(media, "video") with wave.open(str(audio_path), "rb") as source: audio_seconds = source.getnframes() / source.getframerate() video_seconds = float(video_stream.get("duration") or media["format"]["duration"]) if (video_stream["width"], video_stream["height"]) != (PREVIEW_WIDTH, PREVIEW_HEIGHT): raise RuntimeError("Checkpoint preview resolution drifted") if video_seconds < audio_seconds - 1e-6 or video_seconds - audio_seconds > 1 / PREVIEW_FPS + 1e-6: raise RuntimeError("Checkpoint preview would truncate or extend the original audio timeline") video = sample_dir / "prediction_with_audio.mp4" _run([sys.executable, str(PROJECT_ROOT / "scripts/infer/mux_full_duplex_audio.py"), "--video", str(silent), "--audio", str(audio_path), "--output", str(video), "--infer-meta", str(sample_dir / "infer_meta.json"), "--audio-is-timeline", "--expected-fps", str(PREVIEW_FPS)], log, env=environment) _run(["ffmpeg", "-v", "error", "-xerror", "-i", str(video), "-f", "null", "-"], log, env=environment) return video
def _aggregate(rows: Sequence[dict[str, Any]]) -> dict[str, Any]: keys = ("joint_mae_radians", "root_position_rmse_metres", "control_accuracy", "root_rotation_mae_radians", "false_motion_rate", "missed_motion_rate", "background_only_false_motion_rate") result: dict[str, Any] = {"averaging": "unweighted mean over available session metrics"} for key in keys: values = [row["metrics"][key] for row in rows if row["metrics"].get(key) is not None] result[key] = float(np.mean(values)) if values else None result[key + "_sessions"] = len(values) return result
def run_checkpoint_probes(model: Any, launch_config: Any, *, production_root: str | Path, recipes: Sequence[dict[str, Any]], output_root: str | Path, global_step: int, seed: int = 260930, num_inference_steps: int = 10, probe_scope: str = "checkpoint", vlm_processor: Any = None) -> dict[str, Any]: """Run all fixed 12 predictions; persist partial failure and re-raise errors.
The trainer must call only at a source boundary, and pass recipes from its frozen 300-session selection. output_root is normally run/checkpoint_probes. """ from scripts.infer import full_duplex_audio_to_motion as infer
validate_probe_recipes(recipes, probe_scope=probe_scope) if getattr(model, "control_condition_inference_mode", "hard") != "hard": raise ValueError("Third-party checkpoint probes require own hard control conditioning") if int(global_step) < 0 or int(num_inference_steps) <= 0: raise ValueError("Invalid probe step/inference steps") production_root = Path(production_root).resolve() output_root = Path(output_root).resolve() if not output_root.is_relative_to(PROJECT_ROOT.resolve()): raise ValueError("Probe outputs must remain inside HFD_lzk") step_dir = output_root / f"step_{int(global_step):08d}" step_dir.mkdir(parents=True, exist_ok=False) started = time.monotonic() report: dict[str, Any] = { "format": "hfd_third_party_checkpoint_probe_v1", "status": "running", "global_step": int(global_step), "seed": int(seed), "evaluation_split": "train_probe", "probe_scope": probe_scope, "fixed_session_ids": [row["session_id"] for row in recipes], "input_policy": "Exact frozen mixed PCM16; no remix, resampling, gain change, or video input", "rollout_policy": "Own hard control and predicted state/RTC; only initial GT pose supplied", "tail_policy": "Final 0.2s uses last predicted chunk tail, not a GT or stationary hold", "render_backend": "mesa_llvmpipe_cpu", "motion_fps": FPS, "review_video_fps": PREVIEW_FPS, "review_video_resolution": [PREVIEW_WIDTH, PREVIEW_HEIGHT], "render_cpu_threads": PREVIEW_CPU_THREADS, "samples": [], } _write_json(step_dir / "report.json", report) try: with preserve_training_state(model, seed), inference_bindings(model, launch_config, vlm_processor): for index, recipe in enumerate(recipes, 1): session_id = str(recipe["session_id"]) sample_dir = step_dir / f"{index:02d}_{recipe['session_type']}_{session_id[:12]}" sample_dir.mkdir() waveform, timeline, audio_path = load_frozen_probe(production_root, recipe) print(f"[train_probe] step={global_step} sample={index}/{len(recipes)} session={session_id}", flush=True) motion, metadata = infer.rollout_full_duplex( model=model, background_waveforms=[], waveform=waveform, prompt=infer.DEFAULT_COMMAND_PROMPT, source_id=f"train_probe:{session_id}", init_abs=timeline["states"][0].copy(), launch_config=launch_config, motion_frames=max(int(getattr(launch_config.data, "turn_transition_frames", 50)), 50) + 300, num_inference_steps=int(num_inference_steps), respect_control_token=True, max_listen_tail_steps=1, initial_idle_steps=0, seed=seed + index, frozen_audio_timeline=True, ) expected = int(round(len(waveform) * FPS / RATE)) if motion.shape != (expected, 36): raise RuntimeError("Frozen probe prediction does not cover its exact audio timeline") metrics = score_prediction(motion, metadata, timeline, recipe) metadata.update({"session_id": session_id, "global_step": int(global_step), "frozen_audio_path": str(audio_path), "frozen_audio_sha256": recipe["audio"]["sha256"], "artifact_role": "model_prediction_not_GT"}) infer.export_motion(sample_dir, motion) _write_json(sample_dir / "infer_meta.json", metadata) _write_json(sample_dir / "metrics.json", metrics) _write_json(sample_dir / "session_recipe.json", recipe) video = render_prediction(sample_dir, audio_path) row = {"session_id": session_id, "profile": recipe["session_type"], "background_language": recipe["background_assignment"]["language"], "background_sir_db": recipe.get("mix_metadata", {}).get("measured_background_sir_db"), "metrics": metrics, "video": str(video), "video_sha256": _sha256(video), "motion_sha256": _sha256(sample_dir / "motion.npy"), "full_video_decode_passed": True} report["samples"].append(row) _write_json(step_dir / "report.json", report) report["status"] = "complete" report["aggregate"] = _aggregate(report["samples"]) except BaseException as error: report["status"] = "failed" report["error"] = f"{type(error).__name__}: {error}" (step_dir / "failure.txt").write_text(traceback.format_exc(), encoding="utf-8") raise finally: report["elapsed_seconds"] = time.monotonic() - started _write_json(step_dir / "report.json", report) _write_json(output_root / "latest.json", {"report": str(step_dir / "report.json"), "status": report["status"], "global_step": global_step}) with (output_root / "history.jsonl").open("a", encoding="utf-8") as handle: handle.write(json.dumps({"global_step": global_step, "status": report["status"], "report": str(step_dir / "report.json"), "elapsed_seconds": report["elapsed_seconds"], "aggregate": report.get("aggregate", {})}, ensure_ascii=False) + "\n") lines = ["# Checkpoint 训练集闭环记录", "", f"step={global_step},状态:{report['status']}。", "这些是模型预测,不是 GT;训练集结果不代表泛化能力。", "", "审核视频为 320×240 / 25 fps;完整预测轨迹和指标保留 50 Hz,原始混音时间线不变。", "", "| 序号 | 类型 | 背景语言 | 控制准确率 | 视频 |", "|---|---|---|---:|---|"] for index, row in enumerate(report["samples"], 1): relative_video = Path(row["video"]).relative_to(step_dir) lines.append(f"| {index:02d} | {row['profile']} | {row['background_language']} | " f"{row['metrics']['control_accuracy']:.3f} | [模型预测]({relative_video}) |") if report.get("error"): lines.extend(["", "失败原因见 failure.txt;未生成的样本不得视为通过。"]) (step_dir / "README.md").write_text("\n".join(lines) + "\n", encoding="utf-8") return report
def check_renderer() -> dict[str, Any]: from scripts.data.render_hfd_third_party_gt import GMR_PYTHON, GMR_XML, RENDER_ROOT required = (GMR_PYTHON, GMR_XML, RENDER_ROOT / "scripts/batch_render_reference_motion_mujoco.py") missing = [str(path) for path in required if not path.is_file()] missing += [name for name in ("ffmpeg", "ffprobe") if not shutil.which(name)] if missing: raise FileNotFoundError(f"Missing checkpoint video renderer requirements: {missing}") return {"paths_present": True, "backend": "cpu", "render_execution_verified": False}
if __name__ == "__main__": if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check-renderer", action="store_true", required=True) parser.parse_args() print(json.dumps(check_renderer(), ensure_ascii=False))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172#!/usr/bin/env python3"""GPU-0 scale-stage closed-loop metrics on separately frozen train/validation."""from __future__ import annotations
import argparseimport hashlibimport jsonimport osfrom pathlib import Pathimport subprocessimport sysimport time
PROJECT = Path(__file__).resolve().parents[2]sys.path[:0] = [str(PROJECT), str(PROJECT / "src")]from scripts.third_party_strategy_plan import write_jsonfrom scripts.infer.third_party_metrics import aggregate, localfrom scripts.third_party_scale_plan import SEED, safe_relative_path
def read(path): return json.loads(Path(path).read_text())
def sample_seed(sid): return int(hashlib.sha256(f"{SEED}:rollout:{sid}".encode()).hexdigest()[:8], 16)
def recipes_for(manifest, ids): from psi.data.seed.third_party_frozen_dataset import read_jsonl, sha256_file selection = read(manifest) split = selection.get("split") if (selection.get("scaleup") is not True or split not in ("train", "validation") or len(set(ids)) != len(ids) or not set(ids) <= set(selection["session_ids"])): raise ValueError("Invalid scale evaluation split/IDs") root = local(selection["production_root"]) path = root / "manifests/session_recipes.jsonl" if sha256_file(path) != selection["recipe_manifest_sha256"]: raise ValueError("Evaluation recipe manifest changed") wanted, found = set(ids), {} for row in read_jsonl(path): if row["session_id"] in wanted: if row["session_id"] in found or row["split"] != split: raise ValueError("Evaluation crossed production split") for name in ("audio", "timeline"): safe_relative_path(root, row[name]["path"]) found[row["session_id"]] = row if set(found) != wanted: raise ValueError("Missing evaluation recipe") return root, found, split
def evaluate(source_run, step, manifest, output, *, full=False, workers=4, include_videos=False): if os.environ.get("CUDA_VISIBLE_DEVICES") != "0" or workers not in (1, 2, 4): raise RuntimeError("Use the managed single-GPU-0 scale launcher") source_run, manifest, output = map(local, (source_run, manifest, output)) if output.exists() or not output.is_relative_to(PROJECT / "runs"): raise ValueError("Fresh local evaluation directory required") selection = read(manifest) ids = list(selection["session_ids"] if full else selection["evaluation_session_ids"]) if include_videos: ids.extend(sid for sid in selection["video_session_ids"] if sid not in ids) if not ids or len(set(ids)) != len(ids): raise ValueError("Invalid fixed evaluation panel") output.mkdir(parents=True) (output / "samples").mkdir() task = {"source_run": str(source_run), "step": step, "manifest": str(manifest), "manifest_sha256": hashlib.sha256(manifest.read_bytes()).hexdigest(), "output": str(output), "split": selection["split"], "all_ids": ids} write_json(output / "identity.json", task) started = time.monotonic() children, logs = [], [] try: for rank in range(min(workers, len(ids))): path = output / f"worker_{rank}.json" write_json(path, {**task, "ids": ids[rank::workers]}) log = (output / f"worker_{rank}.log").open("x"); logs.append(log) children.append(subprocess.Popen([sys.executable, str(Path(__file__).resolve()), "--worker", str(path)], cwd=PROJECT, stdout=log, stderr=subprocess.STDOUT)) while any(child.poll() is None for child in children): if any(child.poll() not in (None, 0) for child in children): raise RuntimeError(f"Scale evaluation worker failed: {output}") time.sleep(1) if any(child.returncode != 0 for child in children): raise RuntimeError(f"Scale evaluation failed: {output}") finally: for child in children: if child.poll() is None: child.terminate() for child in children: try: child.wait(timeout=30) except subprocess.TimeoutExpired: child.kill(); child.wait() for log in logs: log.close() rows = [read(output / "samples" / sid / "result.json") for sid in ids] by_id = {r["session_id"]: r for r in selection["sessions"]} groups = {} for field in ("session_type", "background_language", "background_high"): groups[field] = {value: {"count": len(subset), **aggregate(subset)} for value in sorted({str(by_id[r["session_id"]][field]) for r in rows}) if (subset := [r for r in rows if str(by_id[r["session_id"]][field]) == value])} report = {"status": "complete", "step": step, "evaluation_split": selection["split"], "panel": "all_eligible" if full else "fixed_class_language_panel", "count": len(rows), "samples": rows, "aggregate": aggregate(rows), "groups": groups, "elapsed_seconds": time.monotonic() - started, "workers": workers, "rendered_videos": 0, "input_policy": "original full mixed WAV; no GT after initial pose; no optimizer updates", "seed_policy": "stable per session, independent of workers/checkpoint/panel size"} panel = set(selection["evaluation_session_ids"]) fixed = [r for r in rows if r["session_id"] in panel] report["fixed_panel_comparison"] = {"count": len(fixed), "aggregate": aggregate(fixed)} write_json(output / "report.json", report) return report
def worker(path): import numpy as np import torch from scripts.third_party_temp import configure_project_temp from scripts.infer import full_duplex_audio_to_motion as infer from scripts.infer.third_party_checkpoint_probe import load_frozen_probe, score_prediction, _sha256 from psi.models.full_duplex_psi0 import FullDuplexPsi0Model from psi.config.train.posttrain_third_party_config import DynamicLaunchConfig if os.environ.get("CUDA_VISIBLE_DEVICES") != "0": raise RuntimeError("Scale metrics require GPU0 isolation") configure_project_temp(PROJECT); torch.set_num_threads(2) task = read(local(path)); manifest = local(task["manifest"]) if hashlib.sha256(manifest.read_bytes()).hexdigest() != task["manifest_sha256"]: raise ValueError("Metric task selection changed") source = local(task["source_run"]) cfg = DynamicLaunchConfig.model_validate_json((source / "run_config.json").read_text()) infer.validate_contract(cfg) model = FullDuplexPsi0Model.from_streaming_checkpoint(source, task["step"], cfg, torch.device("cuda:0")) model.eval() root, recipes, split = recipes_for(manifest, task["ids"]) if split != task["split"]: raise ValueError("Metric task split changed") with torch.inference_mode(): for sid in task["ids"]: started = time.monotonic(); recipe = recipes[sid] dest = local(task["output"]) / "samples" / sid; dest.mkdir() waveform, timeline, audio = load_frozen_probe(root, recipe) seed = sample_seed(sid) motion, metadata = infer.rollout_full_duplex(model=model, background_waveforms=[], waveform=waveform, prompt=infer.DEFAULT_COMMAND_PROMPT, source_id=f"scale_{split}:{sid}", init_abs=timeline["states"][0].copy(), launch_config=cfg, motion_frames=max(int(cfg.data.turn_transition_frames), 50) + 300, num_inference_steps=10, respect_control_token=True, max_listen_tail_steps=1, initial_idle_steps=0, seed=seed, frozen_audio_timeline=True) if motion.shape != (round(len(waveform) * 50 / 16000), 36) or not np.isfinite(motion).all(): raise ValueError("Incomplete/nonfinite scale prediction") metrics = score_prediction(motion, metadata, timeline, recipe) metrics["interpretation"] = ("Held-out production validation; not physics success" if split == "validation" else "Training fit diagnostic, not held-out generalization") metadata.update(session_id=sid, global_step=task["step"], evaluation_split=split, frozen_audio_path=str(audio), frozen_audio_sha256=recipe["audio"]["sha256"], artifact_role="model_prediction_not_GT") infer.export_motion(dest, motion) for name, value in (("infer_meta", metadata), ("metrics", metrics), ("session_recipe", recipe)): write_json(dest / f"{name}.json", value) row = {"session_id": sid, "profile": recipe["session_type"], "split": split, "background_language": recipe["background_assignment"]["language"], "seed": seed, "metrics": metrics, "prediction_directory": str(dest), "motion_sha256": _sha256(dest / "motion.npy"), "render_status": "not_requested", "inference_seconds": time.monotonic() - started} write_json(dest / "result.json", row) print(json.dumps({"session": sid, "split": split, "seconds": row["inference_seconds"]}), flush=True)
if __name__ == "__main__": parser = argparse.ArgumentParser(); parser.add_argument("--worker", required=True) worker(parser.parse_args().worker)12345678910compute_environment: LOCAL_MACHINEdebug: falsedeepspeed_config: deepspeed_config_file: "InternVLA/config/deepseeds/ds_config.yaml" deepspeed_multinode_launcher: standard zero3_init_flag: falsedistributed_type: DEEPSPEED# main_process_port: 12345num_machines: 1num_processes: 812345678910111213141516171819202122232425262728{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "train_micro_batch_size_per_gpu": "auto", "train_batch_size": "auto", "gradient_accumulation_steps": 1, "zero_optimization": { "stage": 2, "allgather_partitions": true, "allgather_bucket_size": 5e8, "reduce_scatter": true, "reduce_bucket_size": 5e8, "overlap_comm": true, "contiguous_gradients": true, "cpu_offload": false }, "gradient_clipping": 1.0, "steps_per_print": 10}123456789101112131415161718192021compute_environment: LOCAL_MACHINEdebug: falsedeepspeed_config: deepspeed_multinode_launcher: standard offload_optimizer_device: none offload_param_device: none zero3_init_flag: false zero_stage: 2distributed_type: DEEPSPEEDdowncast_bf16: 'no'machine_rank: 0main_training_function: mainmixed_precision: bf16num_machines: 1num_processes: 8rdzv_backend: staticsame_network: truetpu_env: []tpu_use_cluster: falsetpu_use_sudo: falseuse_cpu: false12345678910111213141516171819202122232425262728{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "train_micro_batch_size_per_gpu": "auto", "train_batch_size": "auto", "gradient_accumulation_steps": "auto", "zero_optimization": { "stage": 3, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 1e9, "stage3_max_reuse_distance": 1e9, "stage3_gather_16bit_weights_on_model_save": true }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126run_id: internvla_cotrain_customrun_root_dir: results/Checkpointsseed: 42trackers: [jsonl, wandb]wandb_entity: WANDB_ENTITYwandb_project: WANDB_PROJECTis_debug: false
framework: framework_py: InternVLA-M1 qwenvl: # TODO later should not use qwenvl should use vlm directly base_vlm: ./playground/Pretrained_models/Qwen2.5-VL-3B-Instruct attn_implementation: flash_attention_2 vl_hidden_dim: 2048 # TODO should read from internal config dino: dino_backbone: dinov2_vits14 layer_qformer: qformer_end_layer: 37 qformer_start_layer: 36 num_query_tokens: 64 input_dim: 2048 # here is VLM output dimension ouptput_dim: 768 # here is action input dimension # here has a rule that ouptput_dim = action_hidden_dim; --> top2down logic should not default match, should be modified manually grad_scale: 0.5 # let gradient pass through this module to decay, avoid destroying VLM, # seems to affect learning
action_model: action_model_type: DiT-B action_hidden_dim: 768 action_dim: 7 use_ema: false future_action_window_size: 15 past_action_window_size: 0 repeated_diffusion_steps: 8 fm_head_config: input_embedding_dim: 1536 # Action embedding after dimension 48 * 32,and DiT's attention_head_dim * attention_heads corresponds to ActionEncoder hidden_size: 1024 # and DiT's last projection corresponds to ActionDecoder add_pos_embed: True max_seq_len: 1024 action_dim: 7 future_action_window_size: 15 action_horizon: 16 # = future_action_window_size + 1 + past_action_window_size past_action_window_size: 0 noise_beta_alpha: 1.5 noise_beta_beta: 1.0 noise_s: 0.999 num_timestep_buckets: 1000 num_inference_timesteps: 4 num_target_vision_tokens: 32 diffusion_model_cfg: # DiT Transformers parameters attention_head_dim: 48 cross_attention_dim: 2048 # VLM dim dropout: 0.2 final_dropout: true interleave_self_attention: true norm_type: "ada_norm" num_attention_heads: 32 num_layers: 16 output_dim: 1024 positional_embeddings: null
datasets: vlm_data: dataset_py: vlm_datasets dataformat: llava_json dataset_use: asv2_conversation_en,asv2_detailed_description_en,asv2_region_captioning_en,coco_internvl_longcap_en,coco_karpathy_train_567_en,coco_negative_gpt4o_en,coco_poetry_zh,coco_rem_en_zh,cocorem_exist_yorn_en,cocotextv2_en,cocotextv2_gpt4o_en,okvqa_en,refcoco_grounding_aug_en,refcoco_grounding_en,tallyqa_coco_en,toloka_grounding_aug_en,vqav2_en,vsr_en eval_dataset: aokvqa_cauldron_llava_format data_flatten: false base_interval: 2 max_pixels: 50176 min_pixels: 784 model_max_length: 2048 # seems to be 4096 here, some related content is not processed model_type: qwen2.5vl per_device_batch_size: 4
vla_data: dataset_py: lerobot_datasets data_root_dir: playground/Datasets/YOUR_DATASET_PATH data_mix: YOUR_DATASET_NAME action_type: delta_ee CoT_prompt: "Your task is {instruction}. To identify the key objects for your task. Locate their bounding boxes in [x1,y1,x2,y2] format." CoT_answer: bbox default_image_resolution: [3, 224, 224] # this is not effective per_device_batch_size: 16 load_all_data_for_training: true # consider how to enable eval set obs: ["image_0"] # this is not effective image_size: [224,224] #todo is null keep raw size # this is not effective
trainer: epochs: 100 # decide whether to use, he and max_train_steps conflict max_train_steps: 100000 num_warmup_steps: 5000 save_interval: 5000 eval_interval: 100 learning_rate: # you can set different lr for different modules base: 5e-05 qwen_vl_interface: 1.0e-05 action_model: 1.0e-04 lr_scheduler_type: cosine_with_min_lr scheduler_specific_kwargs: min_lr: 5.0e-07 freeze_modules: '' loss_scale: vla: 1.0 vlm: 0.1 # pretrained_checkpoint: ./results/Checkpoints/1_need/0601_qwenact_fixqwen_32gpus_lr_1e-3_qformer_36_37/steps_100000/pytorch_model.pt # reload_modules: 'action_model,layer_qformer' # warning: this may cause model to not converge repeated_diffusion_steps: 4 max_grad_norm: 1.0 warmup_ratio: 0.1 weight_decay: 0.0 logging_frequency: 10 gradient_clipping: 1.0 gradient_accumulation_steps: 1
optimizer: name: AdamW betas: [0.9, 0.95] eps: 1.0e-08 weight_decay: 1.0e-08
# parameters to be determined is_resume: false resume_epoch: null resume_step: null enable_gradient_checkpointing: true enable_mixed_precision_training: true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128run_id: humanoid_g1run_root_dir: runs/InternVLA/Checkpointsseed: 42trackers: [jsonl, wandb]wandb_entity: Nonewandb_project: Noneis_debug: false
framework: framework_py: InternVLA-M1 qwenvl: # TODO later should not use qwenvl should use vlm directly base_vlm: Qwen/Qwen2.5-VL-3B-Instruct attn_implementation: flash_attention_2 vl_hidden_dim: 2048 # TODO should read from internal config dino: dino_backbone: dinov2_vits14 layer_qformer: qformer_end_layer: 37 qformer_start_layer: 36 num_query_tokens: 64 input_dim: 2048 # here is VLM output dimension ouptput_dim: 768 # here is action input dimension # here has a rule that ouptput_dim = action_hidden_dim; --> top2down logic should not default match, should be modified manually grad_scale: 0.5 # let gradient pass through this module to decay, avoid destroying VLM, # seems to affect learning
action_model: action_model_type: DiT-B action_hidden_dim: 768 action_dim: 36 # 32 use_ema: false future_action_window_size: 15 # 29 past_action_window_size: 0 repeated_diffusion_steps: 8 fm_head_config: input_embedding_dim: 1536 # Action embedding after dimension 48 * 32,and DiT's attention_head_dim * attention_heads corresponds to ActionEncoder hidden_size: 1024 # and DiT's last projection corresponds to ActionDecoder add_pos_embed: True max_seq_len: 1024 action_dim: 36 # 32 future_action_window_size: 15 # 29 action_horizon: 16 # 30 # = future_action_window_size + 1 + past_action_window_size past_action_window_size: 0 noise_beta_alpha: 1.5 noise_beta_beta: 1.0 noise_s: 0.999 num_timestep_buckets: 1000 num_inference_timesteps: 4 num_target_vision_tokens: 32 diffusion_model_cfg: # DiT Transformers parameters attention_head_dim: 48 cross_attention_dim: 2048 # VLM dim dropout: 0.2 final_dropout: true interleave_self_attention: true norm_type: "ada_norm" num_attention_heads: 32 num_layers: 16 output_dim: 1024 positional_embeddings: null
datasets: vlm_data: dataset_py: vlm_datasets dataformat: llava_json dataset_use: asv2_conversation_en,asv2_detailed_description_en,asv2_region_captioning_en,coco_internvl_longcap_en,coco_karpathy_train_567_en,coco_negative_gpt4o_en,coco_poetry_zh,coco_rem_en_zh,cocorem_exist_yorn_en,cocotextv2_en,cocotextv2_gpt4o_en,okvqa_en,refcoco_grounding_aug_en,refcoco_grounding_en,tallyqa_coco_en,toloka_grounding_aug_en,vqav2_en,vsr_en eval_dataset: aokvqa_cauldron_llava_format data_flatten: false base_interval: 2 max_pixels: 50176 min_pixels: 784 model_max_length: 2048 # seems to be 4096 here, some related content is not processed model_type: qwen2.5vl per_device_batch_size: 4
vla_data: dataset_py: lerobot_datasets data_root_dir: None data_mix: humanoid_ action_type: abs_joints CoT_prompt: "Your task is {instruction}. To identify the key objects for your task. Locate their bounding boxes in [x1,y1,x2,y2] format." CoT_answer: bbox default_image_resolution: [3, 224, 224] # this is not effective per_device_batch_size: 64 # FIXME preload_all: true #FIXME load_all_data_for_training: true # consider how to enable eval set obs: ["image_0"] # this is not effective image_size: [224,224] #todo is null keep raw size # this is not effective
trainer: epochs: 100 # not effective; use max_train_steps instead max_train_steps: 30000 #100000 #FIXME num_warmup_steps: 0 save_interval: 5000 # 500 eval_interval: 100 learning_rate: # you can set different lr for different modules #FIXME base: 5e-05 qwen_vl_interface: 1.0e-05 action_model: 1.0e-04 lr_scheduler_type: cosine_with_min_lr scheduler_specific_kwargs: min_lr: 5.0e-07 freeze_modules: 'qwen_vl_interface,layer_qformer,dino_encoder,dino_pro' # FIXME loss_scale: vla: 1.0 vlm: 0.1 pretrained_checkpoint: /hfm/cache/checkpoints/InternVLA-M1-Pretrain-RT-1-Bridge/checkpoints/steps_50000_pytorch_model.pt # reload_modules: 'action_model,layer_qformer' # warning: this may cause model to not converge skip_reload_modules: 'action_model' # skip action-related layers # FIXME repeated_diffusion_steps: 4 max_grad_norm: 1.0 warmup_ratio: 0.1 weight_decay: 0.0 logging_frequency: 10 gradient_clipping: 1.0 gradient_accumulation_steps: 1
optimizer: name: AdamW betas: [0.9, 0.95] eps: 1.0e-08 weight_decay: 1.0e-08
# parameters to be determined is_resume: false resume_epoch: null resume_step: null enable_gradient_checkpointing: true enable_mixed_precision_training: true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126run_id: internVLArun_root_dir: results/Checkpointsseed: 42trackers: [jsonl, wandb]wandb_entity: your_wandb_entitywandb_project: internVLAis_debug: false
framework: framework_py: InternVLA-M1 qwenvl: base_vlm: ./playground/Pretrained_models/Qwen2.5-VL-3B-Instruct attn_implementation: flash_attention_2 vl_hidden_dim: 2048 dino: dino_backbone: dinov2_vits14 layer_qformer: qformer_end_layer: 37 qformer_start_layer: 36 num_query_tokens: 64 input_dim: 2048 ouptput_dim: 768 grad_scale: 0.5 action_model: action_model_type: DiT-B action_hidden_dim: 768 action_dim: 7 use_ema: false future_action_window_size: 15 past_action_window_size: 0 repeated_diffusion_steps: 8 fm_head_config: input_embedding_dim: 1536 # Action embedding after dimension 48 * 32,and DiT's attention_head_dim * attention_heads corresponds to ActionEncoder hidden_size: 1024 # and DiT's last projection corresponds to ActionDecoder add_pos_embed: True max_seq_len: 1024 action_dim: 7 future_action_window_size: 15 action_horizon: 16 past_action_window_size: 0 noise_beta_alpha: 1.5 noise_beta_beta: 1.0 noise_s: 0.999 num_timestep_buckets: 1000 num_inference_timesteps: 4 num_target_vision_tokens: 32 diffusion_model_cfg: # DiT Transformers parameters attention_head_dim: 48 cross_attention_dim: 2048 # VLM dim dropout: 0.2 final_dropout: true interleave_self_attention: true norm_type: "ada_norm" num_attention_heads: 32 num_layers: 16 output_dim: 1024 positional_embeddings: null reduce_in_full_precision: true
datasets: vlm_data: dataset_py: vlm_datasets dataformat: llava_json dataset_use: asv2_conversation_en,asv2_detailed_description_en,asv2_region_captioning_en,coco_internvl_longcap_en,coco_karpathy_train_567_en,coco_negative_gpt4o_en,coco_poetry_zh,coco_rem_en_zh,cocorem_exist_yorn_en,cocotextv2_en,cocotextv2_gpt4o_en,okvqa_en,refcoco_grounding_aug_en,refcoco_grounding_en,tallyqa_coco_en,toloka_grounding_aug_en,vqav2_en,vsr_en eval_dataset: aokvqa_cauldron_llava_format data_flatten: false base_interval: 2 max_pixels: 12845056 min_pixels: 3136 model_max_length: 2048 model_type: qwen2.5vl per_device_batch_size: 4
vla_data: dataset_py: lerobot_datasets data_root_dir: playground/Datasets/LEROBOT_LIBERO_DATA data_mix: libero_goal # libero_goal action_type: delta_qpos CoT_prompt: "Your task is {instruction}. To identify the key objects for your task. Locate their bounding boxes in [x1,y1,x2,y2] format." CoT_answer: bbox default_image_resolution: [3, 224, 224] per_device_batch_size: 16 load_all_data_for_training: true obs: ["image_0"]
trainer: epochs: 100 max_train_steps: 100000 num_warmup_steps: 5000 save_interval: 5000 eval_interval: 100 learning_rate: base: 2.5e-05 qwen_vl_interface: 1.0e-05 action_model: 1.0e-04 lr_scheduler_type: cosine_with_min_lr scheduler_specific_kwargs: min_lr: 1.0e-06 freeze_modules: '' loss_scale: vla: 1.0 vlm: 0.1 max_grad_norm: 1.0 warmup_ratio: 0.1 weight_decay: 0.0 logging_frequency: 10 gradient_clipping: 1.0 gradient_accumulation_steps: 1
optimizer: name: AdamW betas: [0.9, 0.95] eps: 1.0e-08 weight_decay: 1.0e-08
# parameters to be determined is_resume: false resume_epoch: null resume_step: null enable_gradient_checkpointing: true enable_mixed_precision_training: true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100run_id: qwenactrun_root_dir: results/Checkpointsseed: 42trackers: [jsonl, wandb]wandb_entity: your_wandb_entitywandb_project: internVLAAAis_debug: false
framework: framework_py: InternVLA-M1 qwenvl: base_vlm: ./playground/Pretrained_models/Qwen2.5-VL-3B-Instruct attn_implementation: flash_attention_2 vl_hidden_dim: 2048 dino: dino_backbone: dinov2_vits14 layer_qformer: qformer_end_layer: 37 qformer_start_layer: 36 num_query_tokens: 64 input_dim: 2048 ouptput_dim: 768 grad_scale: 0.5
action_model: action_model_type: DiT-B action_hidden_dim: 768 action_dim: 7 use_ema: false future_action_window_size: 15 past_action_window_size: 0 repeated_diffusion_steps: 8
datasets: vlm_data: dataset_py: vlm_datasets dataformat: llava_json dataset_use: asv2_conversation_en,asv2_detailed_description_en,asv2_region_captioning_en,coco_internvl_longcap_en,coco_karpathy_train_567_en,coco_negative_gpt4o_en,coco_poetry_zh,coco_rem_en_zh,cocorem_exist_yorn_en,cocotextv2_en,cocotextv2_gpt4o_en,okvqa_en,refcoco_grounding_aug_en,refcoco_grounding_en,tallyqa_coco_en,toloka_grounding_aug_en,vqav2_en,vsr_en eval_dataset: aokvqa_cauldron_llava_format data_flatten: false base_interval: 2 max_pixels: 50176 min_pixels: 784 model_max_length: 2048 model_type: qwen2.5vl per_device_batch_size: 4
vla_data: dataset_py: lerobot_datasets data_root_dir: playground/Datasets/OXE_LEROBOT_DATASET data_mix: bridge_rt_1 # bridge_rt_1 action_type: delta_ee CoT_prompt: "Your task is {instruction}. To identify the key objects for your task. Locate their bounding boxes in [x1,y1,x2,y2] format." CoT_answer: bbox default_image_resolution: [3, 224, 224] per_device_batch_size: 16 load_all_data_for_training: true obs: ["image_0"] image_size: [224,224]
trainer: epochs: 100 max_train_steps: 100000 num_warmup_steps: 5000 save_interval: 5000 eval_interval: 100 learning_rate: base: 1e-05 qwen_vl_interface: 1.0e-05 action_model: 1.0e-04 lr_scheduler_type: cosine_with_min_lr scheduler_specific_kwargs: min_lr: 5.0e-07 freeze_modules: '' loss_scale: vla: 1.0 vlm: 0.1 # pretrained_checkpoint: ./results/Checkpoints/1_need/0601_qwenact_fixqwen_32gpus_lr_1e-3_qformer_36_37/steps_100000/pytorch_model.pt # reload_modules: 'action_model,layer_qformer' # warning: this may cause model to not converge repeated_diffusion_steps: 4 max_grad_norm: 1.0 warmup_ratio: 0.1 weight_decay: 0.0 logging_frequency: 10 gradient_clipping: 1.0 gradient_accumulation_steps: 1
optimizer: name: AdamW betas: [0.9, 0.95] eps: 1.0e-08 weight_decay: 1.0e-08
# parameters to be determined is_resume: false resume_epoch: null resume_step: null enable_gradient_checkpointing: true enable_mixed_precision_training: true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124run_id: qwenactrun_root_dir: results/Checkpointsseed: 42trackers: [jsonl, wandb]wandb_entity: ailab-manipulationwandb_project: internVLAis_debug: false
framework: framework_py: InternVLA-M1 qwenvl: # TODO later should not use qwenvl should use vlm directly base_vlm: ./playground/Pretrained_models/Qwen2.5-VL-3B-Instruct attn_implementation: flash_attention_2 vl_hidden_dim: 2048 # TODO should read from internal config dino: dino_backbone: dinov2_vits14 layer_qformer: qformer_end_layer: 37 qformer_start_layer: 36 num_query_tokens: 64 input_dim: 2048 # here is VLM output dimension ouptput_dim: 768 # here is action input dimension # here has a rule that ouptput_dim = action_hidden_dim; --> top2down logic should not default match, should be modified manually grad_scale: 0.5 # let gradient pass through this module to decay, avoid destroying VLM, # seems to affect learning
action_model: action_model_type: DiT-B action_hidden_dim: 768 action_dim: 8 use_ema: false future_action_window_size: 15 past_action_window_size: 0 repeated_diffusion_steps: 8 fm_head_config: input_embedding_dim: 1536 # Action embedding after dimension 48 * 32,and DiT's attention_head_dim * attention_heads corresponds to ActionEncoder hidden_size: 1024 # and DiT's last projection corresponds to ActionDecoder add_pos_embed: True max_seq_len: 1024 action_dim: 8 future_action_window_size: 15 action_horizon: 16 # = future_action_window_size + 1 + past_action_window_size past_action_window_size: 0 noise_beta_alpha: 1.5 noise_beta_beta: 1.0 noise_s: 0.999 num_timestep_buckets: 1000 num_inference_timesteps: 4 num_target_vision_tokens: 32 diffusion_model_cfg: # DiT Transformers parameters attention_head_dim: 48 cross_attention_dim: 2048 # VLM dim dropout: 0.2 final_dropout: true interleave_self_attention: true norm_type: "ada_norm" num_attention_heads: 32 num_layers: 16 output_dim: 1024 positional_embeddings: null
datasets: vlm_data: dataset_py: vlm_datasets dataformat: llava_json dataset_use: asv2_conversation_en,asv2_detailed_description_en,asv2_region_captioning_en,coco_internvl_longcap_en,coco_karpathy_train_567_en,coco_negative_gpt4o_en,coco_poetry_zh,coco_rem_en_zh,cocorem_exist_yorn_en,cocotextv2_en,cocotextv2_gpt4o_en,okvqa_en,refcoco_grounding_aug_en,refcoco_grounding_en,tallyqa_coco_en,toloka_grounding_aug_en,vqav2_en,vsr_en eval_dataset: aokvqa_cauldron_llava_format data_flatten: false base_interval: 2 max_pixels: 50176 min_pixels: 784 model_max_length: 2048 # seems to be 4096 here, some related content is not processed model_type: qwen2.5vl per_device_batch_size: 4
vla_data: dataset_py: lerobot_datasets data_root_dir: playground/demo_data data_mix: demo_sim_pick_place action_type: delta_joints CoT_prompt: "Your task is {instruction}. To identify the key objects for your task. Locate their bounding boxes in [x1,y1,x2,y2] format." CoT_answer: bbox default_image_resolution: [3, 224, 224] # this is not effective per_device_batch_size: 16 load_all_data_for_training: true # consider how to enable eval set obs: ["image_0"] # this is not effective image_size: [224,224] #todo is null keep raw size # this is not effective
trainer: epochs: 100 # decide whether to use, he and max_train_steps conflict max_train_steps: 100000 num_warmup_steps: 5000 save_interval: 5000 eval_interval: 100 learning_rate: # you can set different lr for different modules base: 5e-05 qwen_vl_interface: 1.0e-05 action_model: 1.0e-04 lr_scheduler_type: cosine_with_min_lr scheduler_specific_kwargs: min_lr: 5.0e-07 freeze_modules: '' loss_scale: vla: 1.0 vlm: 0.1 repeated_diffusion_steps: 4 max_grad_norm: 1.0 warmup_ratio: 0.1 weight_decay: 0.0 logging_frequency: 10 gradient_clipping: 1.0 gradient_accumulation_steps: 1
optimizer: name: AdamW betas: [0.9, 0.95] eps: 1.0e-08 weight_decay: 1.0e-08
# parameters to be determined is_resume: false resume_epoch: null resume_step: null enable_gradient_checkpointing: true enable_mixed_precision_training: true123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import jsonimport osfrom accelerate.logging import get_loggerimport numpy as npfrom torch.utils.data import DataLoaderimport numpy as npimport torch.distributed as distfrom pathlib import Pathfrom InternVLA.dataloader.vlm_datasets import make_vlm_dataloader
logger = get_logger(__name__)
def save_dataset_statistics(dataset_statistics, run_dir): """Saves a `dataset_statistics.json` file.""" out_path = run_dir / "dataset_statistics.json" with open(out_path, "w") as f_json: for _, stats in dataset_statistics.items(): for k in stats["action"].keys(): if isinstance(stats["action"][k], np.ndarray): stats["action"][k] = stats["action"][k].tolist() if "proprio" in stats: for k in stats["proprio"].keys(): if isinstance(stats["proprio"][k], np.ndarray): stats["proprio"][k] = stats["proprio"][k].tolist() if "num_trajectories" in stats: if isinstance(stats["num_trajectories"], np.ndarray): stats["num_trajectories"] = stats["num_trajectories"].item() if "num_transitions" in stats: if isinstance(stats["num_transitions"], np.ndarray): stats["num_transitions"] = stats["num_transitions"].item() json.dump(dataset_statistics, f_json, indent=2) logger.info(f"Saved dataset statistics file at path {out_path}")
def build_dataloader(cfg, dataset_py="lerobot_datasets_oxe"): # TODO now here only is get dataset, we need mv dataloader to here
if dataset_py == "lerobot_datasets": from InternVLA.dataloader.lerobot_datasets import get_vla_dataset, collate_fn vla_dataset_cfg = cfg.datasets.vla_data
data_root_dir = vla_dataset_cfg.data_root_dir data_mix = vla_dataset_cfg.data_mix
vla_dataset = get_vla_dataset(data_cfg=vla_dataset_cfg) vla_train_dataloader = DataLoader( vla_dataset, batch_size=cfg.datasets.vla_data.per_device_batch_size, collate_fn=collate_fn, num_workers=8, # shuffle=True ) if dist.get_rank() == 0: output_dir = Path(cfg.output_dir) vla_dataset.save_dataset_statistics(output_dir / "dataset_statistics.json") return vla_train_dataloader elif dataset_py == "vlm_datasets": vlm_data_module = make_vlm_dataloader(cfg) vlm_train_dataloader = vlm_data_module["train_dataloader"] return vlm_train_dataloader123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.
from abc import ABC, abstractmethod
from InternVLA.dataloader.gr00t_lerobot.datasets import ModalityConfigfrom InternVLA.dataloader.gr00t_lerobot.transform.base import ComposedModalityTransform, ModalityTransformfrom InternVLA.dataloader.gr00t_lerobot.transform.concat import ConcatTransformfrom InternVLA.dataloader.gr00t_lerobot.transform.state_action import ( StateActionSinCosTransform, StateActionToTensor, StateActionTransform,)from InternVLA.dataloader.gr00t_lerobot.transform.video import ( VideoColorJitter, VideoCrop, VideoResize, VideoToNumpy, VideoToTensor,)# from gr00t.model.transforms import GR00TTransform
class BaseDataConfig(ABC): @abstractmethod def modality_config(self) -> dict[str, ModalityConfig]: pass
@abstractmethod def transform(self) -> ModalityTransform: pass
###########################################################################################
class OxeDroidDataConfig: video_keys = [ "video.exterior_image_1", "video.exterior_image_2", "video.wrist_image", ] state_keys = [ "state.eef_position", "state.eef_rotation", "state.gripper_position", ] action_keys = [ "action.eef_position_delta", "action.eef_rotation_delta", "action.gripper_position", ] language_keys = ["annotation.language.language_instruction"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # video transforms VideoToTensor(apply_to=self.video_keys), VideoCrop(apply_to=self.video_keys, scale=0.95), VideoResize(apply_to=self.video_keys, height=224, width=224, interpolation="linear"), VideoColorJitter( apply_to=self.video_keys, brightness=0.3, contrast=0.4, saturation=0.5, hue=0.08, ), VideoToNumpy(apply_to=self.video_keys), # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.eef_position": "min_max", "state.gripper_position": "min_max", }, target_rotations={ "state.eef_rotation": "rotation_6d", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.gripper_position": "binary", }, target_rotations={"action.eef_rotation_delta": "axis_angle"}, ), # concat transforms ConcatTransform( video_concat_order=self.video_keys, state_concat_order=self.state_keys, action_concat_order=self.action_keys, ), GR00TTransform( state_horizon=len(self.observation_indices), action_horizon=len(self.action_indices), max_state_dim=64, max_action_dim=32, ), ]
return ComposedModalityTransform(transforms=transforms)
###########################################################################################
class OxeBridgeDataConfig: video_keys = [ "video.image_0", ] state_keys = [ "state.x", "state.y", "state.z", "state.roll", "state.pitch", "state.yaw", "state.pad", "state.gripper", ] action_keys = [ "action.x", "action.y", "action.z", "action.roll", "action.pitch", "action.yaw", "action.gripper", ] language_keys = ["annotation.human.action.task_description"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # video transforms # VideoToTensor(apply_to=self.video_keys), # VideoCrop(apply_to=self.video_keys, scale=0.95), # VideoResize(apply_to=self.video_keys, height=224, width=224, interpolation="linear"), # VideoColorJitter( # apply_to=self.video_keys, # brightness=0.3, # contrast=0.4, # saturation=0.5, # hue=0.08, # ), # VideoToNumpy(apply_to=self.video_keys), # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.x": "q99", "state.y": "q99", "state.z": "q99", "state.roll": "q99", "state.pitch": "q99", "state.yaw": "q99", "state.pad": "q99", "state.gripper": "binary", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.x": "q99", "action.y": "q99", "action.z": "q99", "action.roll": "q99", "action.pitch": "q99", "action.yaw": "q99", "action.gripper": "binary", }, ), # concat transforms # ConcatTransform( # # video_concat_order=self.video_keys, # state_concat_order=self.state_keys, # action_concat_order=self.action_keys, # ), # GR00TTransform( # state_horizon=len(self.observation_indices), # action_horizon=len(self.action_indices), # max_state_dim=64, # max_action_dim=32, # ), ]
return ComposedModalityTransform(transforms=transforms)
###########################################################################################
class OxeRT1DataConfig: video_keys = [ "video.image", ] state_keys = [ "state.x", "state.y", "state.z", "state.rx", "state.ry", "state.rz", "state.rw", "state.gripper", ] action_keys = [ "action.x", "action.y", "action.z", "action.roll", "action.pitch", "action.yaw", "action.gripper", ] language_keys = ["annotation.human.action.task_description"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # video transforms # VideoToTensor(apply_to=self.video_keys), # VideoCrop(apply_to=self.video_keys, scale=0.95), # VideoResize(apply_to=self.video_keys, height=224, width=224, interpolation="linear"), # VideoColorJitter( # apply_to=self.video_keys, # brightness=0.3, # contrast=0.4, # saturation=0.5, # hue=0.08, # ), # VideoToNumpy(apply_to=self.video_keys), # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.x": "q99", "state.y": "q99", "state.z": "q99", "state.rx": "q99", "state.ry": "q99", "state.rz": "q99", "state.rw": "q99", "state.gripper": "binary", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.x": "q99", "action.y": "q99", "action.z": "q99", "action.roll": "q99", "action.pitch": "q99", "action.yaw": "q99", "action.gripper": "binary", }, ), # concat transforms # ConcatTransform( # # video_concat_order=self.video_keys, # state_concat_order=self.state_keys, # action_concat_order=self.action_keys, # ), # GR00TTransform( # state_horizon=len(self.observation_indices), # action_horizon=len(self.action_indices), # max_state_dim=64, # max_action_dim=32, # ), ]
return ComposedModalityTransform(transforms=transforms)
###########################################################################################
class SingleFrankaRobotiqDeltaEefDataConfig: video_keys = [ "video.base_view", "video.ego_view", ] state_keys = [ "state.eef_position", "state.eef_rotation", ] action_keys = [ "action.delta_eef_position", "action.delta_eef_rotation", "action.gripper_close", ]
language_keys = ["annotation.human.action.task_description"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.eef_position": "min_max", "state.eef_rotation": "min_max", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.delta_eef_position": "min_max", "action.delta_eef_rotation": "min_max", "action.gripper_close": "binary", }, ), ]
return ComposedModalityTransform(transforms=transforms)
###########################################################################################
class Libero4in1DataConfig: video_keys = [ "video.primary_image", "video.wrist_image", ] state_keys = [ "state.x", "state.y", "state.z", "state.roll", "state.pitch", "state.yaw", "state.pad", "state.gripper", ] action_keys = [ "action.x", "action.y", "action.z", "action.roll", "action.pitch", "action.yaw", "action.gripper", ] language_keys = ["annotation.human.action.task_description"]
observation_indices = [0] action_indices = list(range(8))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.x": "min_max", "action.y": "min_max", "action.z": "min_max", "action.roll": "min_max", "action.pitch": "min_max", "action.yaw": "min_max", }, ), ]
return ComposedModalityTransform(transforms=transforms)
###########################################################################################
class SingleFrankaRobotiqDeltaJointsDataConfig: video_keys = [ "video.base_view", "video.ego_view", ] state_keys = [ "state.joints", ] action_keys = [ "action.delta_joints", "action.gripper_close", ]
language_keys = ["annotation.human.action.task_description"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.joints": "min_max", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.delta_joints": "min_max", "action.gripper_close": "binary", }, ), ]
return ComposedModalityTransform(transforms=transforms)
class HumanoidDataConfig: video_keys = [ "video.rs_view", ] state_keys = [ "state.left_hand", "state.right_hand", "state.left_arm", "state.right_arm", "state.rpy", "state.height", ] action_keys = [ "action.left_hand", "action.right_hand", "action.left_arm", "action.right_arm", "action.rpy", "action.height", "action.torso_vx", "action.torso_vy", "action.torso_vyaw", "action.target_yaw", ]
language_keys = ["annotation.human.task_description"] observation_indices = [0] action_indices = list(range(16)) # list(range(30))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) modality_configs = { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, } return modality_configs
def transform(self): transforms = [ # state transforms StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={ "state.left_hand": "min_max", "state.right_hand": "min_max", "state.left_arm": "min_max", "state.right_arm": "min_max", "state.rpy": "min_max", "state.height": "min_max", }, ), # action transforms StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={ "action.left_hand": "min_max", "action.right_hand": "min_max", "action.left_arm": "min_max", "action.right_arm": "min_max", "action.rpy": "min_max", "action.height": "min_max", "action.torso_vx": "min_max", "action.torso_vy": "min_max", "action.torso_vyaw": "min_max", "action.target_yaw": "min_max", }, ), ]
return ComposedModalityTransform(transforms=transforms)
class HumanoidSimDataConfig: video_keys = ["video.rs_view"] state_keys = [ "state.left_hand", "state.right_hand", "state.left_arm", "state.right_arm", "state.waist", ] action_keys = [ "action.left_hand", "action.right_hand", "action.left_arm", "action.right_arm", "action.waist", ] language_keys = ["annotation.human.task_description"] observation_indices = [0] action_indices = list(range(16))
def modality_config(self): video_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.video_keys, ) state_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.state_keys, ) action_modality = ModalityConfig( delta_indices=self.action_indices, modality_keys=self.action_keys, ) language_modality = ModalityConfig( delta_indices=self.observation_indices, modality_keys=self.language_keys, ) return { "video": video_modality, "state": state_modality, "action": action_modality, "language": language_modality, }
def transform(self): transforms = [ VideoToTensor(apply_to=self.video_keys), VideoCrop(apply_to=self.video_keys, scale=0.95), VideoResize(apply_to=self.video_keys, height=224, width=224, interpolation="linear"), VideoColorJitter( apply_to=self.video_keys, brightness=0.3, contrast=0.4, saturation=0.5, hue=0.08, ), VideoToNumpy(apply_to=self.video_keys), StateActionToTensor(apply_to=self.state_keys), StateActionTransform( apply_to=self.state_keys, normalization_modes={key: "min_max" for key in self.state_keys}, ), StateActionToTensor(apply_to=self.action_keys), StateActionTransform( apply_to=self.action_keys, normalization_modes={key: "min_max" for key in self.action_keys}, ), ConcatTransform( video_concat_order=self.video_keys, state_concat_order=self.state_keys, action_concat_order=self.action_keys, ), ] return ComposedModalityTransform(transforms=transforms)###########################################################################################
ROBOT_TYPE_CONFIG_MAP = { "libero_franka": Libero4in1DataConfig(), "oxe_droid": OxeDroidDataConfig(), "oxe_bridge": OxeBridgeDataConfig(), "oxe_rt1": OxeRT1DataConfig(), "demo_sim_franka_delta_joints": SingleFrankaRobotiqDeltaJointsDataConfig(), "custom_robot_config": SingleFrankaRobotiqDeltaEefDataConfig(), "humanoid_config": HumanoidDataConfig(), "humanoid_sim_config": HumanoidSimDataConfig(),}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.
"""In this file, we define 3 types of datasets:1. LeRobotSingleDataset: a single dataset for a given embodiment tag2. LeRobotMixtureDataset: a mixture of datasets for a given list of embodiment tags3. CachedLeRobotSingleDataset: a single dataset for a given embodiment tag, with caching for the video frames
See `scripts/load_dataset.py` for examples on how to use these datasets."""
import hashlibimport jsonfrom collections import defaultdictfrom pathlib import Pathfrom typing import Sequence
import numpy as npimport pandas as pdfrom pydantic import BaseModel, Field, ValidationErrorfrom torch.utils.data import Datasetfrom tqdm import tqdmfrom PIL import Image
from InternVLA.dataloader.gr00t_lerobot.video import get_all_frames, get_frames_by_timestamps
from InternVLA.dataloader.gr00t_lerobot.embodiment_tags import EmbodimentTagfrom InternVLA.dataloader.gr00t_lerobot.schema import ( DatasetMetadata, DatasetStatisticalValues, LeRobotModalityMetadata, LeRobotStateActionMetadata,)from InternVLA.dataloader.gr00t_lerobot.transform import ComposedModalityTransform
from functools import partialfrom typing import Tuple, Listimport pickle
LE_ROBOT_MODALITY_FILENAME = "meta/modality.json"LE_ROBOT_EPISODE_FILENAME = "meta/episodes.jsonl"LE_ROBOT_TASKS_FILENAME = "meta/tasks.jsonl"LE_ROBOT_INFO_FILENAME = "meta/info.json"LE_ROBOT_STATS_FILENAME = "meta/stats_gr00t.json"LE_ROBOT_DATA_FILENAME = "data/*/*.parquet"LE_ROBOT_STEPS_FILENAME = "meta/steps.pkl"EPSILON = 5e-4
def calculate_dataset_statistics(parquet_paths: list[Path]) -> dict: """Calculate the dataset statistics of all columns for a list of parquet files.""" # Dataset statistics all_low_dim_data_list = [] # Collect all the data # parquet_paths = parquet_paths[:3] for parquet_path in tqdm( sorted(list(parquet_paths)), desc="Collecting all parquet files...", ): # Load the parquet file parquet_data = pd.read_parquet(parquet_path) parquet_data = parquet_data all_low_dim_data_list.append(parquet_data) all_low_dim_data = pd.concat(all_low_dim_data_list, axis=0) # Compute dataset statistics dataset_statistics = {} for le_modality in all_low_dim_data.columns: if le_modality not in ["states", "action"]: continue if le_modality.startswith("annotation."): continue print(f"Computing statistics for {le_modality}...") np_data = np.vstack( [np.asarray(x, dtype=np.float32) for x in all_low_dim_data[le_modality]] ) dataset_statistics[le_modality] = { "mean": np.mean(np_data, axis=0).tolist(), "std": np.std(np_data, axis=0).tolist(), "min": np.min(np_data, axis=0).tolist(), "max": np.max(np_data, axis=0).tolist(), "q01": np.quantile(np_data, 0.01, axis=0).tolist(), "q99": np.quantile(np_data, 0.99, axis=0).tolist(), } return dataset_statistics
class ModalityConfig(BaseModel): """Configuration for a modality."""
delta_indices: list[int] """Delta indices to sample relative to the current index. The returned data will correspond to the original data at a sampled base index + delta indices.""" modality_keys: list[str] """The keys to load for the modality in the dataset."""
class LeRobotSingleDataset(Dataset): """ Base dataset class for LeRobot that supports sharding. """ def __init__( self, dataset_path: Path | str, modality_configs: dict[str, ModalityConfig], embodiment_tag: str | EmbodimentTag, video_backend: str = "decord", video_backend_kwargs: dict | None = None, transforms: ComposedModalityTransform | None = None, delete_pause_frame: bool = False, preload_all=True ): """ Initialize the dataset.
Args: dataset_path (Path | str): The path to the dataset. modality_configs (dict[str, ModalityConfig]): The configuration for each modality. The keys are the modality names, and the values are the modality configurations. See `ModalityConfig` for more details. video_backend (str): Backend for video reading. video_backend_kwargs (dict): Keyword arguments for the video backend when initializing the video reader. transforms (ComposedModalityTransform): The transforms to apply to the dataset. embodiment_tag (EmbodimentTag): Overload the embodiment tag for the dataset. e.g. define it as "new_embodiment" """ # first check if the path directory exists if not Path(dataset_path).exists(): raise FileNotFoundError(f"Dataset path {dataset_path} does not exist")
self.delete_pause_frame = delete_pause_frame
self.modality_configs = modality_configs self.video_backend = video_backend self.video_backend_kwargs = video_backend_kwargs if video_backend_kwargs is not None else {} self.transforms = ( transforms if transforms is not None else ComposedModalityTransform(transforms=[]) )
self._dataset_path = Path(dataset_path) self._dataset_name = self._dataset_path.name if isinstance(embodiment_tag, EmbodimentTag): self.tag = embodiment_tag.value else: self.tag = embodiment_tag
self._metadata = self._get_metadata(EmbodimentTag(self.tag))
# LeRobot-specific config self._lerobot_modality_meta = self._get_lerobot_modality_meta() self._lerobot_info_meta = self._get_lerobot_info_meta() self._data_path_pattern = self._get_data_path_pattern() self._video_path_pattern = self._get_video_path_pattern() self._chunk_size = self._get_chunk_size() self._tasks = self._get_tasks() self.curr_traj_data = None self.curr_traj_id = None
self._trajectory_ids, self._trajectory_lengths = self._get_trajectories() if preload_all: self._preload_all_trajectories() self.preload_all = True else: self.preload_all = False self._modality_keys = self._get_modality_keys() self._delta_indices = self._get_delta_indices() self._all_steps = self._get_all_steps() self.set_transforms_metadata(self.metadata) self.set_epoch(0)
print(f"Initialized dataset {self.dataset_name} with {embodiment_tag}")
# Check if the dataset is valid self._check_integrity()
@property def dataset_path(self) -> Path: """The path to the dataset that contains the METADATA_FILENAME file.""" return self._dataset_path
@property def metadata(self) -> DatasetMetadata: """The metadata for the dataset, loaded from metadata.json in the dataset directory""" return self._metadata
@property def trajectory_ids(self) -> np.ndarray: """The trajectory IDs in the dataset, stored as a 1D numpy array of strings.""" return self._trajectory_ids
@property def trajectory_lengths(self) -> np.ndarray: """The trajectory lengths in the dataset, stored as a 1D numpy array of integers. The order of the lengths is the same as the order of the trajectory IDs. """ return self._trajectory_lengths
@property def all_steps(self) -> list[tuple[int, int]]: """The trajectory IDs and base indices for all steps in the dataset. Example: self.trajectory_ids: [0, 1, 2] self.trajectory_lengths: [3, 2, 4] return: [ ("traj_0", 0), ("traj_0", 1), ("traj_0", 2), ("traj_1", 0), ("traj_1", 1), ("traj_2", 0), ("traj_2", 1), ("traj_2", 2), ("traj_2", 3) ] """ return self._all_steps
@property def modality_keys(self) -> dict: """The modality keys for the dataset. The keys are the modality names, and the values are the keys for each modality.
Example: { "video": ["video.image_side_0", "video.image_side_1"], "state": ["state.eef_position", "state.eef_rotation"], "action": ["action.eef_position", "action.eef_rotation"], "language": ["language.human.task"], "timestamp": ["timestamp"], "reward": ["reward"], } """ return self._modality_keys
@property def delta_indices(self) -> dict[str, np.ndarray]: """The delta indices for the dataset. The keys are the modality.key, and the values are the delta indices for each modality.key.""" return self._delta_indices
@property def dataset_name(self) -> str: """The name of the dataset.""" return self._dataset_name
@property def lerobot_modality_meta(self) -> LeRobotModalityMetadata: """The metadata for the LeRobot dataset.""" return self._lerobot_modality_meta
@property def lerobot_info_meta(self) -> dict: """The metadata for the LeRobot dataset.""" return self._lerobot_info_meta
@property def data_path_pattern(self) -> str: """The path pattern for the LeRobot dataset.""" return self._data_path_pattern
@property def video_path_pattern(self) -> str: """The path pattern for the LeRobot dataset.""" return self._video_path_pattern
@property def chunk_size(self) -> int: """The chunk size for the LeRobot dataset.""" return self._chunk_size
@property def tasks(self) -> pd.DataFrame: """The tasks for the dataset.""" return self._tasks
def _get_metadata(self, embodiment_tag: EmbodimentTag) -> DatasetMetadata: """Get the metadata for the dataset.
Returns: dict: The metadata for the dataset. """
# 1. Modality metadata modality_meta_path = self.dataset_path / LE_ROBOT_MODALITY_FILENAME assert ( modality_meta_path.exists() ), f"Please provide a {LE_ROBOT_MODALITY_FILENAME} file in {self.dataset_path}" # 1.1. State and action modalities simplified_modality_meta: dict[str, dict] = {} with open(modality_meta_path, "r") as f: le_modality_meta = LeRobotModalityMetadata.model_validate(json.load(f)) for modality in ["state", "action"]: simplified_modality_meta[modality] = {} le_state_action_meta: dict[str, LeRobotStateActionMetadata] = getattr( le_modality_meta, modality ) for subkey in le_state_action_meta: state_action_dtype = np.dtype(le_state_action_meta[subkey].dtype) if np.issubdtype(state_action_dtype, np.floating): continuous = True else: continuous = False simplified_modality_meta[modality][subkey] = { "absolute": le_state_action_meta[subkey].absolute, "rotation_type": le_state_action_meta[subkey].rotation_type, "shape": [ le_state_action_meta[subkey].end - le_state_action_meta[subkey].start ], "continuous": continuous, }
# 1.2. Video modalities le_info_path = self.dataset_path / LE_ROBOT_INFO_FILENAME assert ( le_info_path.exists() ), f"Please provide a {LE_ROBOT_INFO_FILENAME} file in {self.dataset_path}" with open(le_info_path, "r") as f: le_info = json.load(f) simplified_modality_meta["video"] = {} for new_key in le_modality_meta.video: original_key = le_modality_meta.video[new_key].original_key if original_key is None: original_key = new_key le_video_meta = le_info["features"][original_key] height = le_video_meta["shape"][le_video_meta["names"].index("height")] width = le_video_meta["shape"][le_video_meta["names"].index("width")] # NOTE(FH): different lerobot dataset versions have different keys for the number of channels and fps try: channels = le_video_meta["shape"][le_video_meta["names"].index("channel")] fps = le_video_meta["video_info"]["video.fps"] except (ValueError, KeyError): # channels = le_video_meta["shape"][le_video_meta["names"].index("channels")] channels = le_video_meta["info"]["video.channels"] fps = le_video_meta["info"]["video.fps"] simplified_modality_meta["video"][new_key] = { "resolution": [width, height], "channels": channels, "fps": fps, }
# 2. Dataset statistics stats_path = self.dataset_path / LE_ROBOT_STATS_FILENAME try: with open(stats_path, "r") as f: le_statistics = json.load(f) for stat in le_statistics.values(): DatasetStatisticalValues.model_validate(stat) except (FileNotFoundError, ValidationError) as e: print(f"Failed to load dataset statistics: {e}") print(f"Calculating dataset statistics for {self.dataset_name}") # Get all parquet files in the dataset paths parquet_files = list((self.dataset_path).glob(LE_ROBOT_DATA_FILENAME)) le_statistics = calculate_dataset_statistics(parquet_files) with open(stats_path, "w") as f: json.dump(le_statistics, f, indent=4) dataset_statistics = {} for our_modality in ["state", "action"]: dataset_statistics[our_modality] = {} for subkey in simplified_modality_meta[our_modality]: dataset_statistics[our_modality][subkey] = {} state_action_meta = le_modality_meta.get_key_meta(f"{our_modality}.{subkey}") assert isinstance(state_action_meta, LeRobotStateActionMetadata) le_modality = state_action_meta.original_key for stat_name in le_statistics[le_modality]: indices = np.arange( state_action_meta.start, state_action_meta.end, ) stat = np.array(le_statistics[le_modality][stat_name]) dataset_statistics[our_modality][subkey][stat_name] = stat[indices].tolist()
# 3. Full dataset metadata metadata = DatasetMetadata( statistics=dataset_statistics, # type: ignore modalities=simplified_modality_meta, # type: ignore embodiment_tag=embodiment_tag, )
return metadata
def _get_trajectories(self) -> tuple[np.ndarray, np.ndarray]: """Get the trajectories in the dataset.""" # Get trajectory lengths, IDs, and whitelist from dataset metadata episode_path = self.dataset_path / LE_ROBOT_EPISODE_FILENAME with open(episode_path, "r") as f: episode_metadata = [json.loads(line) for line in f] trajectory_ids = [] trajectory_lengths = [] for episode in episode_metadata: trajectory_ids.append(episode["episode_index"]) trajectory_lengths.append(episode["length"]) return np.array(trajectory_ids), np.array(trajectory_lengths)
def _get_all_steps(self) -> list[tuple[int, int]]: """Get the trajectory IDs and base indices for all steps in the dataset.
Returns: list[tuple[str, int]]: A list of (trajectory_id, base_index) tuples. """ # Create a hash key based on configuration to ensure cache validity config_key = self._get_steps_config_key() # Create a unique filename based on config_key steps_filename = f"steps_{config_key}.pkl" # @DUG # fast get static steps @fangjing --> don't use hash to dynamic sample steps_filename = "steps_7799a3080fbd.pkl"
steps_path = self.dataset_path / "meta" / steps_filename # Try to load cached steps first try: if steps_path.exists(): with open(steps_path, "rb") as f: cached_data = pickle.load(f) return cached_data["steps"] # # Verify the cached data matches current configuration # if cached_data.get("config_key") == config_key: # print(f"Loading cached steps from {steps_path}") # return cached_data["steps"] # else: # print("Cached steps configuration mismatch, recomputing...") except (FileNotFoundError, pickle.PickleError, KeyError) as e: print(f"Failed to load cached steps: {e}") print("Computing steps from scratch...")
# Compute steps using single process all_steps = self._get_all_steps_single_process() # Cache the computed steps with unique filename try: cache_data = { "config_key": config_key, "steps": all_steps, "num_trajectories": len(self.trajectory_ids), "total_steps": len(all_steps), "computed_timestamp": pd.Timestamp.now().isoformat(), "delete_pause_frame": self.delete_pause_frame, } # Ensure the meta directory exists steps_path.parent.mkdir(parents=True, exist_ok=True) with open(steps_path, "wb") as f: pickle.dump(cache_data, f, protocol=pickle.HIGHEST_PROTOCOL) print(f"Cached steps saved to {steps_path}") except Exception as e: print(f"Failed to cache steps: {e}") return all_steps
def _get_steps_config_key(self) -> str: """Generate a configuration key for steps caching.""" config_dict = { "delete_pause_frame": self.delete_pause_frame, "dataset_name": self.dataset_name, } # Create a hash of the configuration config_str = str(sorted(config_dict.items())) return hashlib.md5(config_str.encode()).hexdigest()[:12] #
def _get_all_steps_single_process(self) -> list[tuple[int, int]]: """Original single-process implementation as fallback.""" all_steps: list[tuple[int, int]] = [] skipped_trajectories = 0 processed_trajectories = 0 # Check if language modality is configured has_language_modality = 'language' in self.modality_keys and len(self.modality_keys['language']) > 0 for trajectory_id, trajectory_length in tqdm(zip(self.trajectory_ids, self.trajectory_lengths), total=len(self.trajectory_ids), desc="Getting All Step"): data = self.get_trajectory_data(trajectory_id) trajectory_skipped = False # Check if trajectory has valid language instruction (if language modality is configured) if has_language_modality: self.curr_traj_data = data # Set current trajectory data for get_language to work try: language_instruction = self.get_language(trajectory_id, self.modality_keys['language'][0], 0) print(language_instruction) if not language_instruction or language_instruction[0] == "": print(f"Skipping trajectory {trajectory_id} due to empty language instruction") skipped_trajectories += 1 trajectory_skipped = True continue except Exception as e: print(f"Skipping trajectory {trajectory_id} due to language retrieval error: {e}") skipped_trajectories += 1 trajectory_skipped = True continue if not trajectory_skipped: processed_trajectories += 1 self.delete_pause_frame = False # FIXME if self.delete_pause_frame: # Get position and gripper fields based on available columns delta_position_values, gripper_values = self._get_position_and_gripper_values(data) previous_gripper = gripper_values[0] for base_index in range(trajectory_length): if base_index >= len(delta_position_values) or base_index >= len(gripper_values): break # Check for translation change using the detected position fields has_translation_change = np.any(np.abs(delta_position_values[base_index]) > EPSILON) has_gripper_change = gripper_values[base_index] != (previous_gripper if base_index == 0 else gripper_values[base_index-1]) if has_translation_change or has_gripper_change: all_steps.append((trajectory_id, base_index)) else: for base_index in range(trajectory_length): all_steps.append((trajectory_id, base_index)) # Print summary statistics print(f"Single-process summary: Processed {processed_trajectories} trajectories, skipped {skipped_trajectories} empty trajectories") print(f"Total steps: {len(all_steps)} from {len(self.trajectory_ids)} trajectories") return all_steps
def _get_position_and_gripper_values(self, data: pd.DataFrame) -> tuple[list, list]: """Get position and gripper values based on available columns in the dataset.""" # Get action keys from modality_keys action_keys = self.modality_keys.get('action', []) # Extract position data delta_position_values = None position_candidates = ['delta_eef_position'] coordinate_candidates = ['x', 'y', 'z'] # First try combined position fields for pos_key in position_candidates: full_key = f"action.{pos_key}" if full_key in action_keys: try: # Get the lerobot key for this modality le_action_cfg = self.lerobot_modality_meta.action subkey = pos_key if subkey in le_action_cfg: le_key = le_action_cfg[subkey].original_key or subkey if le_key in data.columns: data_array = np.stack(data[le_key]) le_indices = np.arange(le_action_cfg[subkey].start, le_action_cfg[subkey].end) filtered_data = data_array[:, le_indices] delta_position_values = filtered_data.tolist() break except Exception: continue # If combined fields not found, try individual x,y,z coordinates if delta_position_values is None: x_data, y_data, z_data = None, None, None for coord in coordinate_candidates: full_key = f"action.{coord}" if full_key in action_keys: try: le_action_cfg = self.lerobot_modality_meta.action if coord in le_action_cfg: le_key = le_action_cfg[coord].original_key or coord if le_key in data.columns: data_array = np.stack(data[le_key]) le_indices = np.arange(le_action_cfg[coord].start, le_action_cfg[coord].end) coord_data = data_array[:, le_indices].flatten() if coord == 'x': x_data = coord_data elif coord == 'y': y_data = coord_data elif coord == 'z': z_data = coord_data except Exception: continue if x_data is not None and y_data is not None and z_data is not None: delta_position_values = np.column_stack((x_data, y_data, z_data)).tolist() if delta_position_values is None: # Fallback to the old hardcoded approach if metadata approach fails if 'action.delta_eef_position' in data.columns: delta_position_values = data['action.delta_eef_position'].to_numpy().tolist() elif all(col in data.columns for col in ['action.x', 'action.y', 'action.z']): x_vals = data['action.x'].to_numpy() y_vals = data['action.y'].to_numpy() z_vals = data['action.z'].to_numpy() delta_position_values = np.column_stack((x_vals, y_vals, z_vals)).tolist() else: raise ValueError(f"No suitable position columns found. Available columns: {data.columns.tolist()}") # Extract gripper data gripper_values = None gripper_candidates = ['gripper_close', 'gripper'] for grip_key in gripper_candidates: full_key = f"action.{grip_key}" if full_key in action_keys: try: le_action_cfg = self.lerobot_modality_meta.action if grip_key in le_action_cfg: le_key = le_action_cfg[grip_key].original_key or grip_key if le_key in data.columns: data_array = np.stack(data[le_key]) le_indices = np.arange(le_action_cfg[grip_key].start, le_action_cfg[grip_key].end) gripper_data = data_array[:, le_indices].flatten() gripper_values = gripper_data.tolist() break except Exception: continue if gripper_values is None: # Fallback to the old hardcoded approach if metadata approach fails if 'action.gripper_close' in data.columns: gripper_values = data['action.gripper_close'].to_numpy().tolist() elif 'action.gripper' in data.columns: gripper_values = data['action.gripper'].to_numpy().tolist() else: raise ValueError(f"No suitable gripper columns found. Available columns: {data.columns.tolist()}") return delta_position_values, gripper_values
def _get_modality_keys(self) -> dict: """Get the modality keys for the dataset. The keys are the modality names, and the values are the keys for each modality. See property `modality_keys` for the expected format. """ modality_keys = defaultdict(list) for modality, config in self.modality_configs.items(): modality_keys[modality] = config.modality_keys return modality_keys
def _get_delta_indices(self) -> dict[str, np.ndarray]: """Restructure the delta indices to use modality.key as keys instead of just the modalities.""" delta_indices: dict[str, np.ndarray] = {} for config in self.modality_configs.values(): for key in config.modality_keys: delta_indices[key] = np.array(config.delta_indices) return delta_indices
def _get_lerobot_modality_meta(self) -> LeRobotModalityMetadata: """Get the metadata for the LeRobot dataset.""" modality_meta_path = self.dataset_path / LE_ROBOT_MODALITY_FILENAME assert ( modality_meta_path.exists() ), f"Please provide a {LE_ROBOT_MODALITY_FILENAME} file in {self.dataset_path}" with open(modality_meta_path, "r") as f: modality_meta = LeRobotModalityMetadata.model_validate(json.load(f)) return modality_meta
def _get_lerobot_info_meta(self) -> dict: """Get the metadata for the LeRobot dataset.""" info_meta_path = self.dataset_path / LE_ROBOT_INFO_FILENAME with open(info_meta_path, "r") as f: info_meta = json.load(f) return info_meta
def _get_data_path_pattern(self) -> str: """Get the data path pattern for the LeRobot dataset.""" return self.lerobot_info_meta["data_path"]
def _get_video_path_pattern(self) -> str: """Get the video path pattern for the LeRobot dataset.""" return self.lerobot_info_meta["video_path"]
def _get_chunk_size(self) -> int: """Get the chunk size for the LeRobot dataset.""" return self.lerobot_info_meta["chunks_size"]
def _get_tasks(self) -> pd.DataFrame: """Get the tasks for the dataset.""" tasks_path = self.dataset_path / LE_ROBOT_TASKS_FILENAME with open(tasks_path, "r") as f: tasks = [json.loads(line) for line in f] df = pd.DataFrame(tasks) return df.set_index("task_index")
def _check_integrity(self): """Use the config to check if the keys are valid and detect silent data corruption.""" ERROR_MSG_HEADER = f"Error occurred in initializing dataset {self.dataset_name}:\n"
for modality_config in self.modality_configs.values(): for key in modality_config.modality_keys: if key == "lapa_action" or key == "dream_actions": continue # no need for any metadata for lapa actions because it comes normalized # Check if the key is valid try: self.lerobot_modality_meta.get_key_meta(key) except Exception as e: raise ValueError( ERROR_MSG_HEADER + f"Unable to find key {key} in modality metadata:\n{e}" )
def set_transforms_metadata(self, metadata: DatasetMetadata): """Set the metadata for the transforms. This is useful for transforms that need to know the metadata, such as the normalization values.""" self.transforms.set_metadata(metadata)
def set_epoch(self, epoch: int): """Set the epoch for the dataset.
Args: epoch (int): The epoch to set. """ self.epoch = epoch
def __len__(self) -> int: """Get the total number of data points in the dataset.
Returns: int: the total number of data points in the dataset. """ return len(self.all_steps)
def __str__(self) -> str: """Get the description of the dataset.""" return f"{self.dataset_name} ({len(self)} steps)"
def __getitem__(self, index: int) -> dict: """Get the data for a single step in a trajectory.
Args: index (int): The index of the step to get.
Returns: dict: The data for the step. """ trajectory_id, base_index = self.all_steps[index] data = self.get_step_data(trajectory_id, base_index) # Process all video keys dynamically images = [] for video_key in self.modality_keys["video"]: image = data[video_key][0] # Apply image cropping if enabled and the video key is base_view # Note: crop_obs_camera functionality has been removed image = Image.fromarray(image).resize((224, 224)) images.append(image) # Get language and action data language = data[self.modality_keys["language"][0]][0] action = [] for action_key in self.modality_keys["action"]: action.append(data[action_key]) action = np.concatenate(action, axis=1) return dict(action=action, image=images, language=language)
def get_step_data(self, trajectory_id: int, base_index: int) -> dict: """Get the RAW data for a single step in a trajectory. No transforms are applied.
Args: trajectory_id (int): The name of the trajectory. base_index (int): The base step index in the trajectory.
Returns: dict: The RAW data for the step.
Example return: { "video": { "video.image_side_0": [B, T, H, W, C], "video.image_side_1": [B, T, H, W, C], }, "state": { "state.eef_position": [B, T, state_dim], "state.eef_rotation": [B, T, state_dim], }, "action": { "action.eef_position": [B, T, action_dim], "action.eef_rotation": [B, T, action_dim], }, } """ data = {} # Get the data for all modalities self.curr_traj_data = self.get_trajectory_data(trajectory_id) for modality in self.modality_keys: # Get the data corresponding to each key in the modality for key in self.modality_keys[modality]: data[key] = self.get_data_by_modality(trajectory_id, modality, key, base_index) return data
def _preload_all_trajectories(self): """预加载所有trajectories到内存""" print("Preloading all trajectories...") self._trajectory_cache = {} for trajectory_id in tqdm(self.trajectory_ids, desc="Loading trajectories"): chunk_index = self.get_episode_chunk(trajectory_id) parquet_path = self.dataset_path / self.data_path_pattern.format( episode_chunk=chunk_index, episode_index=trajectory_id ) self._trajectory_cache[trajectory_id] = pd.read_parquet(parquet_path) print(f"Preloaded {len(self._trajectory_cache)} trajectories")
def get_trajectory_data(self, trajectory_id: int) -> pd.DataFrame: """Get the data for a trajectory."""
if self.preload_all: return self._trajectory_cache[trajectory_id] else: if self.curr_traj_id == trajectory_id and self.curr_traj_data is not None: return self.curr_traj_data else: chunk_index = self.get_episode_chunk(trajectory_id) parquet_path = self.dataset_path / self.data_path_pattern.format( episode_chunk=chunk_index, episode_index=trajectory_id ) assert parquet_path.exists(), f"Parquet file not found at {parquet_path}" return pd.read_parquet(parquet_path)
def get_trajectory_index(self, trajectory_id: int) -> int: """Get the index of the trajectory in the dataset by the trajectory ID. This is useful when you need to get the trajectory length or sampling weight corresponding to the trajectory ID.
Args: trajectory_id (str): The ID of the trajectory.
Returns: int: The index of the trajectory in the dataset. """ trajectory_indices = np.where(self.trajectory_ids == trajectory_id)[0] if len(trajectory_indices) != 1: raise ValueError( f"Error finding trajectory index for {trajectory_id}, found {trajectory_indices}" ) return trajectory_indices[0]
def get_episode_chunk(self, ep_index: int) -> int: """Get the chunk index for an episode index.""" return ep_index // self.chunk_size
def retrieve_data_and_pad( self, array: np.ndarray, step_indices: np.ndarray, max_length: int, padding_strategy: str = "first_last", ) -> np.ndarray: """Retrieve the data from the dataset and pad it if necessary. Args: array (np.ndarray): The array to retrieve the data from. step_indices (np.ndarray): The step indices to retrieve the data for. max_length (int): The maximum length of the data. padding_strategy (str): The padding strategy, either "first" or "last". """ # Get the padding indices front_padding_indices = step_indices < 0 end_padding_indices = step_indices >= max_length padding_positions = np.logical_or(front_padding_indices, end_padding_indices) # Retrieve the data with the non-padding indices # If there exists some padding, Given T step_indices, the shape of the retrieved data will be (T', ...) where T' < T raw_data = array[step_indices[~padding_positions]] assert isinstance(raw_data, np.ndarray), f"{type(raw_data)=}" # This is the shape of the output, (T, ...) if raw_data.ndim == 1: expected_shape = (len(step_indices),) else: expected_shape = (len(step_indices), *array.shape[1:])
# Pad the data output = np.zeros(expected_shape) # Assign the non-padded data output[~padding_positions] = raw_data # If there exists some padding, pad the data if padding_positions.any(): if padding_strategy == "first_last": # Use first / last step data to pad front_padding_data = array[0] end_padding_data = array[-1] output[front_padding_indices] = front_padding_data output[end_padding_indices] = end_padding_data elif padding_strategy == "zero": # Use zero padding output[padding_positions] = 0 else: raise ValueError(f"Invalid padding strategy: {padding_strategy}") return output
def get_video_path(self, trajectory_id: int, key: str) -> Path: chunk_index = self.get_episode_chunk(trajectory_id) original_key = self.lerobot_modality_meta.video[key].original_key if original_key is None: original_key = key video_filename = self.video_path_pattern.format( episode_chunk=chunk_index, episode_index=trajectory_id, video_key=original_key ) return self.dataset_path / video_filename
def get_video( self, trajectory_id: int, key: str, base_index: int, ) -> np.ndarray: """Get the video frames for a trajectory by a base index.
Args: dataset (BaseSingleDataset): The dataset to retrieve the data from. trajectory_id (str): The ID of the trajectory. key (str): The key of the video. base_index (int): The base index of the trajectory.
Returns: np.ndarray: The video frames for the trajectory and frame indices. Shape: (T, H, W, C) """ # Get the step indices step_indices = self.delta_indices[key] + base_index # print(f"{step_indices=}") # Get the trajectory index trajectory_index = self.get_trajectory_index(trajectory_id) # Ensure the indices are within the valid range # This is equivalent to padding the video with extra frames at the beginning and end step_indices = np.maximum(step_indices, 0) step_indices = np.minimum(step_indices, self.trajectory_lengths[trajectory_index] - 1) assert key.startswith("video."), f"Video key must start with 'video.', got {key}" # Get the sub-key key = key.replace("video.", "") video_path = self.get_video_path(trajectory_id, key) # Get the action/state timestamps for each frame in the video assert self.curr_traj_data is not None, f"No data found for {trajectory_id}" assert "timestamp" in self.curr_traj_data.columns, f"No timestamp found in {trajectory_id}" timestamp: np.ndarray = self.curr_traj_data["timestamp"].to_numpy() # Get the corresponding video timestamps from the step indices video_timestamp = timestamp[step_indices]
return get_frames_by_timestamps( video_path.as_posix(), video_timestamp, video_backend=self.video_backend, video_backend_kwargs=self.video_backend_kwargs, step_indices_for_assert=step_indices, )
def get_state_or_action( self, trajectory_id: int, modality: str, key: str, base_index: int, ) -> np.ndarray: """Get the state or action data for a trajectory by a base index. If the step indices are out of range, pad with the data: if the data is stored in absolute format, pad with the first or last step data; otherwise, pad with zero.
Args: dataset (BaseSingleDataset): The dataset to retrieve the data from. trajectory_id (int): The ID of the trajectory. modality (str): The modality of the data. key (str): The key of the data. base_index (int): The base index of the trajectory.
Returns: np.ndarray: The data for the trajectory and step indices. """ # Get the step indices step_indices = self.delta_indices[key] + base_index # Get the trajectory index trajectory_index = self.get_trajectory_index(trajectory_id) # Get the maximum length of the trajectory max_length = self.trajectory_lengths[trajectory_index] assert key.startswith(modality + "."), f"{key} must start with {modality + '.'}, got {key}" # Get the sub-key, e.g. state.joint_angles -> joint_angles key = key.replace(modality + ".", "") # Get the lerobot key le_state_or_action_cfg = getattr(self.lerobot_modality_meta, modality) le_key = le_state_or_action_cfg[key].original_key if le_key is None: le_key = key # Get the data array, shape: (T, D) assert self.curr_traj_data is not None, f"No data found for {trajectory_id}" assert le_key in self.curr_traj_data.columns, f"No {le_key} found in {trajectory_id}" data_array: np.ndarray = np.stack(self.curr_traj_data[le_key]) # type: ignore assert data_array.ndim == 2, f"Expected 2D array, got key {le_key} is{data_array.shape} array" le_indices = np.arange( le_state_or_action_cfg[key].start, le_state_or_action_cfg[key].end, ) data_array = data_array[:, le_indices] # Get the state or action configuration state_or_action_cfg = getattr(self.metadata.modalities, modality)[key]
# Pad the data return self.retrieve_data_and_pad( array=data_array, step_indices=step_indices, max_length=max_length, padding_strategy="first_last" if state_or_action_cfg.absolute else "zero", # padding_strategy="first_last", # HACK for realdata )
def get_language( self, trajectory_id: int, key: str, base_index: int, ) -> list[str]: """Get the language annotation data for a trajectory by step indices.
Args: dataset (BaseSingleDataset): The dataset to retrieve the data from. trajectory_id (int): The ID of the trajectory. key (str): The key of the annotation. base_index (int): The base index of the trajectory.
Returns: list[str]: The annotation data for the trajectory and step indices. If no matching data is found, return empty strings. """ assert self.curr_traj_data is not None, f"No data found for {trajectory_id}" # Get the step indices step_indices = self.delta_indices[key] + base_index # Get the trajectory index trajectory_index = self.get_trajectory_index(trajectory_id) # Get the maximum length of the trajectory max_length = self.trajectory_lengths[trajectory_index] # Get the end times corresponding to the closest indices step_indices = np.maximum(step_indices, 0) step_indices = np.minimum(step_indices, max_length - 1) # Get the annotations task_indices: list[int] = [] assert key.startswith( "annotation." ), f"Language key must start with 'annotation.', got {key}" subkey = key.replace("annotation.", "") annotation_meta = self.lerobot_modality_meta.annotation assert annotation_meta is not None, f"Annotation metadata is None for {subkey}" assert ( subkey in annotation_meta ), f"Annotation key {subkey} not found in metadata, available annotation keys: {annotation_meta.keys()}" subkey_meta = annotation_meta[subkey] original_key = subkey_meta.original_key if original_key is None: original_key = key for i in range(len(step_indices)): task_indices.append(self.curr_traj_data[original_key][step_indices[i]].item()) return self.tasks.loc[task_indices]["description"].tolist() # 适配zhenyu脚本
def get_data_by_modality( self, trajectory_id: int, modality: str, key: str, base_index: int, ): """Get the data corresponding to the modality for a trajectory by a base index. This method will call the corresponding helper method based on the modality. See the helper methods for more details. NOTE: For the language modality, the data is padded with empty strings if no matching data is found.
Args: dataset (BaseSingleDataset): The dataset to retrieve the data from. trajectory_id (int): The ID of the trajectory. modality (str): The modality of the data. key (str): The key of the data. base_index (int): The base index of the trajectory. """ if modality == "video": return self.get_video(trajectory_id, key, base_index) elif modality == "state" or modality == "action": return self.get_state_or_action(trajectory_id, modality, key, base_index) elif modality == "language": return self.get_language(trajectory_id, key, base_index) else: raise ValueError(f"Invalid modality: {modality}")
def save_dataset_statistics(self, save_path: Path | str, format: str = "json") -> None: """ Save dataset statistics to specified path in the required format. Only includes statistics for keys that are actually used in the dataset. Gripper-related keys will be placed at the end. Args: save_path (Path | str): Path to save the statistics file format (str): Save format, currently only supports "json" """ save_path = Path(save_path) save_path.parent.mkdir(parents=True, exist_ok=True) # Build the data structure to save statistics_data = {} # Get used modality keys used_action_keys, used_state_keys = get_used_modality_keys(self.modality_keys) # Organize statistics by tag tag = self.tag tag_stats = {} # Process action statistics (only for used keys) if hasattr(self.metadata.statistics, 'action') and self.metadata.statistics.action: action_stats = self.metadata.statistics.action # Filter to only include used action keys and reorder: non-gripper first, gripper last non_gripper_keys = [] gripper_keys = [] for key in action_stats.keys(): if key in used_action_keys: if "gripper" in key.lower(): gripper_keys.append(key) else: non_gripper_keys.append(key) # Reorder: non-gripper first, gripper last reordered_keys = non_gripper_keys + gripper_keys filtered_action_stats = {} for key in reordered_keys: filtered_action_stats[key] = action_stats[key] if filtered_action_stats: # Combine statistics from filtered action sub-keys combined_action_stats = combine_modality_stats(filtered_action_stats) # Add mask field: based on whether it's gripper or not mask = generate_action_mask_for_used_keys( self.metadata.modalities.action, filtered_action_stats.keys() ) combined_action_stats["mask"] = mask tag_stats["action"] = combined_action_stats # Process state statistics (only for used keys) if hasattr(self.metadata.statistics, 'state') and self.metadata.statistics.state: state_stats = self.metadata.statistics.state # Filter to only include used state keys, optionally reorder gripper to end non_gripper_keys = [] gripper_keys = [] for key in state_stats.keys(): if key in used_state_keys: if "gripper" in key.lower(): gripper_keys.append(key) else: non_gripper_keys.append(key) # Reorder: non-gripper first, gripper last reordered_keys = non_gripper_keys + gripper_keys filtered_state_stats = {} for key in reordered_keys: filtered_state_stats[key] = state_stats[key] if filtered_state_stats: combined_state_stats = combine_modality_stats(filtered_state_stats) tag_stats["state"] = combined_state_stats # Add dataset counts tag_stats["num_transitions"] = len(self) tag_stats["num_trajectories"] = len(self.trajectory_ids) statistics_data[tag] = tag_stats # Save as JSON file if format.lower() == "json": if not str(save_path).endswith('.json'): save_path = save_path.with_suffix('.json') with open(save_path, 'w', encoding='utf-8') as f: json.dump(statistics_data, f, indent=2, ensure_ascii=False) else: raise ValueError(f"Unsupported format: {format}. Currently only 'json' is supported.") print(f"Single dataset statistics saved to: {save_path}") print(f"Used action keys (reordered): {list(used_action_keys)}") print(f"Used state keys (reordered): {list(used_state_keys)}")
class CachedLeRobotSingleDataset(LeRobotSingleDataset): def __init__(self, img_resize: tuple[int, int] | None = None, *args, **kwargs): """ This class caches the video frames for each trajectory and key. It is recommended to use this class if the video frames need to be accessed multiple times.
Args: resize_img (tuple[int, int], optional): The size to resize the video frames to reduce memory usage. """ # Convert img_resize to tuple if it is not already if img_resize is not None and not isinstance(img_resize, tuple): img_resize = tuple(img_resize) assert len(img_resize) == 2, f"Expected tuple of length 2, got {img_resize}" self.img_resize = img_resize
# Initialize img_resize attribute first to ensure it exists super().__init__(*args, **kwargs) cached_frames: dict[str, np.ndarray] = {}
for key in self.modality_keys["video"]: all_frames = [] original_key = key key = key.replace("video.", "") for trajectory_id, trajectory_length in tqdm( zip(self.trajectory_ids, self.trajectory_lengths), total=len(self.trajectory_ids), desc=f"Caching {key} frames", ): video_path = self.get_video_path(trajectory_id, key) frames = get_all_frames( video_path.as_posix(), video_backend=self.video_backend, video_backend_kwargs=self.video_backend_kwargs, resize_size=img_resize, ) assert frames.ndim == 4, f"Expected 4D array, got {frames.shape} array" assert frames.shape[3] == 3, f"Expected 3 channels, got {frames.shape[3]} channels" # Apply image cropping if enabled and the video key is base_view # Note: crop_obs_camera functionality has been removed # assert ( # frames.shape[0] == trajectory_length # ), f"Expected {trajectory_length} frames, got {frames.shape[0]} frames" all_frames.append(frames) cached_frames[key] = np.concatenate(all_frames, axis=0) print(f"{key}: {cached_frames[key].shape}") self.cached_frames = cached_frames self.start_indices = np.cumsum(self.trajectory_lengths) - self.trajectory_lengths
def get_video(self, trajectory_id: int, key: str, base_index: int) -> np.ndarray: step_indices = self.delta_indices[key] + base_index # Get the trajectory index trajectory_index = self.get_trajectory_index(trajectory_id) # Ensure the indices are within the valid range # This is equivalent to padding the video with extra frames at the beginning and end step_indices = np.maximum(step_indices, 0) step_indices = np.minimum(step_indices, self.trajectory_lengths[trajectory_index] - 1) assert key.startswith("video."), f"Video key must start with 'video.', got {key}" # Get the sub-key key = key.replace("video.", "") # Calculate the absolute indices absolute_indices = self.start_indices[trajectory_index] + step_indices return self.cached_frames[key][absolute_indices]
def get_step_data(self, trajectory_id: int, base_index: int) -> dict: """Get the RAW data for a single step. No transforms are applied.
Args: trajectory_id (str): The ID of the trajectory. base_index (int): The base index of the step.
Returns: dict: The data for the step. """ data = {} self.curr_traj_data = self.get_trajectory_data(trajectory_id) # Get the data for all modalities for modality in self.modality_keys: # Get the data corresponding to each key in the modality for key in self.modality_keys[modality]: data[key] = self.get_data_by_modality(trajectory_id, modality, key, base_index) return data
def set_transforms_metadata(self, metadata: DatasetMetadata): """Set the metadata for the transforms. This is useful for transforms that need to know the metadata, such as the normalization values.""" if self.img_resize is not None: all_video_keys = [key for key in self.modality_keys["video"]] for key in metadata.modalities.video: if key in all_video_keys: metadata.modalities.video[key].resolution = self.img_resize super().set_transforms_metadata(metadata)
def safe_hash(input_tuple): # keep 128 bits of the hash tuple_string = repr(input_tuple).encode("utf-8") sha256 = hashlib.sha256() sha256.update(tuple_string)
seed = int(sha256.hexdigest(), 16)
return seed & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
class MixtureSpecElement(BaseModel): dataset_path: list[Path] | Path = Field(..., description="The path to the dataset.") dataset_weight: float = Field(..., description="The weight of the dataset in the mixture.") distribute_weights: bool = Field( default=False, description="Whether to distribute the weights of the dataset across all the paths. If True, the weights will be evenly distributed across all the paths.", )
# Helper functions for dataset statistics
def combine_modality_stats(modality_stats: dict) -> dict: """ Combine statistics from all sub-keys under a modality. Args: modality_stats (dict): Statistics for a modality, containing multiple sub-keys. Each sub-key contains DatasetStatisticalValues object. Returns: dict: Combined statistics """ combined_stats = { "mean": [], "std": [], "max": [], "min": [], "q01": [], "q99": [] } # Combine statistics in sub-key order for subkey in modality_stats.keys(): subkey_stats = modality_stats[subkey] # This is a DatasetStatisticalValues object # Convert DatasetStatisticalValues to dict-like access for stat_name in ["mean", "std", "max", "min", "q01", "q99"]: stat_value = getattr(subkey_stats, stat_name) if isinstance(stat_value, (list, tuple)): combined_stats[stat_name].extend(stat_value) else: # Handle NDArray case - convert to list if hasattr(stat_value, 'tolist'): combined_stats[stat_name].extend(stat_value.tolist()) else: combined_stats[stat_name].append(float(stat_value)) return combined_stats
def generate_action_mask_for_used_keys(action_modalities: dict, used_action_keys_ordered) -> list[bool]: """ Generate mask based on action modalities, but only for used keys. Gripper-related are False, others are True. Args: action_modalities (dict): Configuration information for action modalities. used_action_keys_ordered: Iterable of actually used action keys in the correct order. Returns: list[bool]: List of mask values """ mask = [] # Generate mask in the same order as the statistics were combined for subkey in used_action_keys_ordered: if subkey in action_modalities: subkey_config = action_modalities[subkey] # Get dimension count from shape if hasattr(subkey_config, 'shape') and len(subkey_config.shape) > 0: dim_count = subkey_config.shape[0] else: dim_count = 1 # Check if it's gripper-related is_gripper = "gripper" in subkey.lower() # Generate mask value for each dimension for _ in range(dim_count): mask.append(not is_gripper) # gripper is False, others are True return mask
def get_used_modality_keys(modality_keys: dict) -> tuple[set, set]: """Extract used action and state keys from modality configuration.""" used_action_keys = set() used_state_keys = set() # Extract action keys (remove "action." prefix) for action_key in modality_keys.get("action", []): if action_key.startswith("action."): clean_key = action_key.replace("action.", "") used_action_keys.add(clean_key) # Extract state keys (remove "state." prefix) for state_key in modality_keys.get("state", []): if state_key.startswith("state."): clean_key = state_key.replace("state.", "") used_state_keys.add(clean_key) return used_action_keys, used_state_keys
class LeRobotMixtureDataset(Dataset): """ A mixture of multiple datasets. This class samples a single dataset based on the dataset weights and then calls the `__getitem__` method of the sampled dataset. It is recommended to modify the single dataset class instead of this class. """
def __init__( self, data_mixture: Sequence[tuple[LeRobotSingleDataset, float]], mode: str, balance_dataset_weights: bool = True, balance_trajectory_weights: bool = True, seed: int = 42, metadata_config: dict = { "percentile_mixing_method": "min_max", }, ): """ Initialize the mixture dataset.
Args: data_mixture (list[tuple[LeRobotSingleDataset, float]]): Datasets and their corresponding weights. mode (str): If "train", __getitem__ will return different samples every epoch; if "val" or "test", __getitem__ will return the same sample every epoch. balance_dataset_weights (bool): If True, the weight of dataset will be multiplied by the total trajectory length of each dataset. balance_trajectory_weights (bool): If True, sample trajectories within a dataset weighted by their length; otherwise, use equal weighting. seed (int): Random seed for sampling. """ datasets: list[LeRobotSingleDataset] = [] dataset_sampling_weights: list[float] = [] for dataset, weight in data_mixture: # Check if dataset is valid and has data if len(dataset) == 0: print(f"Warning: Skipping empty dataset {dataset.dataset_name}") continue datasets.append(dataset) dataset_sampling_weights.append(weight) if len(datasets) == 0: raise ValueError("No valid datasets found in the mixture. All datasets are empty.") self.datasets = datasets self.balance_dataset_weights = balance_dataset_weights self.balance_trajectory_weights = balance_trajectory_weights self.seed = seed self.mode = mode
# Set properties for sampling
# 1. Dataset lengths self._dataset_lengths = np.array([len(dataset) for dataset in self.datasets]) print(f"Dataset lengths: {self._dataset_lengths}")
# 2. Dataset sampling weights self._dataset_sampling_weights = np.array(dataset_sampling_weights) if self.balance_dataset_weights: self._dataset_sampling_weights *= self._dataset_lengths # Check for zero or negative weights before normalization if np.any(self._dataset_sampling_weights <= 0): print(f"Warning: Found zero or negative sampling weights: {self._dataset_sampling_weights}") # Set minimum weight to prevent division issues self._dataset_sampling_weights = np.maximum(self._dataset_sampling_weights, 1e-8) # Normalize weights weights_sum = self._dataset_sampling_weights.sum() if weights_sum == 0 or np.isnan(weights_sum): print(f"Error: Invalid weights sum: {weights_sum}") # Fallback to equal weights self._dataset_sampling_weights = np.ones(len(self.datasets)) / len(self.datasets) print(f"Fallback to equal weights") else: self._dataset_sampling_weights /= weights_sum
# 3. Trajectory sampling weights self._trajectory_sampling_weights: list[np.ndarray] = [] for i, dataset in enumerate(self.datasets): trajectory_sampling_weights = np.ones(len(dataset.trajectory_lengths)) if self.balance_trajectory_weights: trajectory_sampling_weights *= dataset.trajectory_lengths # Check for zero or negative weights before normalization if np.any(trajectory_sampling_weights <= 0): print(f"Warning: Dataset {i} has zero or negative trajectory weights") trajectory_sampling_weights = np.maximum(trajectory_sampling_weights, 1e-8) # Normalize weights weights_sum = trajectory_sampling_weights.sum() if weights_sum == 0 or np.isnan(weights_sum): print(f"Error: Dataset {i} has invalid trajectory weights sum: {weights_sum}") # Fallback to equal weights trajectory_sampling_weights = np.ones(len(dataset.trajectory_lengths)) / len(dataset.trajectory_lengths) else: trajectory_sampling_weights /= weights_sum self._trajectory_sampling_weights.append(trajectory_sampling_weights)
# 4. Primary dataset indices self._primary_dataset_indices = np.array(dataset_sampling_weights) == 1.0 if not np.any(self._primary_dataset_indices): print(f"Warning: No dataset with weight 1.0 found. Original weights: {dataset_sampling_weights}") # Fallback: use the dataset(s) with maximum weight as primary max_weight = max(dataset_sampling_weights) self._primary_dataset_indices = np.array(dataset_sampling_weights) == max_weight print(f"Using datasets with maximum weight {max_weight} as primary: {self._primary_dataset_indices}") if not np.any(self._primary_dataset_indices): # This should never happen, but just in case print("Error: Still no primary dataset found. Using first dataset as primary.") self._primary_dataset_indices = np.zeros(len(self.datasets), dtype=bool) self._primary_dataset_indices[0] = True
# Set the epoch and sample the first epoch self.set_epoch(0)
self.update_metadata(metadata_config)
@property def dataset_lengths(self) -> np.ndarray: """The lengths of each dataset.""" return self._dataset_lengths
@property def dataset_sampling_weights(self) -> np.ndarray: """The sampling weights for each dataset.""" return self._dataset_sampling_weights
@property def trajectory_sampling_weights(self) -> list[np.ndarray]: """The sampling weights for each trajectory in each dataset.""" return self._trajectory_sampling_weights
@property def primary_dataset_indices(self) -> np.ndarray: """The indices of the primary datasets.""" return self._primary_dataset_indices
def __str__(self) -> str: dataset_descriptions = [] for dataset, weight in zip(self.datasets, self.dataset_sampling_weights): dataset_description = { "Dataset": str(dataset), "Sampling weight": float(weight), } dataset_descriptions.append(dataset_description) return json.dumps({"Mixture dataset": dataset_descriptions}, indent=2)
def set_epoch(self, epoch: int): """Set the epoch for the dataset.
Args: epoch (int): The epoch to set. """ self.epoch = epoch # self.sampled_steps = self.sample_epoch()
def sample_step(self, index: int) -> tuple[LeRobotSingleDataset, int, int]: """Sample a single step from the dataset.""" # return self.sampled_steps[index]
# Set seed seed = index if self.mode != "train" else safe_hash((self.epoch, index, self.seed)) rng = np.random.default_rng(seed)
# Sample dataset dataset_index = rng.choice(len(self.datasets), p=self.dataset_sampling_weights) dataset = self.datasets[dataset_index]
# Sample trajectory # trajectory_index = rng.choice( # len(dataset.trajectory_ids), p=self.trajectory_sampling_weights[dataset_index] # ) # trajectory_id = dataset.trajectory_ids[trajectory_index]
# # Sample step # base_index = rng.choice(dataset.trajectory_lengths[trajectory_index]) # return dataset, trajectory_id, base_index single_step_index = rng.choice(len(dataset.all_steps)) trajectory_id, base_index = dataset.all_steps[single_step_index] return dataset, trajectory_id, base_index
def sample_step_with_shuffle_is_true(self, index: int) -> tuple[LeRobotSingleDataset, int, int]: """Sample a single step from the dataset.""" '''only use this when DataLoader is initialized with shuffle=True''' print(index) # return self.sampled_steps[index]
# Set seed # seed = index if self.mode != "train" else safe_hash((self.epoch, index, self.seed)) # rng = np.random.default_rng(seed)
# Sample dataset # dataset_index = rng.choice(len(self.datasets), p=self.dataset_sampling_weights) # dataset = self.datasets[dataset_index] dataset = self.datasets[0] #FIXME
# Sample trajectory # trajectory_index = rng.choice( # len(dataset.trajectory_ids), p=self.trajectory_sampling_weights[dataset_index] # ) # trajectory_id = dataset.trajectory_ids[trajectory_index]
# # Sample step # base_index = rng.choice(dataset.trajectory_lengths[trajectory_index]) # return dataset, trajectory_id, base_index # no random, follow the order of the dataset # single_step_index = rng.choice(len(dataset.all_steps)) # trajectory_id, base_index = dataset.all_steps[single_step_index]
trajectory_id, base_index = dataset.all_steps[index] return dataset, trajectory_id, base_index
def __getitem__(self, index: int) -> dict: """Get the data for a single trajectory and start index.
Args: index (int): The index of the trajectory to get.
Returns: dict: The data for the trajectory and start index. """ max_retries = 10 last_exception = None for attempt in range(max_retries): try: dataset, trajectory_name, step = self.sample_step(index) data = dataset.transforms(dataset.get_step_data(trajectory_name, step)) # Process all video keys dynamically images = [] for video_key in dataset.modality_keys["video"]: image = data[video_key][0] # Apply image cropping if enabled and the video key is base_view # Note: crop_obs_camera functionality has been removed image = Image.fromarray(image).resize((224, 224)) # # use time stamp as filename # import time # filename = f"/hfm/boqian/storage/tmp/image_{int(time.time())}_{index}.png" # image.save(filename) images.append(image) # Get language and action data language = data[dataset.modality_keys["language"][0]][0] action = [] for action_key in dataset.modality_keys["action"]: action.append(data[action_key]) action = np.concatenate(action, axis=1).astype(np.float16) return dict(action=action, image=images, lang=language) except Exception as e: last_exception = e if attempt < max_retries - 1: # Log the error but continue trying print(f"Attempt {attempt + 1}/{max_retries} failed for index {index}: {e}") print(f"Retrying with new sample...") # For retry, we can use a slightly different index to get a new sample # This helps avoid getting stuck on the same problematic sample index = (index + 1) % len(self) else: # All retries exhausted print(f"All {max_retries} attempts failed for index {index}") print(f"Last error: {last_exception}") # Return a dummy sample or re-raise the exception raise last_exception
def __len__(self) -> int: """Get the length of a single epoch in the mixture.
Returns: int: The length of a single epoch in the mixture. """ # Check for potential issues if len(self.datasets) == 0: return 0 # Check if any dataset lengths are 0 or NaN if np.any(self.dataset_lengths == 0) or np.any(np.isnan(self.dataset_lengths)): print(f"Warning: Found zero or NaN dataset lengths: {self.dataset_lengths}") # Filter out zero/NaN length datasets valid_indices = (self.dataset_lengths > 0) & (~np.isnan(self.dataset_lengths)) if not np.any(valid_indices): print("Error: All datasets have zero or NaN length") return 0 else: valid_indices = np.ones(len(self.datasets), dtype=bool) # Check if any sampling weights are 0 or NaN if np.any(self.dataset_sampling_weights == 0) or np.any(np.isnan(self.dataset_sampling_weights)): print(f"Warning: Found zero or NaN sampling weights: {self.dataset_sampling_weights}") # Use only valid weights valid_weights = (self.dataset_sampling_weights > 0) & (~np.isnan(self.dataset_sampling_weights)) valid_indices = valid_indices & valid_weights if not np.any(valid_indices): print("Error: All sampling weights are zero or NaN") return 0 # Check primary dataset indices primary_and_valid = self.primary_dataset_indices & valid_indices if not np.any(primary_and_valid): print(f"Warning: No valid primary datasets found. Primary indices: {self.primary_dataset_indices}, Valid indices: {valid_indices}") # Fallback: use the largest valid dataset if np.any(valid_indices): max_length = self.dataset_lengths[valid_indices].max() print(f"Fallback: Using maximum dataset length: {max_length}") return int(max_length) else: return 0 # Calculate the ratio and get max ratios = (self.dataset_lengths / self.dataset_sampling_weights)[primary_and_valid] # Check for NaN or inf in ratios if np.any(np.isnan(ratios)) or np.any(np.isinf(ratios)): print(f"Warning: Found NaN or inf in ratios: {ratios}") print(f"Dataset lengths: {self.dataset_lengths[primary_and_valid]}") print(f"Sampling weights: {self.dataset_sampling_weights[primary_and_valid]}") # Filter out invalid ratios valid_ratios = ratios[~np.isnan(ratios) & ~np.isinf(ratios)] if len(valid_ratios) == 0: print("Error: All ratios are NaN or inf") return 0 max_ratio = valid_ratios.max() else: max_ratio = ratios.max() result = int(max_ratio) if result == 0: print(f"Warning: Dataset mixture length is 0") return result
@staticmethod def compute_overall_statistics( per_task_stats: list[dict[str, dict[str, list[float] | np.ndarray]]], dataset_sampling_weights: list[float] | np.ndarray, percentile_mixing_method: str = "weighted_average", ) -> dict[str, dict[str, list[float]]]: """ Computes overall statistics from per-task statistics using dataset sample weights.
Args: per_task_stats: List of per-task statistics. Example format of one element in the per-task statistics list: { "state.gripper": { "min": [...], "max": [...], "mean": [...], "std": [...], "q01": [...], "q99": [...], }, ... } dataset_sampling_weights: List of sample weights for each task. percentile_mixing_method: The method to mix the percentiles, either "weighted_average" or "weighted_std".
Returns: A dict of overall statistics per modality. """ # Normalize the sample weights to sum to 1 dataset_sampling_weights = np.array(dataset_sampling_weights) normalized_weights = dataset_sampling_weights / dataset_sampling_weights.sum()
# Initialize overall statistics dict overall_stats: dict[str, dict[str, list[float]]] = {}
# Get the list of modality keys modality_keys = per_task_stats[0].keys()
for modality in modality_keys: # Number of dimensions (assuming consistent across tasks) num_dims = len(per_task_stats[0][modality]["mean"])
# Initialize accumulators for means and variances weighted_means = np.zeros(num_dims) weighted_squares = np.zeros(num_dims)
# Collect min, max, q01, q99 from all tasks min_list = [] max_list = [] q01_list = [] q99_list = []
for task_idx, task_stats in enumerate(per_task_stats): w_i = normalized_weights[task_idx] stats = task_stats[modality] means = np.array(stats["mean"]) stds = np.array(stats["std"])
# Update weighted sums for mean and variance weighted_means += w_i * means weighted_squares += w_i * (stds**2 + means**2)
# Collect min, max, q01, q99 min_list.append(stats["min"]) max_list.append(stats["max"]) q01_list.append(stats["q01"]) q99_list.append(stats["q99"])
# Compute overall mean overall_mean = weighted_means.tolist()
# Compute overall variance and std deviation overall_variance = weighted_squares - weighted_means**2 overall_std = np.sqrt(overall_variance).tolist()
# Compute overall min and max per dimension overall_min = np.min(np.array(min_list), axis=0).tolist() overall_max = np.max(np.array(max_list), axis=0).tolist()
# Compute overall q01 and q99 per dimension # Use weighted average of per-task quantiles q01_array = np.array(q01_list) q99_array = np.array(q99_list) if percentile_mixing_method == "weighted_average": weighted_q01 = np.average(q01_array, axis=0, weights=normalized_weights).tolist() weighted_q99 = np.average(q99_array, axis=0, weights=normalized_weights).tolist() # std_q01 = np.std(q01_array, axis=0).tolist() # std_q99 = np.std(q99_array, axis=0).tolist() # print(modality) # print(f"{std_q01=}, {std_q99=}") # print(f"{weighted_q01=}, {weighted_q99=}") elif percentile_mixing_method == "min_max": weighted_q01 = np.min(q01_array, axis=0).tolist() weighted_q99 = np.max(q99_array, axis=0).tolist() else: raise ValueError(f"Invalid percentile mixing method: {percentile_mixing_method}")
# Store the overall statistics for the modality overall_stats[modality] = { "min": overall_min, "max": overall_max, "mean": overall_mean, "std": overall_std, "q01": weighted_q01, "q99": weighted_q99, }
return overall_stats
@staticmethod def merge_metadata( metadatas: list[DatasetMetadata], dataset_sampling_weights: list[float], percentile_mixing_method: str, ) -> DatasetMetadata: """Merge multiple metadata into one.""" # Convert to dicts metadata_dicts = [metadata.model_dump(mode="json") for metadata in metadatas] # Create a new metadata dict merged_metadata = {}
# Check all metadata have the same embodiment tag assert all( metadata.embodiment_tag == metadatas[0].embodiment_tag for metadata in metadatas ), "All metadata must have the same embodiment tag" merged_metadata["embodiment_tag"] = metadatas[0].embodiment_tag
# Merge the dataset statistics dataset_statistics = {} dataset_statistics["state"] = LeRobotMixtureDataset.compute_overall_statistics( per_task_stats=[m["statistics"]["state"] for m in metadata_dicts], dataset_sampling_weights=dataset_sampling_weights, percentile_mixing_method=percentile_mixing_method, ) dataset_statistics["action"] = LeRobotMixtureDataset.compute_overall_statistics( per_task_stats=[m["statistics"]["action"] for m in metadata_dicts], dataset_sampling_weights=dataset_sampling_weights, percentile_mixing_method=percentile_mixing_method, ) merged_metadata["statistics"] = dataset_statistics
# Merge the modality configs modality_configs = defaultdict(set) for metadata in metadata_dicts: for modality, configs in metadata["modalities"].items(): modality_configs[modality].add(json.dumps(configs)) merged_metadata["modalities"] = {} for modality, configs in modality_configs.items(): # Check that all modality configs correspond to the same tag matches assert ( len(configs) == 1 ), f"Multiple modality configs for modality {modality}: {list(configs)}" merged_metadata["modalities"][modality] = json.loads(configs.pop())
return DatasetMetadata.model_validate(merged_metadata)
def update_metadata(self, metadata_config: dict, cached_statistics_path: Path | str | None = None) -> None: """ Merge multiple metadatas into one and set the transforms with the merged metadata.
Args: metadata_config (dict): Configuration for the metadata. "percentile_mixing_method": The method to mix the percentiles, either "weighted_average" or "min_max". weighted_average: Use the weighted average of the percentiles using the weight used in sampling the datasets. min_max: Use the min of the 1st percentile and max of the 99th percentile. """ # If cached path is provided, try to load and apply if cached_statistics_path is not None: try: cached_stats = self.load_merged_statistics(cached_statistics_path) self.apply_cached_statistics(cached_stats) return except (FileNotFoundError, KeyError, ValidationError) as e: print(f"Failed to load cached statistics: {e}") print("Falling back to computing statistics from scratch...")
self.tag = EmbodimentTag.NEW_EMBODIMENT.value self.merged_metadata: dict[str, DatasetMetadata] = {} # Group metadata by tag all_metadatas: dict[str, list[DatasetMetadata]] = {} for dataset in self.datasets: if dataset.tag not in all_metadatas: all_metadatas[dataset.tag] = [] all_metadatas[dataset.tag].append(dataset.metadata) for tag, metadatas in all_metadatas.items(): self.merged_metadata[tag] = self.merge_metadata( metadatas=metadatas, dataset_sampling_weights=self.dataset_sampling_weights.tolist(), percentile_mixing_method=metadata_config["percentile_mixing_method"], ) for dataset in self.datasets: dataset.set_transforms_metadata(self.merged_metadata[dataset.tag])
def save_dataset_statistics(self, save_path: Path | str, format: str = "json") -> None: """ Save merged dataset statistics to specified path in the required format. Only includes statistics for keys that are actually used in the datasets. Gripper-related keys will be placed at the end. Args: save_path (Path | str): Path to save the statistics file format (str): Save format, currently only supports "json" """ save_path = Path(save_path) save_path.parent.mkdir(parents=True, exist_ok=True) # Build the data structure to save statistics_data = {} # Collect actually used keys from all datasets all_used_action_keys = set() all_used_state_keys = set() for dataset in self.datasets: used_action_keys, used_state_keys = get_used_modality_keys(dataset.modality_keys) all_used_action_keys.update(used_action_keys) all_used_state_keys.update(used_state_keys) # Organize statistics by tag for tag, merged_metadata in self.merged_metadata.items(): tag_stats = {} # Process action statistics if hasattr(merged_metadata.statistics, 'action') and merged_metadata.statistics.action: action_stats = merged_metadata.statistics.action # Filter and reorder keys non_gripper_keys = [] gripper_keys = [] for key in action_stats.keys(): if key in all_used_action_keys: if "gripper" in key.lower(): gripper_keys.append(key) else: non_gripper_keys.append(key) reordered_keys = non_gripper_keys + gripper_keys filtered_action_stats = {} for key in reordered_keys: filtered_action_stats[key] = action_stats[key] if filtered_action_stats: combined_action_stats = combine_modality_stats(filtered_action_stats) mask = generate_action_mask_for_used_keys( merged_metadata.modalities.action, filtered_action_stats.keys() ) combined_action_stats["mask"] = mask tag_stats["action"] = combined_action_stats # Process state statistics if hasattr(merged_metadata.statistics, 'state') and merged_metadata.statistics.state: state_stats = merged_metadata.statistics.state # Filter and reorder keys non_gripper_keys = [] gripper_keys = [] for key in state_stats.keys(): if key in all_used_state_keys: if "gripper" in key.lower(): gripper_keys.append(key) else: non_gripper_keys.append(key) reordered_keys = non_gripper_keys + gripper_keys filtered_state_stats = {} for key in reordered_keys: filtered_state_stats[key] = state_stats[key] if filtered_state_stats: combined_state_stats = combine_modality_stats(filtered_state_stats) tag_stats["state"] = combined_state_stats # Add dataset counts tag_stats.update(self._get_dataset_counts(tag)) statistics_data[tag] = tag_stats # Save file if format.lower() == "json": if not str(save_path).endswith('.json'): save_path = save_path.with_suffix('.json') with open(save_path, 'w', encoding='utf-8') as f: json.dump(statistics_data, f, indent=2, ensure_ascii=False) else: raise ValueError(f"Unsupported format: {format}. Currently only 'json' is supported.") print(f"Merged dataset statistics saved to: {save_path}") print(f"Used action keys (reordered): {list(all_used_action_keys)}") print(f"Used state keys (reordered): {list(all_used_state_keys)}")
def _combine_modality_stats(self, modality_stats: dict) -> dict: """Backward compatibility wrapper.""" return combine_modality_stats(modality_stats)
def _generate_action_mask_for_used_keys(self, action_modalities: dict, used_action_keys_ordered) -> list[bool]: """Backward compatibility wrapper.""" return generate_action_mask_for_used_keys(action_modalities, used_action_keys_ordered)
def _get_dataset_counts(self, tag: str) -> dict: """ Get dataset count information for specified tag. Args: tag (str): embodiment tag Returns: dict: Dictionary containing num_transitions and num_trajectories """ num_transitions = 0 num_trajectories = 0 # Count dataset information belonging to this tag for dataset in self.datasets: if dataset.tag == tag: num_transitions += len(dataset) num_trajectories += len(dataset.trajectory_ids) return { "num_transitions": num_transitions, "num_trajectories": num_trajectories }
@classmethod def load_merged_statistics(cls, load_path: Path | str) -> dict: """ Load merged dataset statistics from file. Args: load_path (Path | str): Path to the statistics file Returns: dict: Dictionary containing merged statistics """ load_path = Path(load_path) if not load_path.exists(): raise FileNotFoundError(f"Statistics file not found: {load_path}") if load_path.suffix.lower() == '.json': with open(load_path, 'r', encoding='utf-8') as f: return json.load(f) elif load_path.suffix.lower() == '.pkl': import pickle with open(load_path, 'rb') as f: return pickle.load(f) else: raise ValueError(f"Unsupported file format: {load_path.suffix}")
def apply_cached_statistics(self, cached_statistics: dict) -> None: """ Apply cached statistics to avoid recomputation. Args: cached_statistics (dict): Statistics loaded from file """ # Validate that cached statistics match current datasets if "metadata" in cached_statistics: cached_dataset_names = set(cached_statistics["metadata"]["dataset_names"]) current_dataset_names = set(dataset.dataset_name for dataset in self.datasets) if cached_dataset_names != current_dataset_names: print("Warning: Cached statistics dataset names don't match current datasets.") print(f"Cached: {cached_dataset_names}") print(f"Current: {current_dataset_names}") return # Apply cached statistics self.merged_metadata = {} for tag, stats_data in cached_statistics.items(): if tag == "metadata": # Skip metadata field continue # Convert back to DatasetMetadata format metadata_dict = { "embodiment_tag": tag, "statistics": { "action": {}, "state": {} }, "modalities": {} } # Convert action statistics back if "action" in stats_data: action_data = stats_data["action"] # This is simplified - you may need to split back to sub-keys metadata_dict["statistics"]["action"] = action_data # Convert state statistics back if "state" in stats_data: state_data = stats_data["state"] metadata_dict["statistics"]["state"] = state_data self.merged_metadata[tag] = DatasetMetadata.model_validate(metadata_dict) # Update transforms metadata for each dataset for dataset in self.datasets: if dataset.tag in self.merged_metadata: dataset.set_transforms_metadata(self.merged_metadata[dataset.tag]) print(f"Applied cached statistics for {len(self.merged_metadata)} embodiment tags.")nix/lib/runtime.nixAdded+74
nix/runtime-base.nixAdded+49
nix/runtime-host-gpu.nixAdded+101
nix/runtime.nixAdded+14
scripts/deepspeed/zero2.jsonAdded+23
scripts/deepspeed/zero3.jsonAdded+29
scripts/deepspeed/zero3_offload.jsonAdded+56
scripts/infer/multiturn_auto_scenario_backchannel_train_v1.jsonAdded+48
scripts/infer/multiturn_auto_scenario_backchannel_val_v1.jsonAdded+48
scripts/infer/multiturn_auto_scenario_emergency_stop_train_v1.jsonAdded+48
scripts/infer/multiturn_auto_scenario_emergency_stop_val_v1.jsonAdded+40
scripts/infer/multiturn_auto_scenario_hesitation_filled_train_v2.jsonAdded+60
scripts/infer/multiturn_auto_scenario_hesitation_filled_val_v2.jsonAdded+60
scripts/infer/multiturn_auto_scenario_hesitation_repair_train_v1.jsonAdded+42
scripts/infer/multiturn_auto_scenario_hesitation_repair_train_v2.jsonAdded+63
scripts/infer/multiturn_auto_scenario_hesitation_repair_val_v1.jsonAdded+42
scripts/infer/multiturn_auto_scenario_hesitation_repair_val_v2.jsonAdded+62
scripts/infer/multiturn_auto_scenario_interruption_train_v1.jsonAdded+60
scripts/infer/multiturn_auto_scenario_pause_train_v1.jsonAdded+41
scripts/infer/multiturn_auto_scenario_pause_train_v2.jsonAdded+60
scripts/infer/multiturn_auto_scenario_safe_hold_val_v1.jsonAdded+40
scripts/infer/multiturn_auto_scenario_v1.jsonAdded+61
scripts/infer/multiturn_auto_scenario_val_v1.jsonAdded+100
scripts/infer/multiturn_auto_suite_v2.jsonAdded+92
scripts/infer/multiturn_auto_suite_v3.jsonAdded+92
scripts/infer/mux_full_duplex_audio.pyAdded+180
scripts/infer/render_third_party_review.pyAdded+287
scripts/infer/render_third_party_scale.pyAdded+151
scripts/infer/run_multiturn_infer_suite.pyAdded+700
scripts/infer/seed_audio_to_motion.pyAdded+530
scripts/infer/seed_motion_teacher_reconstruct.pyAdded+504
scripts/infer/seed_text_to_motion.pyAdded+873
scripts/infer/seed_video_to_motion.pyAdded+548
scripts/infer/third_party_checkpoint_probe.pyAdded+434
scripts/infer/third_party_scale_metrics.pyAdded+172
src/InternVLA-M1/InternVLA/__init__.pyAdded
src/InternVLA-M1/InternVLA/config/deepseeds/deepspeed_zero2.yamlAdded+10
src/InternVLA-M1/InternVLA/config/deepseeds/ds_config.yamlAdded+28
src/InternVLA-M1/InternVLA/config/deepseeds/zero2.yamlAdded+21
src/InternVLA-M1/InternVLA/config/deepseeds/zero3.jsonAdded+28
src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_custom.yamlAdded+126
src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_humanoid.yamlAdded+128
src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_libero.yamlAdded+126
src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_oxe.yamlAdded+100
src/InternVLA-M1/InternVLA/config/training/internvla_cotrain_sim_demo.yamlAdded+124
src/InternVLA-M1/InternVLA/dataloader/__init__.pyAdded+63
src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/README.mdAdded
src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/__init__.pyAdded
src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/data_config.pyAdded+770
src/InternVLA-M1/InternVLA/dataloader/gr00t_lerobot/datasets.pyAdded+2118