diffneusim 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffneusim/__init__.py +1 -0
- diffneusim/_cache.py +42 -0
- diffneusim/_paths.py +5 -0
- diffneusim/bindings/rew14_ext.cu +115 -0
- diffneusim/bindings/soft14_capi.cpp +443 -0
- diffneusim/bindings/soft14_engine_ext.cu +596 -0
- diffneusim/bindings/soft_capi.cpp +782 -0
- diffneusim/bindings/soft_engine_ext.cu +495 -0
- diffneusim/core/cpu_engine/build.sh +40 -0
- diffneusim/core/cpu_engine/fiber/cuda_runtime.h +445 -0
- diffneusim/core/cpu_engine/x14_cpu.cpp +283 -0
- diffneusim/core/diff/dual.h +126 -0
- diffneusim/core/include/diffneusim/macros.h +35 -0
- diffneusim/core/kin/kinematic_tree.h +273 -0
- diffneusim/core/math/so3.h +182 -0
- diffneusim/core/soft/adj/out_adj.h +102 -0
- diffneusim/core/soft/adj/rnea_adj.h +425 -0
- diffneusim/core/soft/adj/rows_adj.h +439 -0
- diffneusim/core/soft/adj/rows_functor.h +89 -0
- diffneusim/core/soft/adj/rows_lanes.h +443 -0
- diffneusim/core/soft/adj/shell_adj.h +243 -0
- diffneusim/core/soft/adj/tree_adj.h +356 -0
- diffneusim/core/soft/collide.h +183 -0
- diffneusim/core/soft/gpu/adj14.cuh +233 -0
- diffneusim/core/soft/gpu/adj14_mus.cuh +98 -0
- diffneusim/core/soft/gpu/adj_shell.cuh +50 -0
- diffneusim/core/soft/gpu/adj_tab.cuh +49 -0
- diffneusim/core/soft/gpu/body14.cuh +47 -0
- diffneusim/core/soft/gpu/chol_rn.cuh +458 -0
- diffneusim/core/soft/gpu/chol_small.cuh +123 -0
- diffneusim/core/soft/gpu/chol_split.cuh +193 -0
- diffneusim/core/soft/gpu/engine_launch.cuh +263 -0
- diffneusim/core/soft/gpu/fk_rn.cuh +109 -0
- diffneusim/core/soft/gpu/generated/body_019e20820f86_mmfloor.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_62f77a4bb16b_mmfloor.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +28 -0
- diffneusim/core/soft/gpu/generated/body_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +52 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor.cuh +25 -0
- diffneusim/core/soft/gpu/generated/body_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +25 -0
- diffneusim/core/soft/gpu/generated/g1_soft_5db44fd45286.cuh +74 -0
- diffneusim/core/soft/gpu/generated/split_62f77a4bb16b_mmfloor.cuh +18 -0
- diffneusim/core/soft/gpu/generated/split_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +18 -0
- diffneusim/core/soft/gpu/generated/x14_soft_019e20820f86_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_62f77a4bb16b_mmfloor.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_77dbb7213f26_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsd05_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsdef_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_8989b60e4486_mmfloor_rhlsmjd_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a1e8b196b2cd_mmfloor_rampsb3l_n6t12.cuh +129 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor.cuh +123 -0
- diffneusim/core/soft/gpu/generated/x14_soft_a944653edd64_mmfloor_rampsb3l_n6t12.cuh +123 -0
- diffneusim/core/soft/gpu/k_mus.cuh +1038 -0
- diffneusim/core/soft/gpu/k_mus_host.cuh +377 -0
- diffneusim/core/soft/gpu/k_pre.cuh +52 -0
- diffneusim/core/soft/gpu/kernel_p.cuh +490 -0
- diffneusim/core/soft/gpu/kp14.cuh +465 -0
- diffneusim/core/soft/gpu/l2v2.cuh +367 -0
- diffneusim/core/soft/gpu/l2x14.cuh +319 -0
- diffneusim/core/soft/gpu/l3.cuh +1483 -0
- diffneusim/core/soft/gpu/model_view.cuh +48 -0
- diffneusim/core/soft/gpu/mus_case_fits.h +15 -0
- diffneusim/core/soft/gpu/mus_classes.h +182 -0
- diffneusim/core/soft/gpu/mus_row_cf.h +44 -0
- diffneusim/core/soft/gpu/rew14.cuh +177 -0
- diffneusim/core/soft/gpu/rows_ctab.cuh +44 -0
- diffneusim/core/soft/gpu/tree_m.cuh +247 -0
- diffneusim/core/soft/gpu/x14_engine_kernels.cuh +260 -0
- diffneusim/core/soft/gpu/x14_rowcf.h +14 -0
- diffneusim/core/soft/hand.h +124 -0
- diffneusim/core/soft/impedance.h +115 -0
- diffneusim/core/soft/jvp.h +202 -0
- diffneusim/core/soft/kin.h +250 -0
- diffneusim/core/soft/muscle.h +1208 -0
- diffneusim/core/soft/newton.h +371 -0
- diffneusim/core/soft/rows.h +176 -0
- diffneusim/core/soft/step.h +188 -0
- diffneusim/core/soft/tape.h +313 -0
- diffneusim/core/soft/x14/collide14.h +69 -0
- diffneusim/core/soft/x14/jvp14.h +182 -0
- diffneusim/core/soft/x14/law14.h +453 -0
- diffneusim/core/soft/x14adj/collide14_adj.h +134 -0
- diffneusim/core/soft/x14adj/passive14_adj.h +162 -0
- diffneusim/core/soft/x14adj/reward14.h +484 -0
- diffneusim/core/soft/x14adj/rows14_adj.h +400 -0
- diffneusim/core/soft/x14adj/scan14.h +349 -0
- diffneusim/core/soft/x14adj/shell14_adj.h +122 -0
- diffneusim/core/soft/x14adj/sweep14.h +255 -0
- diffneusim/core/soft/x14adj/tree14_adj.h +500 -0
- diffneusim/core/soft/x14adj/x14adj_common.h +96 -0
- diffneusim/data/mirror/H1622v2k_geyer_hfdeq.npz +0 -0
- diffneusim/data/mirror/H1622v2k_hfd.npz +0 -0
- diffneusim/data/mirror/H1622v2k_millard_hfdeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_p2str_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_calf2_pe.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01legs.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_jd01lumbar.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfix.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_lumbfixlegs01.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_hinge.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1a.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n2.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_rom23.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_fusedhand_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_millard.npz +0 -0
- diffneusim/data/mirror/fullbody_contact_spinecoupled_lspine_girdle_osimeq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_compound_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_luispe.npz +0 -0
- diffneusim/data/mirror/myoleg26_3d_kneeexp_g14eq_trunkpose_spin_ank30_hip30_trunk0701.npz +0 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_axfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01legs.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_jd01lumbar.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfix.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_lumbfixlegs01.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n1a.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_n2.json +91 -0
- diffneusim/data/muscle_fit/wang_mass_volume_14t_rom23.json +91 -0
- diffneusim/data/reference/musclemimic/myofullbody_mimic_sites.json +261 -0
- diffneusim/data/reference/pose3/pose3_scone.json +305 -0
- diffneusim/data/reference/pose3/pose3_scone.txt +3 -0
- diffneusim/data/reference/pose3/pose3_scone_gait.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_mirror.npz +0 -0
- diffneusim/data/reference/pose3/pose3_scone_stand.npz +0 -0
- diffneusim/data/reference/x016run/MD5SUMS +241 -0
- diffneusim/data/reference/x016run/x016run_states.txt +240 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p00_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s4_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p25_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p50_s7_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s0_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s1_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s2_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s3_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s5_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s6_r3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_l3.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r0.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r1.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r2.npz +0 -0
- diffneusim/data/reference/x016run/x016run_v3p75_s7_r3.npz +0 -0
- diffneusim/data/state_prior/lumbar_poly_fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc.npz +0 -0
- diffneusim/engine/__init__.py +0 -0
- diffneusim/engine/build_tag.py +52 -0
- diffneusim/engine/case_tables.py +46 -0
- diffneusim/engine/d16_body.py +80 -0
- diffneusim/engine/engine14.py +367 -0
- diffneusim/engine/gen_split.py +159 -0
- diffneusim/engine/hand_format.py +69 -0
- diffneusim/engine/live14.py +149 -0
- diffneusim/engine/phase_b_tree.py +137 -0
- diffneusim/engine/soft14.py +130 -0
- diffneusim/engine/soft_capi.py +373 -0
- diffneusim/engine/soft_engine.py +165 -0
- diffneusim/engine/step14.py +132 -0
- diffneusim/engine/tape_format.py +89 -0
- diffneusim/engine/x14cpu.py +163 -0
- diffneusim/env/__init__.py +0 -0
- diffneusim/env/absent.py +20 -0
- diffneusim/env/cpu14.py +105 -0
- diffneusim/env/e0loop14.py +224 -0
- diffneusim/env/env14.py +568 -0
- diffneusim/env/kin_contact14.py +193 -0
- diffneusim/env/mimic_sites_x14.json +366 -0
- diffneusim/env/old_count.py +78 -0
- diffneusim/env/rew14.py +114 -0
- diffneusim/env/rew14_hook.py +105 -0
- diffneusim/g1/__init__.py +1 -0
- diffneusim/g1/arm_a2.py +165 -0
- diffneusim/g1/arm_a3.py +576 -0
- diffneusim/g1/read_a3.py +79 -0
- diffneusim/g1/rg1_read.py +89 -0
- diffneusim/model/__init__.py +66 -0
- diffneusim/model/case.py +17 -0
- diffneusim/model/dnmodel.py +79 -0
- diffneusim/model/fuse_fixed.py +281 -0
- diffneusim/model/monitor.py +834 -0
- diffneusim/models/BODIES.toml +48 -0
- diffneusim/models/MANIFEST.toml +979 -0
- diffneusim/models/cases/G290/case.bin +0 -0
- diffneusim/models/cases/G290/case.json +1 -0
- diffneusim/models/cases/G356-SRC/case.bin +0 -0
- diffneusim/models/cases/G356-SRC/case.json +1 -0
- diffneusim/models/cases/G416/case.bin +0 -0
- diffneusim/models/cases/G416/case.json +1 -0
- diffneusim/models/cases/M290C-SRC/case.bin +0 -0
- diffneusim/models/cases/M290C-SRC/case.json +1 -0
- diffneusim/models/cases/M290R-SRC/case.bin +0 -0
- diffneusim/models/cases/M290R-SRC/case.json +1 -0
- diffneusim/models/cases/M356C-SRC/case.bin +0 -0
- diffneusim/models/cases/M356C-SRC/case.json +1 -0
- diffneusim/models/cases/M356R-SRC/case.bin +0 -0
- diffneusim/models/cases/M356R-SRC/case.json +1 -0
- diffneusim/models/cases/M416C-SRC/case.bin +0 -0
- diffneusim/models/cases/M416C-SRC/case.json +1 -0
- diffneusim/models/derived/d16_expanded_62f77a4bb16b1e67_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_expanded_a1e8b196b2cd7b3c_mmfloor.xml +673 -0
- diffneusim/models/derived/d16_soft_law_019e20820f8633b9_mmfloor.json +7844 -0
- diffneusim/models/derived/d16_soft_law_62f77a4bb16b1e67_mmfloor.json +16855 -0
- diffneusim/models/derived/d16_soft_law_77dbb7213f26e821_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rampsb3l_n6t12.json +7883 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsd05_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsdef_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_8989b60e44860c5b_mmfloor_rhlsmjd_n6t12.json +7868 -0
- diffneusim/models/derived/d16_soft_law_a1e8b196b2cd7b3c_mmfloor_rampsb3l_n6t12.json +16894 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor.json +12655 -0
- diffneusim/models/derived/d16_soft_law_a944653edd642082_mmfloor_rampsb3l_n6t12.json +12700 -0
- diffneusim/models/derived/unitree_g1_soft_law.json +15580 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +28913 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +29202 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_axfixlegs01.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_armless_ball_lspine_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +46970 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src.dnmodel +38570 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid.dnmodel +38923 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_millard_stickspin_wrapvia_mtp60k25_trunkfix_toepair_n1_src_rigid_qk.txt +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1.dnmodel +1 -0
- diffneusim/models/fullbody_contact_spinecoupled_fusedhand_ball_lspine_girdle_osimeq_stickspin_wrapvia_mtp60k25_trunkfix_calf2_pe_toepair_flsrc_n1_qk.txt +1 -0
- diffneusim/models/fullbody_meshes/1mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2distph.stl +0 -0
- diffneusim/models/fullbody_meshes/2mc.stl +0 -0
- diffneusim/models/fullbody_meshes/2midph.stl +0 -0
- diffneusim/models/fullbody_meshes/2proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/3distph.stl +0 -0
- diffneusim/models/fullbody_meshes/3mc.stl +0 -0
- diffneusim/models/fullbody_meshes/3midph.stl +0 -0
- diffneusim/models/fullbody_meshes/3proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/4distph.stl +0 -0
- diffneusim/models/fullbody_meshes/4mc.stl +0 -0
- diffneusim/models/fullbody_meshes/4midph.stl +0 -0
- diffneusim/models/fullbody_meshes/4proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/5distph.stl +0 -0
- diffneusim/models/fullbody_meshes/5mc.stl +0 -0
- diffneusim/models/fullbody_meshes/5midph.stl +0 -0
- diffneusim/models/fullbody_meshes/5proxph.stl +0 -0
- diffneusim/models/fullbody_meshes/NOTICE +2 -0
- diffneusim/models/fullbody_meshes/capitate.stl +0 -0
- diffneusim/models/fullbody_meshes/clavicle.stl +0 -0
- diffneusim/models/fullbody_meshes/hamate.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_cervical.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_jaw.stl +0 -0
- diffneusim/models/fullbody_meshes/hat_skull.stl +0 -0
- diffneusim/models/fullbody_meshes/humerus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/l_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/l_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/l_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/l_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/l_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/l_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar1.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar2.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar3.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar4.stl +0 -0
- diffneusim/models/fullbody_meshes/lumbar5.stl +0 -0
- diffneusim/models/fullbody_meshes/lunate.stl +0 -0
- diffneusim/models/fullbody_meshes/pisiform.stl +0 -0
- diffneusim/models/fullbody_meshes/r_bofoot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_femur.stl +0 -0
- diffneusim/models/fullbody_meshes/r_fibula.stl +0 -0
- diffneusim/models/fullbody_meshes/r_foot.stl +0 -0
- diffneusim/models/fullbody_meshes/r_patella.stl +0 -0
- diffneusim/models/fullbody_meshes/r_pelvis.stl +0 -0
- diffneusim/models/fullbody_meshes/r_talus.stl +0 -0
- diffneusim/models/fullbody_meshes/r_tibia.stl +0 -0
- diffneusim/models/fullbody_meshes/radius.stl +0 -0
- diffneusim/models/fullbody_meshes/sacrum.stl +0 -0
- diffneusim/models/fullbody_meshes/scaphoid.stl +0 -0
- diffneusim/models/fullbody_meshes/scapula.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic10_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic11_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic12_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic1_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic2_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic3_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic4_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic5_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic6_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic7_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic8_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thoracic9_s.stl +0 -0
- diffneusim/models/fullbody_meshes/thorax.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbdist.stl +0 -0
- diffneusim/models/fullbody_meshes/thumbprox.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezium.stl +0 -0
- diffneusim/models/fullbody_meshes/trapezoid.stl +0 -0
- diffneusim/models/fullbody_meshes/triquetrum.stl +0 -0
- diffneusim/models/fullbody_meshes/ulna.stl +0 -0
- diffneusim/models/source/myo_fullbody/UPSTREAM.md +91 -0
- diffneusim/models/source/myoleg/UPSTREAM.md +52 -0
- diffneusim/models/source/unitree_g1/LICENSE.mjlab +202 -0
- diffneusim/models/source/unitree_g1/UPSTREAM.md +38 -0
- diffneusim/models/source/unitree_g1/assets/head_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/left_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/logo_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/pelvis_contour_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_ankle_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_elbow_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_hip_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_knee_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_rubber_hand.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_shoulder_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_pitch_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_roll_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/right_wrist_yaw_link.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/torso_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_roll_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/assets/waist_yaw_link_rev_1_0.STL +0 -0
- diffneusim/models/source/unitree_g1/dump_mjlab_reference.py +30 -0
- diffneusim/models/source/unitree_g1/g1.xml +308 -0
- diffneusim/models/source/unitree_g1/g1_constants.py +298 -0
- diffneusim/models/source/unitree_g1/mjlab_compiled_reference.json +857 -0
- diffneusim/models/unitree_g1.dnmodel +4393 -0
- diffneusim/models/unitree_g1_selfcol.dnmodel +20824 -0
- diffneusim/rl/__init__.py +2 -0
- diffneusim/rl/dynsyn_layer.py +146 -0
- diffneusim/rl/footstep_plan.py +337 -0
- diffneusim/rl/g1_bm_env.py +572 -0
- diffneusim/rl/g1_bm_eval.py +168 -0
- diffneusim/rl/g1_bm_fused.py +275 -0
- diffneusim/rl/g1_bm_ppo.py +622 -0
- diffneusim/rl/g1_bm_sapo.py +551 -0
- diffneusim/rl/g1_ppo.py +395 -0
- diffneusim/rl/g1_sapo_soft.py +240 -0
- diffneusim/rl/g1_soft_env.py +452 -0
- diffneusim/rl/g1_soft_grad.py +145 -0
- diffneusim/rl/geyer_curves_torch.py +108 -0
- diffneusim/rl/gpu_fullbody_vec_env.py +1241 -0
- diffneusim/rl/imitation.py +2027 -0
- diffneusim/rl/imitation_reward_v2.py +248 -0
- diffneusim/rl/imitation_reward_v3.py +349 -0
- diffneusim/rl/latent_task.py +175 -0
- diffneusim/rl/llc_reward.py +316 -0
- diffneusim/rl/millard_curves_torch.py +154 -0
- diffneusim/rl/mirror_symmetry.py +212 -0
- diffneusim/rl/model_path.py +35 -0
- diffneusim/rl/mvae_recon.py +123 -0
- diffneusim/rl/nets_shac.py +599 -0
- diffneusim/rl/reset_pool.py +154 -0
- diffneusim/rl/sapo_capture.py +873 -0
- diffneusim/rl/sapo_vec.py +1051 -0
- diffneusim/rl/shac_vec.py +346 -0
- diffneusim/rl/state_prior.py +151 -0
- diffneusim/rl/step_library.py +105 -0
- diffneusim/rl/task_walk_env.py +1793 -0
- diffneusim/rl/task_walk_reward.py +3300 -0
- diffneusim/run.py +23 -0
- diffneusim/run_env.py +46 -0
- diffneusim/tasks/__init__.py +147 -0
- diffneusim/tasks/legacy_names.py +63 -0
- diffneusim/tasks/paths.py +79 -0
- diffneusim/tasks/settings.py +202 -0
- diffneusim/third_party/instantmimic_947430ee/LICENSE +202 -0
- diffneusim/third_party/instantmimic_947430ee/NOTICE +19 -0
- diffneusim/third_party/instantmimic_947430ee/README.md +31 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/benchmark_protocol.py +106 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/metrics.py +214 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/envs/unitree_g1/tasks/beyondmimic_tracking/reference.py +513 -0
- diffneusim/third_party/instantmimic_947430ee/instantmimic/motion/quaternion.py +193 -0
- diffneusim/train/__init__.py +0 -0
- diffneusim/train/eval_ckpt.py +239 -0
- diffneusim/train/eval_mimic.py +133 -0
- diffneusim/train/gait_report.py +203 -0
- diffneusim/train/gcot_chain.py +51 -0
- diffneusim/train/levers.py +135 -0
- diffneusim/train/masked_reset.py +314 -0
- diffneusim/train/rl_algorithm_suite.py +917 -0
- diffneusim/train/train14.py +240 -0
- diffneusim/train/train_tw14.py +674 -0
- diffneusim/viz/__init__.py +5 -0
- diffneusim/viz/__main__.py +41 -0
- diffneusim/viz/camera.py +115 -0
- diffneusim/viz/dnrec.py +118 -0
- diffneusim/viz/dnrec_io.py +686 -0
- diffneusim/viz/hud.py +565 -0
- diffneusim/viz/meshes.py +458 -0
- diffneusim/viz/play.py +237 -0
- diffneusim/viz/record.py +74 -0
- diffneusim/viz/render.py +1402 -0
- diffneusim/viz/renderer.py +268 -0
- diffneusim/viz/rl_env_render.py +635 -0
- diffneusim/viz/snapshot.py +54 -0
- diffneusim/viz/strobe.py +124 -0
- diffneusim/viz/to_mp4.py +58 -0
- diffneusim/viz/ui.py +481 -0
- diffneusim/viz/viewer.py +2086 -0
- diffneusim-1.0.0.dist-info/METADATA +226 -0
- diffneusim-1.0.0.dist-info/RECORD +682 -0
- diffneusim-1.0.0.dist-info/WHEEL +5 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSE +201 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-ARMS-hand-wrist-4.3.txt +20 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/BSD-3-Clause-NC-MoBL-ARMS.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/CC-BY-3.0-OpenSim-geometry.txt +25 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Christophy2012-lumbarspine.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lai2017-model-high-flex.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Lee2015-hand_muscle.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Rajagopal2016-full_body.txt +11 -0
- diffneusim-1.0.0.dist-info/licenses/LICENSES/MIT-Uhlrich2022-fbmodpassivecal.txt +10 -0
- diffneusim-1.0.0.dist-info/licenses/NOTICE +274 -0
- diffneusim-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
"""P3 of tools/d16_fused_env/CAPTURE_PLAN.md (2026-11-03): SAPO's actor window on env14 as per-slot steps.
|
|
2
|
+
|
|
3
|
+
Each control step k of the window is two functions with explicit tensor inputs and outputs, and the reset stays eager between
|
|
4
|
+
them (it is the step's one host read):
|
|
5
|
+
A_k the action noise in -> the actor, the entropy, env14's pre-step, env._step_a (the physics, the phase, _post_physics on
|
|
6
|
+
REW14's node) -> done, the reward, the obs before the reset, the new state
|
|
7
|
+
(eager) env._step_reset: done.nonzero(), _reset_envs (RSI on env.rng, the fibre equilibration), env14's reset hook
|
|
8
|
+
B_k the post-reset state in -> env._step_obs, env14's activation hand-off, obs_rms.update, the frozen normalizer, the
|
|
9
|
+
critic's two bootstraps, SAPO's per-step return arithmetic and buffers -> the next obs and the carried accumulators
|
|
10
|
+
|
|
11
|
+
mode "eager" (P3a) calls them directly, and is bitwise to SapoVec.compute_actor_loss on the configuration (the same operations;
|
|
12
|
+
the return accumulator rew_acc[i] becomes a carried (n,) tensor, identical in the forward). mode "graph" (P3b) runs them as
|
|
13
|
+
graphed callables over (A_0, B_0, ..., A_{H-1}, B_{H-1}) (_graph_chain: torch.cuda.make_graphed_callables with each slot's state
|
|
14
|
+
inputs as views of the static outputs that feed them; one shared pool; forwards captured in that order and backwards in reverse,
|
|
15
|
+
which is the order SAPO's backward runs them), warmed up on the real inputs of one eager window, with the state the recording
|
|
16
|
+
touches snapshotted and restored. The replay launches the same kernels, so it is meant to be bitwise to eager.
|
|
17
|
+
|
|
18
|
+
W = install(algo, env, e14, mode) # replaces algo.compute_actor_loss; W.undo() puts it back
|
|
19
|
+
State the graphs bake in by address (asserted at every window): algo's buffers (obs_buf, rew_buf, done_mask, next_values,
|
|
20
|
+
ent_raw_buf, the action-gradient monitors), obs_rms's mean / var / count, the frozen normalizer, env14's warm start and reset mask.
|
|
21
|
+
They are updated in place; reassigning one (a checkpoint load, a harness restore) after recording is refused.
|
|
22
|
+
|
|
23
|
+
TW1 S2a (11-10; tools/d16_taskwalk/TW1_S2_DESIGN.md): the taskwalk env behind an explicit argument,
|
|
24
|
+
W = install(algo, env, e14, mode, extra_state=TASKWALK_STATE) (TASKWALK_STATE: W290b's recipe's list, below)
|
|
25
|
+
extra_state lists the env's cross-step state outside P3's explicit tensors, as attribute paths from the env (tw1_state.py measures
|
|
26
|
+
it). Each slot's A and B take the entries present at that slot (an entry that is None, as _tw_lce_prev_graph at a window's start,
|
|
27
|
+
is absent; the per-slot presence is recorded with the grad flags and asserted on replay), A returns their post-step values, and the
|
|
28
|
+
loop puts them back on the env objects before the eager reset, which may edit or reassign them. The reward's window-varying weights
|
|
29
|
+
(enable_tensor_weights) are read from a per-slot block filled before the window from the schedule's own arithmetic at each slot's step
|
|
30
|
+
count, and copied into their 0-d tensors at the start of A_k; the speed P update runs after the window (defer_speed_p). the path,
|
|
31
|
+
extra_state=None, is unchanged.
|
|
32
|
+
"""
|
|
33
|
+
import os
|
|
34
|
+
import re
|
|
35
|
+
|
|
36
|
+
import torch
|
|
37
|
+
import torch.nn as nn
|
|
38
|
+
|
|
39
|
+
from .nets_shac import ActorSquashedMLP
|
|
40
|
+
|
|
41
|
+
# TW1 S2a: the taskwalk env's cross-step state outside P3's explicit tensors, W290b's recipe (tools/d16_taskwalk/tw1_state.py,
|
|
42
|
+
# results/tw1_census_20261110/state_W290b.txt): the grad-carrying ones first
|
|
43
|
+
TASKWALK_STATE = ("_tw_last_u", "_tw_lce_prev_graph", "taskwalk._com_graph", "taskwalk.last_effort_t", "taskwalk.last_v_com",
|
|
44
|
+
"_lce_prev", "_tw_fell", "_tw_lce_fresh", "mirror._prev_l", "mirror._prev_r", "mirror.flipped",
|
|
45
|
+
"taskwalk._prev['com']", "taskwalk._prev['head_q']", "taskwalk._prev['valid']", "taskwalk.last_fall",
|
|
46
|
+
"taskwalk.last_v_com_valid", "taskwalk._speed_p._s_v", "taskwalk._speed_p._s_c", "taskwalk._speed_p._s_n",
|
|
47
|
+
"taskwalk.v_tgt",
|
|
48
|
+
# the mid-lane term's lane origin and its latch flag (task_walk_reward._origin; 11-12, the A14 / run-clip capture gate):
|
|
49
|
+
# written in place each step and by the reset pool, read by the reward; carried explicitly like the reward's other _prev
|
|
50
|
+
"taskwalk._prev['lane0']", "taskwalk._prev['lane0_set']",
|
|
51
|
+
# TASKWALK_SPEED_MEAN_TAU's attached velocity average and its validity flag (task_walk_reward._velocity_ema; 11-12, review
|
|
52
|
+
# the human-like walk cell): rebound every step by the reward, the flag replaced by the reset, read by the next step;
|
|
53
|
+
# absent (and so not carried) while the switch is 0
|
|
54
|
+
"taskwalk._mean_graph", "taskwalk._prev['mean_valid']",
|
|
55
|
+
# live only inside the weight ramps (the head-acceleration stencil: tw1_state at step 8000 / 64000)
|
|
56
|
+
"taskwalk._acc_graph['_acc_head'][0]", "taskwalk._acc_graph['_acc_head'][1]",
|
|
57
|
+
"taskwalk._prev['_acc_head'][0]", "taskwalk._prev['_acc_head'][1]", "taskwalk._prev['_acc_head'][2]",
|
|
58
|
+
# TASKWALK_EXC_NOISE_SD > 0 (task_walk_env.set_exc_noise): the per-world draw count, so a replay draws fresh noise
|
|
59
|
+
"_exc_k",
|
|
60
|
+
# TASKWALK_METABOLIC_ONSET=1 (11-12): the activation-onset counter t_stim per muscle and world, rebound every step and
|
|
61
|
+
# by reset (tw1_state census on the N1 body, switch on vs off: the one new path); absent when the switch is off
|
|
62
|
+
"taskwalk._prev['onset_t']",
|
|
63
|
+
# TASKWALK_W_ACTION_RATE != 0 (11-12, the catch): the action-rate term's previous excitation (_rate("u", ...)), rebound
|
|
64
|
+
# every step and by reset (tw1_state census on the N1 body, w 0.097 vs off: the one new path); absent when the weight is 0
|
|
65
|
+
"taskwalk._prev['u']",
|
|
66
|
+
# TASKWALK_METABOLIC_FORCE_RATE != 0 (11-12): the force-rate cost's filter state, grad-carrying inside a window (cut at
|
|
67
|
+
# its start like _com_graph), rebound every step; absent when the switch is off
|
|
68
|
+
"taskwalk._fr_x1", "taskwalk._fr_x2", "taskwalk._fr_y1", "taskwalk._fr_y2",
|
|
69
|
+
# TASKWALK_MID_LANE_FORM=heading (11-14, the L3): the lane's low-passed COM velocity, grad-carrying inside a window (cut
|
|
70
|
+
# at its start like _fr_x1), and its per-env seed flag; absent when the form is offset
|
|
71
|
+
"taskwalk._lane_graph", "taskwalk._prev['lane_ema_valid']")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _Slot(nn.Module):
|
|
75
|
+
"""one slot's A or B as a module, so make_graphed_callables includes the parameters it differentiates (the actor for A, the
|
|
76
|
+
critic for B) in the graph's input surface"""
|
|
77
|
+
|
|
78
|
+
def __init__(self, W, k, part, net):
|
|
79
|
+
super().__init__()
|
|
80
|
+
object.__setattr__(self, "W", W) # not a submodule
|
|
81
|
+
self.k, self.part, self.net = k, part, net
|
|
82
|
+
|
|
83
|
+
def forward(self, *x):
|
|
84
|
+
if self.W.memtrace and self.k % 8 == 0: # (debug: C_P3_MEMTRACE=1, the memory at the slots' warm-ups and captures)
|
|
85
|
+
print(f"[memtrace] {self.part}{self.k} capturing {torch.cuda.is_current_stream_capturing()} allocated "
|
|
86
|
+
f"{torch.cuda.memory_allocated() / 2**30:.2f} GB reserved {torch.cuda.memory_reserved() / 2**30:.2f}", flush=True)
|
|
87
|
+
return (self.W.step_a if self.part == "a" else self.W.step_b)(self.k, *x)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _graph_chain(calls, args, links, num_warmup_iters=3, return_souts=False):
|
|
91
|
+
"""torch.cuda.make_graphed_callables (torch 2.11, torch/cuda/graphs.py, read for this) for a CHAIN of callables, with one
|
|
92
|
+
change: an argument that links[i][j] = (i', j') names is, in the captures, a view of callable i''s static output j' rather
|
|
93
|
+
than a buffer of its own. The live loop passes exactly that output (or the eager reset's in-place edit of it), so the
|
|
94
|
+
replay's copy-in is skipped by the same data_ptr test, and the recorded value is not kept twice (1.7 GB at 4,096 x 32).
|
|
95
|
+
Otherwise as torch: warm-ups on a side stream on the recorded inputs, one pool, the forwards captured in order and the
|
|
96
|
+
backwards in reverse (the order they replay in), the same autograd Function. args is a list, emptied of the linked inputs
|
|
97
|
+
after the warm-ups (they are freed before the captures, where the peak is)."""
|
|
98
|
+
n = len(calls)
|
|
99
|
+
params = [tuple(c.parameters()) for c in calls]
|
|
100
|
+
for c in calls:
|
|
101
|
+
assert not (c._backward_hooks or c._forward_hooks or c._forward_pre_hooks)
|
|
102
|
+
assert all(not b.requires_grad for b in c.buffers())
|
|
103
|
+
torch.cuda.synchronize()
|
|
104
|
+
with torch.cuda.stream(torch.cuda.Stream()):
|
|
105
|
+
for c, x, p in zip(calls, args, params):
|
|
106
|
+
for _ in range(num_warmup_iters):
|
|
107
|
+
outs = c(*x)
|
|
108
|
+
og = tuple(o for o in outs if o.requires_grad)
|
|
109
|
+
if og:
|
|
110
|
+
gi = torch.autograd.grad(og, tuple(t for t in x + p if t.requires_grad),
|
|
111
|
+
grad_outputs=tuple(torch.empty_like(o) for o in og), only_inputs=True, allow_unused=True)
|
|
112
|
+
del gi
|
|
113
|
+
del outs, og
|
|
114
|
+
torch.cuda.synchronize()
|
|
115
|
+
meta = [[(t.shape, t.dtype, t.stride(), t.requires_grad) for t in x] for x in args]
|
|
116
|
+
for i in range(n): # the linked recorded inputs go now
|
|
117
|
+
args[i] = tuple(None if links[i][j] is not None else t for j, t in enumerate(args[i]))
|
|
118
|
+
import gc
|
|
119
|
+
gc.collect()
|
|
120
|
+
torch.cuda.empty_cache()
|
|
121
|
+
pool = torch.cuda.graph_pool_handle()
|
|
122
|
+
fwd = [torch.cuda.CUDAGraph() for _ in range(n)]
|
|
123
|
+
bwd = [torch.cuda.CUDAGraph() for _ in range(n)]
|
|
124
|
+
surf, souts = [], []
|
|
125
|
+
for i, c in enumerate(calls):
|
|
126
|
+
xs = []
|
|
127
|
+
for j, t in enumerate(args[i]):
|
|
128
|
+
if links[i][j] is None:
|
|
129
|
+
xs.append(t)
|
|
130
|
+
continue
|
|
131
|
+
src = souts[links[i][j][0]][links[i][j][1]]
|
|
132
|
+
shape, dtype, stride, rg = meta[i][j]
|
|
133
|
+
assert (src.shape, src.dtype, src.stride()) == (shape, dtype, stride), (i, j, src.shape, shape, src.stride(), stride)
|
|
134
|
+
xs.append(src.detach().requires_grad_(rg))
|
|
135
|
+
xs = tuple(xs)
|
|
136
|
+
with torch.cuda.graph(fwd[i], pool=pool):
|
|
137
|
+
o = c(*xs)
|
|
138
|
+
assert isinstance(o, tuple) and all(torch.is_tensor(t) for t in o), type(o)
|
|
139
|
+
surf.append(xs + params[i])
|
|
140
|
+
souts.append(o)
|
|
141
|
+
sgo, sgi = [None] * n, [None] * n
|
|
142
|
+
for i in reversed(range(n)):
|
|
143
|
+
go = tuple(torch.empty_like(o) if o.requires_grad else None for o in souts[i])
|
|
144
|
+
og = tuple(o for o in souts[i] if o.requires_grad)
|
|
145
|
+
gi = None
|
|
146
|
+
if og:
|
|
147
|
+
with torch.cuda.graph(bwd[i], pool=pool):
|
|
148
|
+
gi = torch.autograd.grad(og, tuple(t for t in surf[i] if t.requires_grad),
|
|
149
|
+
grad_outputs=tuple(g for g in go if g is not None), only_inputs=True, allow_unused=True)
|
|
150
|
+
it = iter(gi or ())
|
|
151
|
+
sgi[i] = tuple(next(it) if (t.requires_grad and gi is not None) else None for t in surf[i])
|
|
152
|
+
sgo[i] = go
|
|
153
|
+
|
|
154
|
+
def graphed(i):
|
|
155
|
+
fg, bg, s, so, go, gi, nu, p = fwd[i], bwd[i], surf[i], souts[i], sgo[i], sgi[i], len(args[i]), params[i]
|
|
156
|
+
|
|
157
|
+
class Graphed(torch.autograd.Function):
|
|
158
|
+
@staticmethod
|
|
159
|
+
def forward(ctx, *inputs):
|
|
160
|
+
for k in range(nu):
|
|
161
|
+
if s[k].data_ptr() != inputs[k].data_ptr():
|
|
162
|
+
s[k].copy_(inputs[k])
|
|
163
|
+
fg.replay()
|
|
164
|
+
return tuple(o.detach() for o in so)
|
|
165
|
+
|
|
166
|
+
@staticmethod
|
|
167
|
+
@torch.autograd.function.once_differentiable
|
|
168
|
+
def backward(ctx, *grads):
|
|
169
|
+
assert len(grads) == len(go)
|
|
170
|
+
for g, grad in zip(go, grads):
|
|
171
|
+
if g is not None and g.data_ptr() != grad.data_ptr():
|
|
172
|
+
g.copy_(grad)
|
|
173
|
+
bg.replay()
|
|
174
|
+
return tuple(b.detach() if b is not None else None for b in gi)
|
|
175
|
+
|
|
176
|
+
def call(*x):
|
|
177
|
+
return Graphed.apply(*(tuple(x) + p))
|
|
178
|
+
return call
|
|
179
|
+
out = [graphed(i) for i in range(n)]
|
|
180
|
+
return (out, souts) if return_souts else out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _chain_links(S, parts, nex=None):
|
|
184
|
+
"""the links of SAPO's chain (see _graph_chain): A_k's state from A_{k-1} (q, qd, lce, phase, progress, all after the eager
|
|
185
|
+
reset) and B_{k-1} (obs, a); B_k's from A_k and B_{k-1} (the carried return, discount, loss). The action noise, z, the
|
|
186
|
+
clip ids and alpha keep buffers of their own (the live loop hands them in fresh). Only when both halves are graphed."""
|
|
187
|
+
A_OUT = ("ent", "ent_norm", "rew", "done", "timeout", "obr", "ep_end", "q", "qd", "lce", "a", "phase", "progress", "a1")
|
|
188
|
+
B_OUT = ("obs", "a", "racc", "gamma", "actor_loss")
|
|
189
|
+
links = []
|
|
190
|
+
for k in range(S):
|
|
191
|
+
la, lb = [None] * len(SapoWindow.A_IN), [None] * len(SapoWindow.B_IN)
|
|
192
|
+
if nex is not None: # (TW1) the extra_state entries: no links, buffers of their own
|
|
193
|
+
la, lb = la + [None] * nex[0][k], lb + [None] * nex[1][k]
|
|
194
|
+
# (TW1, GPU gates 4 / 5, 11-10) no links at all on the taskwalk path: its eager reset REBINDS the state it resets (the edits it
|
|
195
|
+
# in place), so the live input's data_ptr differs, the replay's copy-in writes the post-reset values into the previous slot's
|
|
196
|
+
# static output, and that slot's backward then reads them (every graph arm forward-exact, its backward 8e-6 off at 8000, 2.4e-4
|
|
197
|
+
# at 48-step episodes; with every input in a buffer of its own the graph arm at 8000 is bitwise to eager over 4 replays)
|
|
198
|
+
if parts == "ab" and nex is None:
|
|
199
|
+
ia, ib = 2 * k, 2 * k + 1 # this slot's callables; the previous slot's are ia - 2, ia - 1
|
|
200
|
+
for j, nm in enumerate(SapoWindow.A_IN):
|
|
201
|
+
if k > 0 and nm in ("q", "qd", "lce", "phase", "progress"):
|
|
202
|
+
la[j] = (ia - 2, A_OUT.index(nm))
|
|
203
|
+
elif k > 0 and nm in ("obs", "a"):
|
|
204
|
+
la[j] = (ia - 1, B_OUT.index(nm))
|
|
205
|
+
for j, nm in enumerate(SapoWindow.B_IN):
|
|
206
|
+
if nm in ("q", "qd", "lce", "a", "phase", "a1", "rew", "ent", "ent_norm", "done", "obr", "ep_end"):
|
|
207
|
+
lb[j] = (ia, A_OUT.index(nm))
|
|
208
|
+
elif k > 0 and nm in ("racc", "gamma", "actor_loss"):
|
|
209
|
+
lb[j] = (ib - 2, B_OUT.index(nm))
|
|
210
|
+
links += [la, lb] if parts == "ab" else ([la] if parts == "a" else [lb])
|
|
211
|
+
return links
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _graded(graphed, mask):
|
|
215
|
+
"""a graphed callable whose outputs carry a gradient edge only where the eager step's did. make_graphed_callables marks no
|
|
216
|
+
output non-differentiable, so every float output of a replay requires grad (its inputs include the parameters): the phase
|
|
217
|
+
(A) and the discount (B) would carry the replay's GraphedBackward, and the phase, which the window's start does not detach
|
|
218
|
+
(clear_grad), would link the next window's first step into this window's graph. Its backward then reran this window's
|
|
219
|
+
backward graphs out of order (zero cotangents, on memory the next window's replay owns) and reached its freed eager reset
|
|
220
|
+
nodes ('backward through the graph a second time', a growing BPTT, corrupted saved tensors)."""
|
|
221
|
+
def call(*x):
|
|
222
|
+
return tuple(o if m else o.detach() for o, m in zip(graphed(*x), mask))
|
|
223
|
+
return call
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class SapoWindow:
|
|
227
|
+
A_IN = ("obs", "eps_a", "eps_e", "q", "qd", "lce", "a", "z", "phase", "progress", "clip_id")
|
|
228
|
+
B_IN = ("q", "qd", "lce", "a", "z", "phase", "clip_id", "a1", "rew", "ent", "ent_norm", "done", "obr", "ep_end", "racc",
|
|
229
|
+
"gamma", "actor_loss", "alpha")
|
|
230
|
+
|
|
231
|
+
def __init__(self, algo, env, e14, mode, extra_state=None, pool=False):
|
|
232
|
+
assert mode in ("eager", "graph"), mode
|
|
233
|
+
assert e14 is not None and e14.glue, "P3 runs on env14 with the compiled glue"
|
|
234
|
+
self.extra = list(extra_state) if extra_state is not None else None
|
|
235
|
+
if self.extra is None:
|
|
236
|
+
assert "_post_physics" in vars(env) and getattr(e14, "rew14", None) is not None, \
|
|
237
|
+
"P3 is built for REW14's _post_physics (E0's default with the glue, or rew14_hook.install)"
|
|
238
|
+
else:
|
|
239
|
+
tw = env.taskwalk
|
|
240
|
+
assert tw is not None, "extra_state is the taskwalk env's (TW1 S2a)"
|
|
241
|
+
assert tw._speed_p is None or tw._speed_p_defer, "the speed P update must leave the window (defer_speed_p)"
|
|
242
|
+
sched = {n for n, *_ in env._tw_w_sched} | {n for n, *_ in getattr(env, "_tw_w_sched2", [])}
|
|
243
|
+
assert sched <= set(tw._wt or {}), f"scheduled weights without a tensor route: {sorted(sched - set(tw._wt or {}))}"
|
|
244
|
+
assert tw._speed_p is None or "w_speed_max" in (tw._wt or {}), "w_speed_max changes between windows: enable its tensor"
|
|
245
|
+
assert not env.REF_SWITCH and not env.M4C and not env.act_warmstart
|
|
246
|
+
# (the finding, the review 11-11) the env's Python-side schedules move only inside env.step's Python, and a replay runs none:
|
|
247
|
+
# the ones read OUTSIDE the graphs (the reset's commanded-speed draw TW_V_LO / TW_V_HI, the RSI clip mix) are advanced
|
|
248
|
+
# per slot from the slot's step count (_py_sched); fall_h is read INSIDE them (the reward's fall test, a baked float),
|
|
249
|
+
# so its schedule has no replay: the eager loop
|
|
250
|
+
assert getattr(env, "_tw_fall_h_end", None) is None, \
|
|
251
|
+
"TASKWALK_FALL_H_END: the fall height is baked into the captured graphs, so its schedule needs the eager loop"
|
|
252
|
+
assert isinstance(algo.actor, ActorSquashedMLP), type(algo.actor)
|
|
253
|
+
assert algo.latent is None and not algo.ltask and algo._slope is None and algo._ks_teacher is None
|
|
254
|
+
assert not algo.per_env_cut
|
|
255
|
+
assert not algo.adaptive_horizon, "P3's slots are fixed at steps_num (AHAC re-pins it every epoch)"
|
|
256
|
+
if self.extra is None:
|
|
257
|
+
assert env.mirror is None and env.taskwalk is None and not env.REF_SWITCH and not env.M4C and not env.act_warmstart
|
|
258
|
+
assert algo.target_critic is algo.critic
|
|
259
|
+
self.algo, self.env, self.e14, self.mode = algo, env, e14, mode
|
|
260
|
+
self.task = env.imitation_task
|
|
261
|
+
self.S, self.N = algo.steps_num, algo.num_envs
|
|
262
|
+
r = algo.obs_rms # the frozen normalizer of a window, persistent (copied in place)
|
|
263
|
+
self.rms = type(r)(r.mean.shape, device=r.mean.device)
|
|
264
|
+
self.rms.fixed = r.fixed
|
|
265
|
+
self.A = [_Slot(self, k, "a", algo.actor) for k in range(self.S)]
|
|
266
|
+
self.B = [_Slot(self, k, "b", algo.critic) for k in range(self.S)]
|
|
267
|
+
self.graphs = None # (A_k graphed, B_k graphed) per slot once recorded
|
|
268
|
+
self.record_next = mode == "graph" # the first window runs eagerly and keeps its inputs
|
|
269
|
+
self.samples = None
|
|
270
|
+
self.windows = dict(eager=0, graph=0)
|
|
271
|
+
self.obr_log = None # a list to append each step's obs_before_reset to (the gates), or None
|
|
272
|
+
self.memtrace = False # set during record() under C_P3_MEMTRACE=1
|
|
273
|
+
if self.extra is not None: # a recipe without a component (W290d: no speed P) has no state for it
|
|
274
|
+
drop = [p_ for p_ in self.extra if not self._ex_component(p_)]
|
|
275
|
+
self.extra = [p_ for p_ in self.extra if p_ not in drop]
|
|
276
|
+
print(f"[sapo_capture] TW1 extra_state: {len(self.extra)} paths" + (f" (absent in this recipe: {drop})" if drop else ""), flush=True)
|
|
277
|
+
self.present = None # (TW1) per slot, the extra_state entries passed (A's; B's are the same)
|
|
278
|
+
self._recording, self._key_rec, self._t0_rec, self._scal_ref = False, None, None, None
|
|
279
|
+
self.pool = None # (TW1 S2b) the reset pool: built per window, applied inside A_k (reset_pool.py)
|
|
280
|
+
if pool:
|
|
281
|
+
assert self.extra is not None, "the reset pool is the taskwalk path's (extra_state)"
|
|
282
|
+
if "z" not in self.extra: # the stiction state, rebound by the reset: A_k's output must carry it (pool mode only)
|
|
283
|
+
self.extra = list(self.extra) + ["z"]
|
|
284
|
+
from diffneusim.rl.reset_pool import ResetPool
|
|
285
|
+
self.pool = ResetPool(env, e14)
|
|
286
|
+
# PREREG_S290 Amendment 16: with TASKWALK_DECISION_EVERY > 1 the env's held action crosses slots, an explicit input / output like
|
|
287
|
+
# the reward's state; off, the list is unchanged
|
|
288
|
+
self.decision_every = getattr(env, "decision_every", 1)
|
|
289
|
+
if self.decision_every > 1:
|
|
290
|
+
assert self.extra is not None, "the decision-rate hold runs on the taskwalk path (extra_state)"
|
|
291
|
+
if "_dr_held" not in self.extra:
|
|
292
|
+
self.extra = list(self.extra) + ["_dr_held"]
|
|
293
|
+
if e14.win is not None: # the adjoint's flags, checked with gn's finiteness in SapoVec.train (one sync)
|
|
294
|
+
algo._window_flags = e14.win.flags
|
|
295
|
+
self.wblock = None # (TW1) {weight: (S,) device tensor}, filled before each window
|
|
296
|
+
|
|
297
|
+
# ------------------------------------------------------------------ TW1 S2a: the extra state by path
|
|
298
|
+
@staticmethod
|
|
299
|
+
def _ex_tokens(path):
|
|
300
|
+
"""'taskwalk._prev[\'_acc_head\'][0]' -> [('attr', 'taskwalk'), ('attr', '_prev'), ('key', '_acc_head'), ('idx', 0)]"""
|
|
301
|
+
toks = []
|
|
302
|
+
for name, key, idx in re.findall(r"\.?([A-Za-z_][A-Za-z0-9_]*)|\['([^']*)'\]|\[(\d+)\]", path):
|
|
303
|
+
toks.append(("attr", name) if name else ("key", key) if key else ("idx", int(idx)))
|
|
304
|
+
return toks
|
|
305
|
+
|
|
306
|
+
def _ex_get(self, path):
|
|
307
|
+
"""the entry's tensor, or None when it, or a container on its path, does not exist (yet)"""
|
|
308
|
+
cur = self.env
|
|
309
|
+
for kind, t in self._ex_tokens(path):
|
|
310
|
+
if cur is None:
|
|
311
|
+
return None
|
|
312
|
+
if kind == "attr":
|
|
313
|
+
cur = getattr(cur, t, None)
|
|
314
|
+
elif kind == "key":
|
|
315
|
+
cur = cur.get(t) if isinstance(cur, dict) else None
|
|
316
|
+
else:
|
|
317
|
+
cur = cur[t] if isinstance(cur, list) and len(cur) > t else None
|
|
318
|
+
return cur
|
|
319
|
+
|
|
320
|
+
def _ex_set(self, path, value):
|
|
321
|
+
"""write the entry; None makes it absent again (an attribute None, a dict entry removed, a list element None). A missing dict
|
|
322
|
+
entry or list on the path is created for a tensor value (the state the window's own code would have made). A list held in a
|
|
323
|
+
dict is removed from the dict once its last element is made absent: the reward's histories (`_prev['_acc_head']`,
|
|
324
|
+
`_acc_graph['_acc_head']`) are whole lists or no entry, and `_accel` reads an entry that exists as a full one (GPU gate 3,
|
|
325
|
+
graph_6336: a re-record whose first slot had no head history left [None, None] in the dict and `_accel` read None.shape)."""
|
|
326
|
+
toks = self._ex_tokens(path)
|
|
327
|
+
cur, parent, pkey = self.env, None, None
|
|
328
|
+
for i, (kind, t) in enumerate(toks[:-1]):
|
|
329
|
+
nk = toks[i + 1][0]
|
|
330
|
+
if kind == "attr":
|
|
331
|
+
parent, pkey = None, None
|
|
332
|
+
cur = getattr(cur, t)
|
|
333
|
+
else:
|
|
334
|
+
nxt = cur.get(t) if kind == "key" else (cur[t] if len(cur) > t else None)
|
|
335
|
+
if nxt is None:
|
|
336
|
+
if value is None:
|
|
337
|
+
return # absent already
|
|
338
|
+
nxt = {} if nk == "key" else []
|
|
339
|
+
if kind == "key":
|
|
340
|
+
cur[t] = nxt
|
|
341
|
+
else:
|
|
342
|
+
cur.extend([None] * (t + 1 - len(cur)))
|
|
343
|
+
cur[t] = nxt
|
|
344
|
+
parent, pkey = (cur, t) if kind == "key" else (None, None)
|
|
345
|
+
cur = nxt
|
|
346
|
+
kind, t = toks[-1]
|
|
347
|
+
if kind == "attr":
|
|
348
|
+
setattr(cur, t, value)
|
|
349
|
+
elif kind == "key":
|
|
350
|
+
if value is None:
|
|
351
|
+
cur.pop(t, None)
|
|
352
|
+
else:
|
|
353
|
+
cur[t] = value
|
|
354
|
+
else:
|
|
355
|
+
if len(cur) <= t:
|
|
356
|
+
if value is None:
|
|
357
|
+
return
|
|
358
|
+
cur.extend([None] * (t + 1 - len(cur)))
|
|
359
|
+
cur[t] = value
|
|
360
|
+
if value is None and parent is not None and all(x is None for x in cur):
|
|
361
|
+
parent.pop(pkey) # the whole list absent: no entry, as before the reward first wrote it
|
|
362
|
+
|
|
363
|
+
def _ex_component(self, path):
|
|
364
|
+
"""False when an object on the path's attribute prefix is None (a component the recipe lacks: W290d has no speed P)"""
|
|
365
|
+
cur = self.env
|
|
366
|
+
for kind, t in self._ex_tokens(path)[:-1]: # the objects on the way; the entry itself may simply not exist yet
|
|
367
|
+
if kind != "attr":
|
|
368
|
+
return True
|
|
369
|
+
cur = getattr(cur, t, None)
|
|
370
|
+
if cur is None:
|
|
371
|
+
return False
|
|
372
|
+
return True
|
|
373
|
+
|
|
374
|
+
def _ex_present(self):
|
|
375
|
+
return tuple(p for p in self.extra if torch.is_tensor(self._ex_get(p)))
|
|
376
|
+
|
|
377
|
+
def _sched_value(self, name, t):
|
|
378
|
+
"""a routed weight's value at step count t: the schedule's own arithmetic (_tw_advance_w_sched), else its current float"""
|
|
379
|
+
env, tw = self.env, self.env.taskwalk
|
|
380
|
+
v = float(getattr(tw, name))
|
|
381
|
+
for n, w0, w1, steps, after in env._tw_w_sched:
|
|
382
|
+
if n == name:
|
|
383
|
+
v = w0 + (w1 - w0) * min(1.0, max(0.0, t - after) / float(steps))
|
|
384
|
+
for n, w1, w2, steps, after in getattr(env, "_tw_w_sched2", []):
|
|
385
|
+
if n == name and t >= after:
|
|
386
|
+
v = w1 + (w2 - w1) * min(1.0, (t - after) / float(steps))
|
|
387
|
+
return v
|
|
388
|
+
|
|
389
|
+
def _live_key(self, t0):
|
|
390
|
+
"""the reward's control flow over a window from step count t0: each scheduled weight on or off (it tests `w != 0.0`) at the
|
|
391
|
+
window's first and last slot"""
|
|
392
|
+
tw = self.env.taskwalk
|
|
393
|
+
key = tuple((n, self._sched_value(n, t0 + 1) != 0.0, self._sched_value(n, t0 + self.S) != 0.0)
|
|
394
|
+
for n in sorted(tw._wt) if n != "w_speed_max")
|
|
395
|
+
if self.pool is not None: # (S2b) the reset's set is control flow too (apply's where list)
|
|
396
|
+
key = key + (("reset_pool", hash(self.pool.sig)),)
|
|
397
|
+
return key
|
|
398
|
+
|
|
399
|
+
SCALAR_ALLOW = ("env._train_steps", "speed_p.n_updates", "speed_p._calls", "taskwalk._wt_frozen", # (the loop's own flag)
|
|
400
|
+
"env.TW_V_LO", "env.TW_V_HI", # read only by the reset's draw (_tw_command_speed), outside the graphs
|
|
401
|
+
"speed_p.lam_i") # M1's integral state (TASKWALK_SPEED_I_ETA): read and written only by update() at the
|
|
402
|
+
# window boundary (speed_p_window_end), outside the graphs; the graphs read the
|
|
403
|
+
# multiplier through the routed w_speed_max tensor. (B-AW's first hold-only form kept a
|
|
404
|
+
# host float speed_p._c_prev here, 1f43cc679; the hold now reads the schedule's own
|
|
405
|
+
# host integers, env._train_steps already listed, and keeps no state)
|
|
406
|
+
|
|
407
|
+
def _py_sched(self, t):
|
|
408
|
+
"""a replayed slot's Python-side env schedules at step count t, as the eager step leaves them: _step_a sets _train_steps
|
|
409
|
+
(gpu_fullbody_vec_env.py: += 1), then _tw_reward advances v_hi, v_lo (after the ceiling), ..., the RSI mix
|
|
410
|
+
(task_walk_env.py:1331-1337). Only those read outside the graphs; the weights go through the tensor route (wblock), the
|
|
411
|
+
command ramp and the heading are tensor state the graphs carry, fall_h is refused at install."""
|
|
412
|
+
env = self.env
|
|
413
|
+
env._train_steps = t
|
|
414
|
+
env._tw_advance_v_hi()
|
|
415
|
+
env._tw_advance_v_lo()
|
|
416
|
+
env._tw_advance_rsi_mix()
|
|
417
|
+
|
|
418
|
+
def _scalars(self):
|
|
419
|
+
"""the Python scalars a capture bakes: env's, the reward's, the mirror's, the speed P's (the routed weights excluded)"""
|
|
420
|
+
env, tw = self.env, self.env.taskwalk
|
|
421
|
+
out = {}
|
|
422
|
+
for name, o in (("env", env), ("taskwalk", tw), ("mirror", env.mirror), ("speed_p", tw._speed_p)):
|
|
423
|
+
if o is None:
|
|
424
|
+
continue
|
|
425
|
+
for k, v in vars(o).items():
|
|
426
|
+
if isinstance(v, (bool, int, float)) and not (name == "taskwalk" and k in tw._wt) and f"{name}.{k}" not in self.SCALAR_ALLOW:
|
|
427
|
+
out[f"{name}.{k}"] = v
|
|
428
|
+
return out
|
|
429
|
+
|
|
430
|
+
def _fill_wblock(self):
|
|
431
|
+
"""each window-varying weight at each slot: the schedule's own arithmetic at the slot's step count (_step_a advances
|
|
432
|
+
_train_steps before the reward reads the schedule, so slot k sees T0 + k + 1); w_speed_max holds over the window"""
|
|
433
|
+
env, tw = self.env, self.env.taskwalk
|
|
434
|
+
t0 = env._train_steps
|
|
435
|
+
vals = {n: [float(getattr(tw, n))] * self.S for n in tw._wt}
|
|
436
|
+
for k in range(self.S):
|
|
437
|
+
t = t0 + k + 1
|
|
438
|
+
for name, w0, w1, steps, after in env._tw_w_sched:
|
|
439
|
+
vals[name][k] = w0 + (w1 - w0) * min(1.0, max(0.0, t - after) / float(steps))
|
|
440
|
+
for name, w1, w2, steps, after in getattr(env, "_tw_w_sched2", []):
|
|
441
|
+
if t >= after:
|
|
442
|
+
vals[name][k] = w1 + (w2 - w1) * min(1.0, (t - after) / float(steps))
|
|
443
|
+
if self.wblock is None:
|
|
444
|
+
self.wblock = {n: torch.zeros(self.S, dtype=torch.float32, device=self.algo.device) for n in tw._wt}
|
|
445
|
+
for n, v in vals.items():
|
|
446
|
+
self.wblock[n].copy_(torch.tensor(v, dtype=torch.float32))
|
|
447
|
+
|
|
448
|
+
# ------------------------------------------------------------------ the two halves of a control step
|
|
449
|
+
def step_a(self, k, obs, eps_a, eps_e, q, qd, lce, a, z, phase, progress, clip_id, *ex):
|
|
450
|
+
algo, env, e14 = self.algo, self.env, self.e14
|
|
451
|
+
env.q, env.qd, env.lce, env.a, env.z, env.phase, env.progress = q, qd, lce, a, z, phase, progress
|
|
452
|
+
self.task.clip_id = clip_id
|
|
453
|
+
if self.extra is not None:
|
|
454
|
+
if self._recording: # the recorded window's step count at this slot: the schedule's floats (and so the
|
|
455
|
+
self.env._train_steps = self._t0_rec + k # reward's control flow) are the recorded slot's, not the warm-ups' drift
|
|
456
|
+
pres = self._pres_live[k]
|
|
457
|
+
assert len(pres) == len(ex), (k, len(pres), len(ex))
|
|
458
|
+
for path in self.extra: # an entry absent at this slot is absent again on every call (the record's warm-ups
|
|
459
|
+
if path not in pres: # run a slot 4 times: the first call's _tw_lce_prev_graph would reach the second's graph
|
|
460
|
+
self._ex_set(path, None) # and its backward a freed one; the GPU gate's graph arm, 11-10)
|
|
461
|
+
for path, v in zip(pres, ex):
|
|
462
|
+
self._ex_set(path, v)
|
|
463
|
+
for n in env.taskwalk._wt: # this slot's weights: its own element of the block (a view, never written in the window:
|
|
464
|
+
env.taskwalk._wt[n] = self.wblock[n][k] # the reward's w * r saves w for the backward, so an in-place copy into one shared
|
|
465
|
+
# 0-d tensor broke the previous slots' backward; the GPU gate's eagerx arm, 11-10)
|
|
466
|
+
algo.obs_buf[k] = obs.detach()
|
|
467
|
+
dist = algo.actor.distribution(obs)
|
|
468
|
+
actions = dist.rsample_eps(eps_a)
|
|
469
|
+
actions.register_hook(algo._action_grad_hook)
|
|
470
|
+
ent = dist.entropy_eps(eps_e)
|
|
471
|
+
ent = (ent if algo._ent_dims is None else ent[:, algo._ent_dims]).sum(-1)
|
|
472
|
+
if self.decision_every > 1: # Amendment 16: only a DECISION step carries the entropy bonus (held: ent = H_bar,
|
|
473
|
+
dec = (env.progress % self.decision_every) == 0 # so ent_norm = 0 in the return and the critic target); env.progress is
|
|
474
|
+
if env._dr_diag != "no_entmask": # (a gate diagnostic only: the entropy unmasked)
|
|
475
|
+
ent = torch.where(dec, ent, torch.full_like(ent, algo.target_entropy)) # this slot's clock before the step
|
|
476
|
+
algo.dec_buf[k] = dec.float() # the alpha dual step's mask (a persistent buffer, as obs_buf)
|
|
477
|
+
ent_norm = algo._ent_norm(ent)
|
|
478
|
+
assert e14.k == 0, e14.k # env14's step wrapper, its part before the step
|
|
479
|
+
e14.win.t = k # this control step's tape slot (a recording calls a slot more than once)
|
|
480
|
+
e14.reset_mask.zero_()
|
|
481
|
+
rew, done, extra, switching, _, timeout = env._step_a(algo._env_action(actions))
|
|
482
|
+
if self.pool is not None: # (S2b) the reset inside the slot: where(done, pool, state), the outputs post-reset
|
|
483
|
+
self.pool.apply(done)
|
|
484
|
+
assert not switching
|
|
485
|
+
out_ex = ()
|
|
486
|
+
if self.extra is not None: # the entries present after the step (a term's state appears when its weight turns on)
|
|
487
|
+
opres = self._ex_present()
|
|
488
|
+
self._opres_live[k] = opres
|
|
489
|
+
out_ex = tuple(self._ex_get(p) for p in opres)
|
|
490
|
+
return (ent, ent_norm, rew, done, timeout, extra["obs_before_reset"], extra["episode_end"],
|
|
491
|
+
env.q, env.qd, env.lce, env.a, env.phase, env.progress, e14.a1) + out_ex
|
|
492
|
+
|
|
493
|
+
def step_b(self, k, q, qd, lce, a, z, phase, clip_id, a1, rew, ent, ent_norm, done, obr, ep_end, racc, gamma, actor_loss,
|
|
494
|
+
alpha, *ex):
|
|
495
|
+
algo, env, e14, rms = self.algo, self.env, self.e14, self.rms
|
|
496
|
+
env.q, env.qd, env.lce, env.a, env.z, env.phase = q, qd, lce, a, z, phase
|
|
497
|
+
self.task.clip_id = clip_id
|
|
498
|
+
if self.extra is not None:
|
|
499
|
+
bpres = self._bpres_live[k]
|
|
500
|
+
assert len(bpres) == len(ex), (k, len(bpres), len(ex))
|
|
501
|
+
for path in self.extra:
|
|
502
|
+
if path not in bpres:
|
|
503
|
+
self._ex_set(path, None)
|
|
504
|
+
for path, v in zip(bpres, ex): # the entries present after the eager reset
|
|
505
|
+
self._ex_set(path, v)
|
|
506
|
+
obs_raw = env._step_obs()
|
|
507
|
+
# env14's step wrapper, its part after the step: the next step's a is the engine's a1 except on the reset columns
|
|
508
|
+
env.a = (torch.where(e14.reset_mask[None, :].clone(), env.a.detach(), a1).contiguous() if e14.reset_fix else a1)
|
|
509
|
+
algo.obs_rms.update(obs_raw)
|
|
510
|
+
obs = rms.normalize(obs_raw)
|
|
511
|
+
if algo.one_bootstrap != "1": # (4d' as SapoVec's window: one call on obs_before_reset)
|
|
512
|
+
base_min, base_avg = algo.target_critic(obs, return_type="min_and_avg")
|
|
513
|
+
base_min, base_avg = base_min.squeeze(-1), base_avg.squeeze(-1)
|
|
514
|
+
obr_valid = torch.isfinite(obr).all(dim=1) & (obr.abs() <= 1e6).all(dim=1)
|
|
515
|
+
obr_safe = torch.where(obr_valid[:, None], obr, torch.zeros_like(obr))
|
|
516
|
+
obr_c = rms.normalize(obr_safe)
|
|
517
|
+
to_min, to_avg = algo.target_critic(obr_c, return_type="min_and_avg")
|
|
518
|
+
to_min, to_avg = to_min.squeeze(-1), to_avg.squeeze(-1)
|
|
519
|
+
if algo.one_bootstrap == "1":
|
|
520
|
+
torch._assert_async((obr_valid | done).all()) # 4d''s premise: a valid obs_before_reset on every non-done row
|
|
521
|
+
base_min, base_avg = to_min, to_avg
|
|
522
|
+
elif algo.one_bootstrap == "planted": # the gate's control: V(obs) for the done envs (must fail)
|
|
523
|
+
to_min, to_avg, base_min, base_avg = base_min, base_avg, to_min, to_avg
|
|
524
|
+
boot = done & ep_end & obr_valid
|
|
525
|
+
nv = torch.where(done, torch.where(boot, to_avg, torch.zeros_like(base_avg)), base_avg)
|
|
526
|
+
nv_min = torch.where(done, torch.where(boot, to_min, torch.zeros_like(base_min)), base_min)
|
|
527
|
+
done_eff = done
|
|
528
|
+
rew_aug = rew + alpha * ent_norm
|
|
529
|
+
racc_new = racc + gamma * rew_aug
|
|
530
|
+
if k < self.S - 1:
|
|
531
|
+
actor_loss = actor_loss + ((-racc_new - algo.gamma * gamma * nv) * done_eff.float()).sum()
|
|
532
|
+
else:
|
|
533
|
+
actor_loss = actor_loss + (-racc_new - algo.gamma * gamma * nv).sum()
|
|
534
|
+
gamma_new = torch.where(done_eff, torch.ones_like(gamma), gamma * algo.gamma)
|
|
535
|
+
racc_out = torch.where(done_eff, torch.zeros_like(racc_new), racc_new)
|
|
536
|
+
with torch.no_grad():
|
|
537
|
+
algo.rew_buf[k] = rew
|
|
538
|
+
algo.done_mask[k] = done.float() if k < self.S - 1 else torch.ones(self.N, device=algo.device)
|
|
539
|
+
algo.next_values[k] = nv_min
|
|
540
|
+
algo.ent_raw_buf[k] = ent.detach()
|
|
541
|
+
return obs, env.a, racc_out, gamma_new, actor_loss
|
|
542
|
+
|
|
543
|
+
# ------------------------------------------------------------------ the window
|
|
544
|
+
def window_start(self):
|
|
545
|
+
"""called once per window, right after initialize_trajectory (the masked reset draws its start table here)"""
|
|
546
|
+
|
|
547
|
+
def reset_step(self, k, graph, q, qd, lce, a, done, timeout):
|
|
548
|
+
"""the reset after slot k's A part (the masked reset replaces it with its own)"""
|
|
549
|
+
self.env._step_reset(done, {}, False, None, timeout)
|
|
550
|
+
|
|
551
|
+
def _chain(self, calls, args, links):
|
|
552
|
+
return _graph_chain(calls, args, links)
|
|
553
|
+
|
|
554
|
+
def baked(self):
|
|
555
|
+
a, e14 = self.algo, self.e14
|
|
556
|
+
d = dict(obs_buf=a.obs_buf, rew_buf=a.rew_buf, done_mask=a.done_mask, next_values=a.next_values, ent_raw_buf=a.ent_raw_buf,
|
|
557
|
+
rag_max=a._rag_max_gpu, rag_nf=a._rag_nonfinite_gpu, rms_mean=a.obs_rms.mean, rms_var=a.obs_rms.var,
|
|
558
|
+
rms_count=a.obs_rms._count, warm=e14.warm, reset_mask=e14.reset_mask)
|
|
559
|
+
if self.decision_every > 1: # Amendment 16: the decision mask the graphs write
|
|
560
|
+
d["dec_buf"] = a.dec_buf
|
|
561
|
+
return d
|
|
562
|
+
|
|
563
|
+
def actor_loss(self):
|
|
564
|
+
algo = self.algo
|
|
565
|
+
if not algo.freeze_critic_bptt:
|
|
566
|
+
return self._actor_loss()
|
|
567
|
+
ps = [p for p in algo.critic.parameters() if p.requires_grad]
|
|
568
|
+
for p in ps: # 4e as SapoVec's window (the capture too: B's graphs skip the weight gradients)
|
|
569
|
+
p.requires_grad_(False)
|
|
570
|
+
loss = self._actor_loss()
|
|
571
|
+
for p in ps:
|
|
572
|
+
p.requires_grad_(True)
|
|
573
|
+
return loss
|
|
574
|
+
|
|
575
|
+
def _actor_loss(self):
|
|
576
|
+
algo, env, e14, task = self.algo, self.env, self.e14, self.task
|
|
577
|
+
S, N, dev = self.S, self.N, algo.device
|
|
578
|
+
if self.mode == "graph" and self.graphs is None and self.samples is not None:
|
|
579
|
+
self.record() # the training loop's path: capture at the start of the window after the recorded one
|
|
580
|
+
graph = self.graphs is not None
|
|
581
|
+
# env14's switch guards once per window (Env14.assert_guards): its per-step wrapper is around env.step, which this loop never calls
|
|
582
|
+
guards = getattr(e14, "assert_guards", None)
|
|
583
|
+
reads0 = e14.foot.n_calls if getattr(e14, "foot", None) is not None else None
|
|
584
|
+
if graph:
|
|
585
|
+
now = self.baked()
|
|
586
|
+
moved = [k for k, t in now.items() if t is not self._baked[k]]
|
|
587
|
+
assert not moved, f"P3: state the graphs bake in was reassigned after recording: {moved}"
|
|
588
|
+
e14.win.flags.zero_() # this window's adjoint flags (SapoVec.train reads them with gn; no eager reset() here)
|
|
589
|
+
algo._rag_max_gpu.zero_()
|
|
590
|
+
algo._rag_nonfinite_gpu.zero_()
|
|
591
|
+
alpha = algo.get_alpha().detach()
|
|
592
|
+
self.rms.mean.copy_(algo.obs_rms.mean) # the window's frozen normalizer (deepcopy in compute_actor_loss)
|
|
593
|
+
self.rms.var.copy_(algo.obs_rms.var)
|
|
594
|
+
obs = env.initialize_trajectory()
|
|
595
|
+
self.window_start()
|
|
596
|
+
if self.pool is not None: # (S2b) this window's pool, outside the graphs (the state put back bitwise)
|
|
597
|
+
self.pool.build()
|
|
598
|
+
if self.pool.n_builds == 1:
|
|
599
|
+
# a replay runs no Python, so a tensor the reset REBINDS reaches the next slot only through A's outputs or the extras;
|
|
600
|
+
# an in-place one lives in memory the graphs write (env14's warm / reset mask, z, actions, progress, _just_reset)
|
|
601
|
+
cov = {"q", "qd", "lce", "a", "phase", "progress"}
|
|
602
|
+
# dead state the reset writes and nothing reads before it is overwritten: env.actions (the next _step_a sets it first),
|
|
603
|
+
# the RSI's clip id (imitation.py writes it, nothing reads it)
|
|
604
|
+
dead = {"actions", "imitation_task._rsi_clip_id"}
|
|
605
|
+
|
|
606
|
+
def name(k):
|
|
607
|
+
root, path = k
|
|
608
|
+
s_ = "" if root == "env" else root + "."
|
|
609
|
+
s_ += path[0][1] + "".join(f"['{t}']" if kd == "key" else f"[{t}]" for kd, t in path[1:])
|
|
610
|
+
return s_
|
|
611
|
+
miss = [name(k) for k, kind, _ in self.pool.entries if kind == "rebind"
|
|
612
|
+
and not (k[0] == "env" and len(k[1]) == 1 and k[1][0][1] in cov) and name(k) not in self.extra
|
|
613
|
+
and name(k) not in dead]
|
|
614
|
+
assert not miss, f"the reset pool rebinds state no slot output carries (add it to TASKWALK_STATE): {miss}"
|
|
615
|
+
algo.obs_rms.update(obs)
|
|
616
|
+
obs = self.rms.normalize(obs)
|
|
617
|
+
tw = env.taskwalk if self.extra is not None else None
|
|
618
|
+
if tw is not None:
|
|
619
|
+
if tw._speed_p is not None:
|
|
620
|
+
assert tw._speed_p._calls == 0, f"the speed P window is not aligned with SAPO's: _calls {tw._speed_p._calls} at its start"
|
|
621
|
+
for p_ in self.extra: # the previous window's history ends here: its graph is freed after its backward, so no
|
|
622
|
+
v = self._ex_get(p_) # gradient can flow into it (stock training would fail if one did); detached, slot 0's
|
|
623
|
+
if torch.is_tensor(v) and v.grad_fn is not None: # inputs carry the same grad flags in every window (the record cuts them
|
|
624
|
+
self._ex_set(p_, v.detach()) # once; a replay window would otherwise see attached ones)
|
|
625
|
+
self._fill_wblock()
|
|
626
|
+
tw._wt_frozen = True # the schedule writes floats only inside the window; A_k copies the block's row
|
|
627
|
+
pres_rec, pres_out_rec, pres_b_rec = [], [], []
|
|
628
|
+
if not hasattr(self, "_pres_live"):
|
|
629
|
+
self._pres_live, self._opres_live, self._bpres_live = [None] * S, [None] * S, [None] * S
|
|
630
|
+
racc = torch.zeros(N, device=dev)
|
|
631
|
+
gamma = torch.ones(N, device=dev)
|
|
632
|
+
actor_loss = torch.zeros((), device=dev)
|
|
633
|
+
algo._window_states, algo._grad_order = None, []
|
|
634
|
+
t0_win = env._train_steps # the window's first step count (slot k's is t0_win + k + 1)
|
|
635
|
+
rec = [] if self.record_next else None
|
|
636
|
+
if tw is not None and rec is not None and self.windows["eager"] + self.windows["graph"] == 0:
|
|
637
|
+
rec = None # the very first window is not the steady one: its slot 0 lacks the entries the first
|
|
638
|
+
# steps make (_tw_last_u, the reward's _prev, ...); the second window is recorded
|
|
639
|
+
if tw is not None:
|
|
640
|
+
key = self._live_key(env._train_steps)
|
|
641
|
+
crossing = any(len(x) == 3 and x[1] != x[2] for x in key) # (the pool's entry has no ends to cross)
|
|
642
|
+
if graph and (crossing or key != self._key_rec):
|
|
643
|
+
# a scheduled term turns on (or off) in this window: the graphs replay the recorded control flow, so they are stale.
|
|
644
|
+
# This window runs eagerly; a window without a crossing is recorded and captured at the next one.
|
|
645
|
+
print(f"[sapo_capture] TW1: the reward's control flow changes at step {env._train_steps} ({key} against the recorded "
|
|
646
|
+
f"{self._key_rec}): the graphs are dropped and re-recorded", flush=True)
|
|
647
|
+
self.graphs, self.samples, self.present = None, None, None
|
|
648
|
+
graph = False
|
|
649
|
+
torch.cuda.empty_cache()
|
|
650
|
+
self.record_next, rec = True, [] # this window is the new recording (unless it is the crossing itself)
|
|
651
|
+
if rec is not None and crossing: # a crossing window is never the one recorded
|
|
652
|
+
rec = None
|
|
653
|
+
self.record_next = True
|
|
654
|
+
steady = getattr(self, "_key_last", None) == key and not getattr(self, "_cross_last", True)
|
|
655
|
+
if rec is not None and not steady:
|
|
656
|
+
# nor the first window with a new control flow (GPU gate 3, graph_6336; the very first window's rule, generalized): the
|
|
657
|
+
# terms that just turned on have no history at its slot 0 (the head acceleration's `_prev` / `_acc_graph` entries) and do
|
|
658
|
+
# at every later window's; the window after it is recorded
|
|
659
|
+
rec = None
|
|
660
|
+
self.record_next = True
|
|
661
|
+
self._key_last, self._cross_last = key, crossing
|
|
662
|
+
if graph:
|
|
663
|
+
now = self._scalars()
|
|
664
|
+
moved = sorted(k for k in now if now[k] != self._scal_ref.get(k))
|
|
665
|
+
assert not moved, f"TW1: Python scalars the graphs baked changed since the capture: {[(k, self._scal_ref.get(k), now[k]) for k in moved]}"
|
|
666
|
+
if rec is not None:
|
|
667
|
+
self._key_rec, self._t0_rec = key, env._train_steps
|
|
668
|
+
for k in range(S):
|
|
669
|
+
eps_a, eps_e = algo._action_noise()
|
|
670
|
+
xa = (obs, eps_a, eps_e, env.q, env.qd, env.lce, env.a, env.z, env.phase, env.progress, task.clip_id)
|
|
671
|
+
if tw is not None:
|
|
672
|
+
pres = self._ex_present()
|
|
673
|
+
if graph: # a replay's extra inputs are its recording's
|
|
674
|
+
assert pres == self.present[k], (k, "extra_state presence", pres, self.present[k])
|
|
675
|
+
if rec is not None:
|
|
676
|
+
pres_rec.append(pres)
|
|
677
|
+
self._pres_live[k] = pres # what step_a reads when it runs eagerly
|
|
678
|
+
xa = xa + tuple(self._ex_get(p_) for p_ in pres)
|
|
679
|
+
if graph: # a replay's gradient surface is its recording's
|
|
680
|
+
assert tuple(x.requires_grad for x in xa) == self.in_grad[k][0], (k, "a", self.in_grad[k][0])
|
|
681
|
+
fa = self.graphs[k][0] if graph else self.A[k]
|
|
682
|
+
outa = fa(*xa)
|
|
683
|
+
if graph and tw is not None: # a replay runs no Python: this slot's step count and the env's Python schedules
|
|
684
|
+
self._py_sched(t0_win + k + 1)
|
|
685
|
+
ent, ent_norm, rew, done, timeout, obr, ep_end, q, qd, lce, a, phase, progress, a1 = outa[:14]
|
|
686
|
+
env.q, env.qd, env.lce, env.a, env.phase, env.progress = q, qd, lce, a, phase, progress
|
|
687
|
+
e14.a1 = a1
|
|
688
|
+
if tw is not None:
|
|
689
|
+
opres = self.present_out[k] if graph else self._opres_live[k]
|
|
690
|
+
if rec is not None:
|
|
691
|
+
pres_out_rec.append(opres)
|
|
692
|
+
if graph: # a replay runs no Python: the state goes back on the env from its outputs
|
|
693
|
+
for p_ in self.extra:
|
|
694
|
+
if p_ not in opres:
|
|
695
|
+
self._ex_set(p_, None)
|
|
696
|
+
for p_, v in zip(opres, outa[14:]):
|
|
697
|
+
self._ex_set(p_, v)
|
|
698
|
+
if self.pool is None:
|
|
699
|
+
self.reset_step(k, graph, q, qd, lce, a, done, timeout)
|
|
700
|
+
xb = (env.q, env.qd, env.lce, env.a, env.z, env.phase, task.clip_id, a1, rew, ent, ent_norm, done, obr, ep_end, racc,
|
|
701
|
+
gamma, actor_loss, alpha)
|
|
702
|
+
if tw is not None:
|
|
703
|
+
bpres = self._ex_present()
|
|
704
|
+
if graph:
|
|
705
|
+
assert bpres == self.present_b[k], (k, "extra_state presence after the reset", bpres, self.present_b[k])
|
|
706
|
+
if rec is not None:
|
|
707
|
+
pres_b_rec.append(bpres)
|
|
708
|
+
self._bpres_live[k] = bpres
|
|
709
|
+
xb = xb + tuple(self._ex_get(p_) for p_ in bpres)
|
|
710
|
+
if graph:
|
|
711
|
+
assert tuple(x.requires_grad for x in xb) == self.in_grad[k][1], (k, "b", self.in_grad[k][1])
|
|
712
|
+
fb = self.graphs[k][1] if graph else self.B[k]
|
|
713
|
+
outb = fb(*xb)
|
|
714
|
+
obs, a_new, racc, gamma, actor_loss = outb
|
|
715
|
+
env.a = a_new
|
|
716
|
+
if self.obr_log is not None:
|
|
717
|
+
self.obr_log.append(obr.detach().clone())
|
|
718
|
+
if rec is not None:
|
|
719
|
+
rec.append((tuple(x.detach().clone().requires_grad_(x.requires_grad) for x in xa),
|
|
720
|
+
tuple(x.detach().clone().requires_grad_(x.requires_grad) for x in xb),
|
|
721
|
+
tuple(o.requires_grad for o in outa), tuple(o.requires_grad for o in outb)))
|
|
722
|
+
self.windows["graph" if graph else "eager"] += 1
|
|
723
|
+
if tw is not None:
|
|
724
|
+
if rec is not None:
|
|
725
|
+
self.present, self.present_out, self.present_b = pres_rec, pres_out_rec, pres_b_rec # the recorded window's (record() reads them)
|
|
726
|
+
if graph: # a replay runs no Python: _py_sched set the step count per slot (t0 + S at the last)
|
|
727
|
+
assert env._train_steps == t0_win + S, (env._train_steps, t0_win, S)
|
|
728
|
+
if tw._speed_p is not None:
|
|
729
|
+
tw._speed_p._calls += S
|
|
730
|
+
tw._wt_frozen = False
|
|
731
|
+
if tw._speed_p is not None:
|
|
732
|
+
tw.speed_p_window_end() # the window boundary: the update the step deferred
|
|
733
|
+
if rec is not None:
|
|
734
|
+
self.samples, self.record_next = rec, False
|
|
735
|
+
actor_loss = actor_loss / (S * N)
|
|
736
|
+
algo.step_count += S * N
|
|
737
|
+
algo.last_cut_frac = 0.0
|
|
738
|
+
if guards is not None: # a replay runs no Python, so its latch reads are 0; an eager window reads once per step
|
|
739
|
+
guards(f"window {self.windows['eager'] + self.windows['graph']} ({'replay' if graph else 'eager'})",
|
|
740
|
+
None if reads0 is None else (e14.foot.n_calls - reads0, 0 if graph else S))
|
|
741
|
+
return actor_loss
|
|
742
|
+
|
|
743
|
+
def record(self, parts="ab"):
|
|
744
|
+
"""the per-slot graphs from the last eager window's inputs (call after that window's backward, with no live reference to
|
|
745
|
+
its graph: drop the loss first); the state the warm-ups and captures touch is snapshotted and restored in place, and the
|
|
746
|
+
adjoint's flags and the gradient monitors are cleared"""
|
|
747
|
+
assert self.mode == "graph" and self.samples is not None and self.graphs is None
|
|
748
|
+
algo, env, e14 = self.algo, self.env, self.e14
|
|
749
|
+
# free the recorded window's graph first. A leaf parameter's AccumulateGrad node is cached and keeps the stream it was
|
|
750
|
+
# created on: while the last eager window's graph is alive (the env's state depends on its actions), the actor's nodes
|
|
751
|
+
# from that window (the legacy default stream) are reused inside the capture, and the backward capture fails
|
|
752
|
+
# (cudaErrorStreamCaptureImplicit; found by capturing the actor's own layers against a fresh one). The window is over
|
|
753
|
+
# and its values stay: only the history goes.
|
|
754
|
+
import gc
|
|
755
|
+
|
|
756
|
+
def has_hist(v):
|
|
757
|
+
if torch.is_tensor(v):
|
|
758
|
+
return v.grad_fn is not None
|
|
759
|
+
if isinstance(v, (tuple, list)):
|
|
760
|
+
return any(has_hist(x) for x in v)
|
|
761
|
+
if isinstance(v, dict):
|
|
762
|
+
return any(has_hist(x) for x in v.values())
|
|
763
|
+
return False
|
|
764
|
+
|
|
765
|
+
def cut(v): # tensors, and tensors inside tuples / lists / dicts (env14's out, cap)
|
|
766
|
+
if torch.is_tensor(v):
|
|
767
|
+
return v.detach() if v.grad_fn is not None else v
|
|
768
|
+
if isinstance(v, (tuple, list)):
|
|
769
|
+
return type(v)(cut(x) for x in v)
|
|
770
|
+
if isinstance(v, dict):
|
|
771
|
+
return {k: cut(x) for k, x in v.items()}
|
|
772
|
+
return v
|
|
773
|
+
cutn = []
|
|
774
|
+
for o in (env, self.task, e14, algo, self) + (tuple(x for x in (env.taskwalk, env.mirror) if x is not None) if self.extra is not None else ()):
|
|
775
|
+
for k, v in list(vars(o).items()):
|
|
776
|
+
if has_hist(v): # only what still carries the window's history is replaced
|
|
777
|
+
setattr(o, k, cut(v))
|
|
778
|
+
cutn.append(f"{type(o).__name__}.{k}")
|
|
779
|
+
gc.collect()
|
|
780
|
+
torch.cuda.empty_cache() # the pool reuses what the eager window held (else the 4090 spills on WSL)
|
|
781
|
+
print(f"[sapo_capture] record: the last window's history cut at {cutn}", flush=True)
|
|
782
|
+
gb = lambda b: f"{b / 2**30:.2f}"
|
|
783
|
+
sbytes = sum(x.numel() * x.element_size() for sk in self.samples for xs in sk[:2] for x in xs)
|
|
784
|
+
print(f"[sapo_capture] record: before the graphs allocated {gb(torch.cuda.memory_allocated())} GB, reserved "
|
|
785
|
+
f"{gb(torch.cuda.memory_reserved())}, of which the recorded inputs {gb(sbytes)}", flush=True)
|
|
786
|
+
keep = {k: t.detach().to("cpu", copy=True) for k, t in self.baked().items()} # on the host (obs_buf alone is 0.37 GB at 4,096 x 32);
|
|
787
|
+
# copy=True: a CPU tensor's .cpu() is itself, so the restore was a no-op on the Mac's emulation (on the GPU .cpu() copies anyway)
|
|
788
|
+
attrs = ("q", "qd", "lce", "a", "z", "phase", "progress", "actions")
|
|
789
|
+
env_keep = {k: getattr(env, k) for k in attrs}
|
|
790
|
+
if self.extra is not None: # the warm-ups and captures run every slot 4 times: the taskwalk state they touch
|
|
791
|
+
tw = env.taskwalk
|
|
792
|
+
ex_keep = {p_: self._ex_get(p_) for p_ in self.extra}
|
|
793
|
+
int_keep = dict(train_steps=env._train_steps,
|
|
794
|
+
sp=(tw._speed_p._calls, tw._speed_p.n_updates) if tw._speed_p is not None else None,
|
|
795
|
+
w={n: getattr(tw, n) for n in vars(tw) if n.startswith("w_") and isinstance(getattr(tw, n), float)})
|
|
796
|
+
clip_keep, a1_keep = self.task.clip_id, e14.a1
|
|
797
|
+
assert parts in ("ab", "a", "b"), parts # "a" / "b": graph one half of every step, the other eager
|
|
798
|
+
calls, args = [], []
|
|
799
|
+
for k in range(self.S):
|
|
800
|
+
for p, f, x in (("a", self.A[k], self.samples[k][0]), ("b", self.B[k], self.samples[k][1])):
|
|
801
|
+
if p in parts:
|
|
802
|
+
calls.append(f)
|
|
803
|
+
args.append(x)
|
|
804
|
+
masks = [(sk[2], sk[3]) for sk in self.samples]
|
|
805
|
+
self.in_grad = [(tuple(x.requires_grad for x in sk[0]), tuple(x.requires_grad for x in sk[1])) for sk in self.samples]
|
|
806
|
+
self.samples = None # args holds the recorded inputs now (the chain frees the linked ones)
|
|
807
|
+
self.memtrace = False
|
|
808
|
+
nex = None
|
|
809
|
+
if self.extra is not None:
|
|
810
|
+
self._pres_live, self._bpres_live = list(self.present), list(self.present_b) # the warm-ups and captures run on the recorded inputs
|
|
811
|
+
self._opres_live = [None] * self.S
|
|
812
|
+
nex = ([len(self.present[k]) for k in range(self.S)], [len(self.present_b[k]) for k in range(self.S)])
|
|
813
|
+
self._recording = True
|
|
814
|
+
env.taskwalk._wt_frozen = True # the warm-ups and captures are inside a window: set_weight must not build tensors (a host
|
|
815
|
+
# to device copy, refused under capture; the GPU gate's graph arm, 11-10)
|
|
816
|
+
g = iter(self._chain(calls, args, _chain_links(self.S, parts, nex)))
|
|
817
|
+
self._recording = False
|
|
818
|
+
if self.extra is not None:
|
|
819
|
+
env.taskwalk._wt_frozen = False
|
|
820
|
+
del args
|
|
821
|
+
self.graphs = [(_graded(next(g), masks[k][0]) if "a" in parts else self.A[k],
|
|
822
|
+
_graded(next(g), masks[k][1]) if "b" in parts else self.B[k]) for k in range(self.S)]
|
|
823
|
+
self.parts = parts
|
|
824
|
+
self.memtrace = False
|
|
825
|
+
with torch.no_grad():
|
|
826
|
+
for k, t in self.baked().items():
|
|
827
|
+
t.copy_(keep[k]) # host to device directly (a device temporary here sits at the peak)
|
|
828
|
+
e14.win.flags.zero_() # the warm-ups' backward ran on garbage cotangents
|
|
829
|
+
for k, v in env_keep.items():
|
|
830
|
+
setattr(env, k, v)
|
|
831
|
+
self.task.clip_id, e14.a1 = clip_keep, a1_keep
|
|
832
|
+
if self.extra is not None:
|
|
833
|
+
for p_, v in ex_keep.items():
|
|
834
|
+
self._ex_set(p_, v)
|
|
835
|
+
env._train_steps = int_keep["train_steps"]
|
|
836
|
+
if int_keep["sp"] is not None:
|
|
837
|
+
tw._speed_p._calls, tw._speed_p.n_updates = int_keep["sp"]
|
|
838
|
+
for n, v in int_keep["w"].items():
|
|
839
|
+
setattr(tw, n, v)
|
|
840
|
+
self._scal_ref = self._scalars() # what the captures read: a later change outside the routed set fails fast
|
|
841
|
+
e14.k = 0
|
|
842
|
+
self._baked = self.baked()
|
|
843
|
+
print(f"[sapo_capture] record: after the graphs allocated {gb(torch.cuda.memory_allocated())} GB, reserved "
|
|
844
|
+
f"{gb(torch.cuda.memory_reserved())}, peak {gb(torch.cuda.max_memory_allocated())}", flush=True)
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
def install_from_env(algo, env, e14):
|
|
848
|
+
"""E0_P3=1 is the trainer's flag: SAPO's actor window as per-slot CUDA graphs. Unset or 0: nothing (the default path).
|
|
849
|
+
Install after env14, the arm's critic change and the levers (B's graphs hold the critic as it is then, m1c compiled in
|
|
850
|
+
place). The first window runs eagerly and is recorded; the graphs are captured at the start of the second (SapoVec.train
|
|
851
|
+
deletes each window's loss at the end of its iteration, so no live graph reaches the capture)."""
|
|
852
|
+
v = os.environ.get("E0_P3", "0")
|
|
853
|
+
assert v in ("0", "1"), f"E0_P3={v!r}"
|
|
854
|
+
if v == "0":
|
|
855
|
+
return None
|
|
856
|
+
W = install(algo, env, e14, "graph")
|
|
857
|
+
print(f"[sapo_capture] E0_P3=1: the actor window as per-slot CUDA graphs ({algo.steps_num} steps x {algo.num_envs} envs)",
|
|
858
|
+
flush=True)
|
|
859
|
+
return W
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
def install(algo, env, e14, mode, extra_state=None, pool=False):
|
|
863
|
+
W = SapoWindow(algo, env, e14, mode, extra_state, pool)
|
|
864
|
+
orig = algo.compute_actor_loss
|
|
865
|
+
|
|
866
|
+
def compute_actor_loss():
|
|
867
|
+
return W.actor_loss()
|
|
868
|
+
algo.compute_actor_loss = compute_actor_loss
|
|
869
|
+
|
|
870
|
+
def undo():
|
|
871
|
+
algo.compute_actor_loss = orig
|
|
872
|
+
W.undo = undo
|
|
873
|
+
return W
|