anhtld commited on
Commit
df82245
·
verified ·
1 Parent(s): e6c1804

Auto-sync: 2026-06-30 03:27:59 (part 4)

Browse files
tests/test_maniskill_policy_rollout.py CHANGED
@@ -21,6 +21,7 @@ from dovla_cil.eval.maniskill_policy_rollout import (
21
  _attach_retrieved_residual_candidates,
22
  _diagnostic_candidate_indices,
23
  _effective_lattice_candidate_count,
 
24
  _lattice_candidate_mask,
25
  _lattice_candidate_type_bonus,
26
  _load_state_archive,
@@ -311,6 +312,33 @@ def test_retrieval_residual_margin_can_abstain_to_policy() -> None:
311
  assert index.tolist() == [0]
312
 
313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  def test_candidate_oracle_prefix_keeps_deployed_candidate_first() -> None:
315
  import torch
316
 
@@ -554,6 +582,39 @@ def test_lattice_candidate_mask_can_exclude_exact_composite_without_parts() -> N
554
  assert mask.tolist() == [[True, True, False, True]]
555
 
556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  def test_lattice_candidate_type_bonus_can_sum_composite_parts() -> None:
558
  import torch
559
 
 
21
  _attach_retrieved_residual_candidates,
22
  _diagnostic_candidate_indices,
23
  _effective_lattice_candidate_count,
24
+ _lattice_candidate_include_mask,
25
  _lattice_candidate_mask,
26
  _lattice_candidate_type_bonus,
27
  _load_state_archive,
 
312
  assert index.tolist() == [0]
313
 
314
 
315
+ def test_retrieval_residual_challenger_can_override_primary_anchor() -> None:
316
+ import torch
317
+
318
+ mean = torch.zeros(1, 1, 1)
319
+ offset = torch.full_like(mean, 0.4)
320
+ model = _StubModel(torch, mean, best_offset=offset)
321
+ residuals = torch.tensor([[[[0.0]], [[0.1]], [[0.4]]]], dtype=torch.float32)
322
+
323
+ actions, index = _select_action_chunk(
324
+ model,
325
+ observations=torch.zeros(1, 3),
326
+ instructions=["a"],
327
+ torch=torch,
328
+ selection_mode="retrieval_residual",
329
+ num_candidates=1,
330
+ candidate_sigma=0.0,
331
+ selection_seed=0,
332
+ selection_margin=1.0,
333
+ action_candidates=residuals,
334
+ challenger_mask=torch.tensor([[False, False, True]]),
335
+ challenger_margin=0.05,
336
+ )
337
+
338
+ assert torch.allclose(actions, mean + offset)
339
+ assert index.tolist() == [2]
340
+
341
+
342
  def test_candidate_oracle_prefix_keeps_deployed_candidate_first() -> None:
343
  import torch
344
 
 
582
  assert mask.tolist() == [[True, True, False, True]]
583
 
584
 
585
+ def test_lattice_candidate_include_mask_uses_exact_candidate_types() -> None:
586
+ import torch
587
+
588
+ case = _RolloutCase(
589
+ group_id="g",
590
+ task_id="PickCube-v1",
591
+ source_dataset=Path("."),
592
+ state={},
593
+ observation={"features": [0.0]},
594
+ instruction="pick",
595
+ oracle_score=1.0,
596
+ oracle_success=True,
597
+ expert_score=1.0,
598
+ expert_success=True,
599
+ best_action_values=[[0.0]],
600
+ candidate_action_values=[[[0.0]], [[0.2]], [[0.4]]],
601
+ candidate_types=[
602
+ "policy_residual",
603
+ "residual_near_miss",
604
+ "residual_near_miss+residual_wrong_gripper",
605
+ ],
606
+ )
607
+
608
+ mask = _lattice_candidate_include_mask(
609
+ [case],
610
+ torch=torch,
611
+ device="cpu",
612
+ include_types=("residual_near_miss",),
613
+ )
614
+
615
+ assert mask.tolist() == [[False, True, False]]
616
+
617
+
618
  def test_lattice_candidate_type_bonus_can_sum_composite_parts() -> None:
619
  import torch
620