Skip to content

Commit e347cb6

Browse files
yijiegkellyguo11
andcommitted
Fixes warnings when running AutoMate env (#3660)
# Description * Fixes the warning messages reported in the QA testing * Remove redundant config argument 'sample_from' * Change the default value of config argument 'num_log_traj' ## Type of change - Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I have read and understood the [contribution guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html) - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Co-authored-by: Kelly Guo <[email protected]>
1 parent fbb57b7 commit e347cb6

File tree

5 files changed

+22
-52
lines changed

5 files changed

+22
-52
lines changed

source/isaaclab_tasks/isaaclab_tasks/direct/automate/assembly_env.py

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,12 @@ def __init__(self, cfg: AssemblyEnvCfg, render_mode: str | None = None, **kwargs
6060
)
6161

6262
# Create criterion for dynamic time warping (later used for imitation reward)
63-
self.soft_dtw_criterion = SoftDTW(use_cuda=True, gamma=self.cfg_task.soft_dtw_gamma)
63+
self.soft_dtw_criterion = SoftDTW(use_cuda=True, device=self.device, gamma=self.cfg_task.soft_dtw_gamma)
6464

6565
# Evaluate
6666
if self.cfg_task.if_logging_eval:
6767
self._init_eval_logging()
6868

69-
if self.cfg_task.sample_from != "rand":
70-
self._init_eval_loading()
71-
72-
def _init_eval_loading(self):
73-
eval_held_asset_pose, eval_fixed_asset_pose, eval_success = automate_log.load_log_from_hdf5(
74-
self.cfg_task.eval_filename
75-
)
76-
77-
if self.cfg_task.sample_from == "gp":
78-
self.gp = automate_algo.model_succ_w_gp(eval_held_asset_pose, eval_fixed_asset_pose, eval_success)
79-
elif self.cfg_task.sample_from == "gmm":
80-
self.gmm = automate_algo.model_succ_w_gmm(eval_held_asset_pose, eval_fixed_asset_pose, eval_success)
81-
8269
def _init_eval_logging(self):
8370

8471
self.held_asset_pose_log = torch.empty(
@@ -246,7 +233,7 @@ def _load_disassembly_data(self):
246233
# offset each trajectory to be relative to the goal
247234
eef_pos_traj.append(curr_ee_traj - curr_ee_goal)
248235

249-
self.eef_pos_traj = torch.tensor(eef_pos_traj, dtype=torch.float32, device=self.device).squeeze()
236+
self.eef_pos_traj = torch.tensor(np.array(eef_pos_traj), dtype=torch.float32, device=self.device).squeeze()
250237

251238
def _get_keypoint_offsets(self, num_keypoints):
252239
"""Get uniformly-spaced keypoints along a line of unit length, centered at 0."""
@@ -804,28 +791,12 @@ def randomize_held_initial_state(self, env_ids, pre_grasp):
804791
torch.rand((self.num_envs,), dtype=torch.float32, device=self.device)
805792
)
806793

807-
if self.cfg_task.sample_from == "rand":
808-
809-
rand_sample = torch.rand((len(env_ids), 3), dtype=torch.float32, device=self.device)
810-
held_pos_init_rand = 2 * (rand_sample - 0.5) # [-1, 1]
811-
held_asset_init_pos_rand = torch.tensor(
812-
self.cfg_task.held_asset_init_pos_noise, dtype=torch.float32, device=self.device
813-
)
814-
self.held_pos_init_rand = held_pos_init_rand @ torch.diag(held_asset_init_pos_rand)
815-
816-
if self.cfg_task.sample_from == "gp":
817-
rand_sample = torch.rand((self.cfg_task.num_gp_candidates, 3), dtype=torch.float32, device=self.device)
818-
held_pos_init_rand = 2 * (rand_sample - 0.5) # [-1, 1]
819-
held_asset_init_pos_rand = torch.tensor(
820-
self.cfg_task.held_asset_init_pos_noise, dtype=torch.float32, device=self.device
821-
)
822-
held_asset_init_candidates = held_pos_init_rand @ torch.diag(held_asset_init_pos_rand)
823-
self.held_pos_init_rand, _ = automate_algo.propose_failure_samples_batch_from_gp(
824-
self.gp, held_asset_init_candidates.cpu().detach().numpy(), len(env_ids), self.device
825-
)
826-
827-
if self.cfg_task.sample_from == "gmm":
828-
self.held_pos_init_rand = automate_algo.sample_rel_pos_from_gmm(self.gmm, len(env_ids), self.device)
794+
rand_sample = torch.rand((len(env_ids), 3), dtype=torch.float32, device=self.device)
795+
held_pos_init_rand = 2 * (rand_sample - 0.5) # [-1, 1]
796+
held_asset_init_pos_rand = torch.tensor(
797+
self.cfg_task.held_asset_init_pos_noise, dtype=torch.float32, device=self.device
798+
)
799+
self.held_pos_init_rand = held_pos_init_rand @ torch.diag(held_asset_init_pos_rand)
829800

830801
# Set plug pos to assembled state, but offset plug Z-coordinate by height of socket,
831802
# minus curriculum displacement

source/isaaclab_tasks/isaaclab_tasks/direct/automate/assembly_tasks_cfg.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ class AssemblyTask:
139139
num_eval_trials: int = 100
140140
eval_filename: str = "evaluation_00015.h5"
141141

142-
# Fine-tuning
143-
sample_from: str = "rand" # gp, gmm, idv, rand
144-
num_gp_candidates: int = 1000
145-
146142

147143
@configclass
148144
class Peg8mm(HeldAssetCfg):

source/isaaclab_tasks/isaaclab_tasks/direct/automate/disassembly_tasks_cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Extraction(DisassemblyTask):
118118
assembly_id = "00015"
119119
assembly_dir = f"{ASSET_DIR}/{assembly_id}/"
120120
disassembly_dir = "disassembly_dir"
121-
num_log_traj = 1000
121+
num_log_traj = 100
122122

123123
fixed_asset_cfg = Hole8mm()
124124
held_asset_cfg = Peg8mm()

source/isaaclab_tasks/isaaclab_tasks/direct/automate/run_w_id.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ def main():
5959

6060
update_task_param(args.cfg_path, args.assembly_id, args.train, args.log_eval)
6161

62-
bash_command = None
62+
# avoid the warning of low GPU occupancy for SoftDTWCUDA function
63+
bash_command = "NUMBA_CUDA_LOW_OCCUPANCY_WARNINGS=0"
6364
if sys.platform.startswith("win"):
64-
bash_command = "isaaclab.bat -p"
65+
bash_command += " isaaclab.bat -p"
6566
elif sys.platform.startswith("linux"):
66-
bash_command = "./isaaclab.sh -p"
67+
bash_command += " ./isaaclab.sh -p"
6768
if args.train:
6869
bash_command += " scripts/reinforcement_learning/rl_games/train.py --task=Isaac-AutoMate-Assembly-Direct-v0"
6970
bash_command += f" --seed={str(args.seed)} --max_iterations={str(args.max_iterations)}"

source/isaaclab_tasks/isaaclab_tasks/direct/automate/soft_dtw_cuda.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ class _SoftDTWCUDA(Function):
120120
"""
121121

122122
@staticmethod
123-
def forward(ctx, D, gamma, bandwidth):
123+
def forward(ctx, D, device, gamma, bandwidth):
124124
dev = D.device
125125
dtype = D.dtype
126-
gamma = torch.cuda.FloatTensor([gamma])
127-
bandwidth = torch.cuda.FloatTensor([bandwidth])
126+
gamma = torch.tensor([gamma], dtype=torch.float, device=device)
127+
bandwidth = torch.tensor([bandwidth], dtype=torch.float, device=device)
128128

129129
B = D.shape[0]
130130
N = D.shape[1]
@@ -255,7 +255,7 @@ class _SoftDTW(Function):
255255
"""
256256

257257
@staticmethod
258-
def forward(ctx, D, gamma, bandwidth):
258+
def forward(ctx, D, device, gamma, bandwidth):
259259
dev = D.device
260260
dtype = D.dtype
261261
gamma = torch.Tensor([gamma]).to(dev).type(dtype) # dtype fixed
@@ -286,10 +286,11 @@ class SoftDTW(torch.nn.Module):
286286
The soft DTW implementation that optionally supports CUDA
287287
"""
288288

289-
def __init__(self, use_cuda, gamma=1.0, normalize=False, bandwidth=None, dist_func=None):
289+
def __init__(self, use_cuda, device, gamma=1.0, normalize=False, bandwidth=None, dist_func=None):
290290
"""
291291
Initializes a new instance using the supplied parameters
292292
:param use_cuda: Flag indicating whether the CUDA implementation should be used
293+
:param device: device to run the soft dtw computation
293294
:param gamma: sDTW's gamma parameter
294295
:param normalize: Flag indicating whether to perform normalization
295296
(as discussed in https://github.com/mblondel/soft-dtw/issues/10#issuecomment-383564790)
@@ -301,6 +302,7 @@ def __init__(self, use_cuda, gamma=1.0, normalize=False, bandwidth=None, dist_fu
301302
self.gamma = gamma
302303
self.bandwidth = 0 if bandwidth is None else float(bandwidth)
303304
self.use_cuda = use_cuda
305+
self.device = device
304306

305307
# Set the distance function
306308
if dist_func is not None:
@@ -357,12 +359,12 @@ def forward(self, X, Y):
357359
x = torch.cat([X, X, Y])
358360
y = torch.cat([Y, X, Y])
359361
D = self.dist_func(x, y)
360-
out = func_dtw(D, self.gamma, self.bandwidth)
362+
out = func_dtw(D, self.device, self.gamma, self.bandwidth)
361363
out_xy, out_xx, out_yy = torch.split(out, X.shape[0])
362364
return out_xy - 1 / 2 * (out_xx + out_yy)
363365
else:
364366
D_xy = self.dist_func(X, Y)
365-
return func_dtw(D_xy, self.gamma, self.bandwidth)
367+
return func_dtw(D_xy, self.device, self.gamma, self.bandwidth)
366368

367369

368370
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)