Auto-sync: 2026-06-28 07:49:25
Browse files
dovla_cil/eval/maniskill_policy_rollout.py
CHANGED
|
@@ -55,6 +55,7 @@ def evaluate_maniskill_policy_rollout(
|
|
| 55 |
num_candidates: int = 1,
|
| 56 |
candidate_sigma: float = 0.2,
|
| 57 |
selection_seed: int = 0,
|
|
|
|
| 58 |
field_optim_steps: int = 0,
|
| 59 |
field_optim_step_size: float = 0.05,
|
| 60 |
field_optim_trust_radius: float = 0.5,
|
|
@@ -138,6 +139,8 @@ def evaluate_maniskill_policy_rollout(
|
|
| 138 |
raise ValueError("field_optim_trust_radius must be non-negative")
|
| 139 |
if field_optim_l2_penalty < 0:
|
| 140 |
raise ValueError("field_optim_l2_penalty must be non-negative")
|
|
|
|
|
|
|
| 141 |
if retrieval_neighbors <= 0:
|
| 142 |
raise ValueError("retrieval_neighbors must be positive")
|
| 143 |
if retrieval_metric not in {"raw", "zscore"}:
|
|
@@ -233,6 +236,7 @@ def evaluate_maniskill_policy_rollout(
|
|
| 233 |
num_candidates=num_candidates,
|
| 234 |
candidate_sigma=candidate_sigma,
|
| 235 |
selection_seed=selection_seed,
|
|
|
|
| 236 |
field_optim_steps=field_optim_steps,
|
| 237 |
field_optim_step_size=field_optim_step_size,
|
| 238 |
field_optim_trust_radius=field_optim_trust_radius,
|
|
@@ -266,6 +270,7 @@ def evaluate_maniskill_policy_rollout(
|
|
| 266 |
if selection_mode in {"field", "field_optim", "retrieval_residual"}
|
| 267 |
and num_candidates > 1
|
| 268 |
else 0.0,
|
|
|
|
| 269 |
"field_optim_steps": field_optim_steps
|
| 270 |
if selection_mode == "field_optim"
|
| 271 |
else 0,
|
|
@@ -599,6 +604,7 @@ def _evaluate_task_cases(
|
|
| 599 |
num_candidates: int = 1,
|
| 600 |
candidate_sigma: float = 0.2,
|
| 601 |
selection_seed: int = 0,
|
|
|
|
| 602 |
field_optim_steps: int = 0,
|
| 603 |
field_optim_step_size: float = 0.05,
|
| 604 |
field_optim_trust_radius: float = 0.5,
|
|
@@ -662,6 +668,7 @@ def _evaluate_task_cases(
|
|
| 662 |
num_candidates=num_candidates,
|
| 663 |
candidate_sigma=candidate_sigma,
|
| 664 |
selection_seed=selection_seed + start,
|
|
|
|
| 665 |
field_optim_steps=field_optim_steps,
|
| 666 |
field_optim_step_size=field_optim_step_size,
|
| 667 |
field_optim_trust_radius=field_optim_trust_radius,
|
|
@@ -761,6 +768,7 @@ def _select_action_chunk(
|
|
| 761 |
num_candidates: int,
|
| 762 |
candidate_sigma: float,
|
| 763 |
selection_seed: int,
|
|
|
|
| 764 |
field_optim_steps: int = 0,
|
| 765 |
field_optim_step_size: float = 0.05,
|
| 766 |
field_optim_trust_radius: float = 0.5,
|
|
@@ -794,6 +802,7 @@ def _select_action_chunk(
|
|
| 794 |
action_low=action_low,
|
| 795 |
action_high=action_high,
|
| 796 |
candidate_mask=candidate_mask,
|
|
|
|
| 797 |
)
|
| 798 |
|
| 799 |
policy_mean = model.forward_policy(observations, instructions)
|
|
@@ -815,6 +824,7 @@ def _select_action_chunk(
|
|
| 815 |
num_gaussian_candidates=num_candidates,
|
| 816 |
candidate_sigma=candidate_sigma,
|
| 817 |
selection_seed=selection_seed,
|
|
|
|
| 818 |
)
|
| 819 |
|
| 820 |
if selection_mode == "policy" or num_candidates <= 1:
|
|
@@ -1054,6 +1064,7 @@ def _select_lattice_action_chunk(
|
|
| 1054 |
action_low: Any | None,
|
| 1055 |
action_high: Any | None,
|
| 1056 |
candidate_mask: Any | None,
|
|
|
|
| 1057 |
) -> tuple[Any, np.ndarray]:
|
| 1058 |
if action_candidates.ndim != 4:
|
| 1059 |
raise ValueError("action_candidates must have shape [B,K,H,D]")
|
|
@@ -1079,6 +1090,13 @@ def _select_lattice_action_chunk(
|
|
| 1079 |
if candidate_mask is not None:
|
| 1080 |
potentials = potentials.masked_fill(~candidate_mask, float("-inf"))
|
| 1081 |
best_index = torch.argmax(potentials, dim=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1082 |
batch_index = torch.arange(batch_size, device=candidates.device)
|
| 1083 |
best_actions = candidates[batch_index, best_index]
|
| 1084 |
return best_actions, best_index.detach().cpu().numpy()
|
|
@@ -1099,6 +1117,7 @@ def _select_residual_lattice_action_chunk(
|
|
| 1099 |
num_gaussian_candidates: int,
|
| 1100 |
candidate_sigma: float,
|
| 1101 |
selection_seed: int,
|
|
|
|
| 1102 |
) -> tuple[Any, np.ndarray]:
|
| 1103 |
if action_residuals.ndim != 4:
|
| 1104 |
raise ValueError("action_residuals must have shape [B,K,H,D]")
|
|
@@ -1147,6 +1166,7 @@ def _select_residual_lattice_action_chunk(
|
|
| 1147 |
else action_high
|
| 1148 |
),
|
| 1149 |
candidate_mask=candidate_mask,
|
|
|
|
| 1150 |
)
|
| 1151 |
|
| 1152 |
|
|
|
|
| 55 |
num_candidates: int = 1,
|
| 56 |
candidate_sigma: float = 0.2,
|
| 57 |
selection_seed: int = 0,
|
| 58 |
+
selection_margin: float = 0.0,
|
| 59 |
field_optim_steps: int = 0,
|
| 60 |
field_optim_step_size: float = 0.05,
|
| 61 |
field_optim_trust_radius: float = 0.5,
|
|
|
|
| 139 |
raise ValueError("field_optim_trust_radius must be non-negative")
|
| 140 |
if field_optim_l2_penalty < 0:
|
| 141 |
raise ValueError("field_optim_l2_penalty must be non-negative")
|
| 142 |
+
if selection_margin < 0:
|
| 143 |
+
raise ValueError("selection_margin must be non-negative")
|
| 144 |
if retrieval_neighbors <= 0:
|
| 145 |
raise ValueError("retrieval_neighbors must be positive")
|
| 146 |
if retrieval_metric not in {"raw", "zscore"}:
|
|
|
|
| 236 |
num_candidates=num_candidates,
|
| 237 |
candidate_sigma=candidate_sigma,
|
| 238 |
selection_seed=selection_seed,
|
| 239 |
+
selection_margin=selection_margin,
|
| 240 |
field_optim_steps=field_optim_steps,
|
| 241 |
field_optim_step_size=field_optim_step_size,
|
| 242 |
field_optim_trust_radius=field_optim_trust_radius,
|
|
|
|
| 270 |
if selection_mode in {"field", "field_optim", "retrieval_residual"}
|
| 271 |
and num_candidates > 1
|
| 272 |
else 0.0,
|
| 273 |
+
"selection_margin": selection_margin,
|
| 274 |
"field_optim_steps": field_optim_steps
|
| 275 |
if selection_mode == "field_optim"
|
| 276 |
else 0,
|
|
|
|
| 604 |
num_candidates: int = 1,
|
| 605 |
candidate_sigma: float = 0.2,
|
| 606 |
selection_seed: int = 0,
|
| 607 |
+
selection_margin: float = 0.0,
|
| 608 |
field_optim_steps: int = 0,
|
| 609 |
field_optim_step_size: float = 0.05,
|
| 610 |
field_optim_trust_radius: float = 0.5,
|
|
|
|
| 668 |
num_candidates=num_candidates,
|
| 669 |
candidate_sigma=candidate_sigma,
|
| 670 |
selection_seed=selection_seed + start,
|
| 671 |
+
selection_margin=selection_margin,
|
| 672 |
field_optim_steps=field_optim_steps,
|
| 673 |
field_optim_step_size=field_optim_step_size,
|
| 674 |
field_optim_trust_radius=field_optim_trust_radius,
|
|
|
|
| 768 |
num_candidates: int,
|
| 769 |
candidate_sigma: float,
|
| 770 |
selection_seed: int,
|
| 771 |
+
selection_margin: float = 0.0,
|
| 772 |
field_optim_steps: int = 0,
|
| 773 |
field_optim_step_size: float = 0.05,
|
| 774 |
field_optim_trust_radius: float = 0.5,
|
|
|
|
| 802 |
action_low=action_low,
|
| 803 |
action_high=action_high,
|
| 804 |
candidate_mask=candidate_mask,
|
| 805 |
+
selection_margin=selection_margin,
|
| 806 |
)
|
| 807 |
|
| 808 |
policy_mean = model.forward_policy(observations, instructions)
|
|
|
|
| 824 |
num_gaussian_candidates=num_candidates,
|
| 825 |
candidate_sigma=candidate_sigma,
|
| 826 |
selection_seed=selection_seed,
|
| 827 |
+
selection_margin=selection_margin,
|
| 828 |
)
|
| 829 |
|
| 830 |
if selection_mode == "policy" or num_candidates <= 1:
|
|
|
|
| 1064 |
action_low: Any | None,
|
| 1065 |
action_high: Any | None,
|
| 1066 |
candidate_mask: Any | None,
|
| 1067 |
+
selection_margin: float = 0.0,
|
| 1068 |
) -> tuple[Any, np.ndarray]:
|
| 1069 |
if action_candidates.ndim != 4:
|
| 1070 |
raise ValueError("action_candidates must have shape [B,K,H,D]")
|
|
|
|
| 1090 |
if candidate_mask is not None:
|
| 1091 |
potentials = potentials.masked_fill(~candidate_mask, float("-inf"))
|
| 1092 |
best_index = torch.argmax(potentials, dim=1)
|
| 1093 |
+
if selection_margin > 0.0 and candidate_count > 0:
|
| 1094 |
+
baseline = potentials[:, 0]
|
| 1095 |
+
best_potential = potentials.gather(1, best_index.reshape(batch_size, 1)).reshape(
|
| 1096 |
+
batch_size
|
| 1097 |
+
)
|
| 1098 |
+
keep_baseline = best_potential <= baseline + float(selection_margin)
|
| 1099 |
+
best_index = torch.where(keep_baseline, torch.zeros_like(best_index), best_index)
|
| 1100 |
batch_index = torch.arange(batch_size, device=candidates.device)
|
| 1101 |
best_actions = candidates[batch_index, best_index]
|
| 1102 |
return best_actions, best_index.detach().cpu().numpy()
|
|
|
|
| 1117 |
num_gaussian_candidates: int,
|
| 1118 |
candidate_sigma: float,
|
| 1119 |
selection_seed: int,
|
| 1120 |
+
selection_margin: float = 0.0,
|
| 1121 |
) -> tuple[Any, np.ndarray]:
|
| 1122 |
if action_residuals.ndim != 4:
|
| 1123 |
raise ValueError("action_residuals must have shape [B,K,H,D]")
|
|
|
|
| 1166 |
else action_high
|
| 1167 |
),
|
| 1168 |
candidate_mask=candidate_mask,
|
| 1169 |
+
selection_margin=selection_margin,
|
| 1170 |
)
|
| 1171 |
|
| 1172 |
|