td-builder commited on
Commit
401180b
·
verified ·
1 Parent(s): 6f011d4

Upload train_isaac_humanoid.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. train_isaac_humanoid.py +74 -0
train_isaac_humanoid.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Isaac Lab Humanoid — Upright Walking Training
3
+ ===============================================
4
+ Uses NVIDIA Isaac Sim physics with Isaac Lab's humanoid environment.
5
+ Custom reward weights for upright, stable walking.
6
+
7
+ Runs 2048 parallel environments on GPU (vs 16 in MuJoCo).
8
+
9
+ Author: Milan Narula
10
+ Project: ARCSA AIR Scholarship Application
11
+ """
12
+
13
+ import sys
14
+ sys.argv += ["--headless"]
15
+
16
+ from isaaclab.app import AppLauncher
17
+ launcher = AppLauncher({"headless": True})
18
+ sim_app = launcher.app
19
+
20
+ import gymnasium as gym
21
+ import torch
22
+ import isaaclab_tasks # registers all Isaac Lab envs
23
+
24
+ from isaaclab_tasks.direct.humanoid.humanoid_env import HumanoidEnvCfg
25
+
26
+ # ── Custom config: heavy uprightness reward ──
27
+ cfg = HumanoidEnvCfg()
28
+ cfg.up_weight = 2.0 # default 0.1 — 20x increase
29
+ cfg.alive_reward_scale = 3.0 # reward for staying alive
30
+ cfg.heading_weight = 0.5 # reward for walking straight
31
+ cfg.termination_height = 0.9 # terminate if torso drops below this
32
+
33
+ # Run 2048 envs in parallel on GPU
34
+ cfg.scene.num_envs = 2048
35
+
36
+ print("=" * 60)
37
+ print("ISAAC LAB HUMANOID — Upright Walking")
38
+ print(f"Physics: NVIDIA PhysX (Isaac Sim 5.1)")
39
+ print(f"Parallel envs: {cfg.scene.num_envs}")
40
+ print(f"Uprightness weight: {cfg.up_weight} (20x default)")
41
+ print("=" * 60)
42
+
43
+ env = gym.make("Isaac-Humanoid-Direct-v0", cfg=cfg)
44
+
45
+ # Wrap for rsl_rl
46
+ from isaaclab_tasks.utils.wrappers.rsl_rl import RslRlVecEnvWrapper
47
+ env = RslRlVecEnvWrapper(env)
48
+
49
+ # Load PPO runner config
50
+ from isaaclab_tasks.direct.humanoid.agents.rsl_rl_ppo_cfg import HumanoidPPORunnerCfg
51
+ from rsl_rl.runners import OnPolicyRunner
52
+
53
+ runner_cfg = HumanoidPPORunnerCfg()
54
+ runner_cfg.max_iterations = 3000
55
+
56
+ runner = OnPolicyRunner(
57
+ env,
58
+ runner_cfg.to_dict(),
59
+ log_dir="./logs/humanoid_upright",
60
+ device="cuda"
61
+ )
62
+
63
+ print("\nStarting training...")
64
+ print("With 2048 parallel envs, this should be MUCH faster than MuJoCo\n")
65
+
66
+ runner.learn(
67
+ num_learning_iterations=runner_cfg.max_iterations,
68
+ init_at_random_ep_len=True
69
+ )
70
+
71
+ print("\nTraining complete!")
72
+ print("Model saved in ./logs/humanoid_upright/")
73
+
74
+ sim_app.close()