Auto-sync: 2026-06-29 08:12:42
Browse files
dovla_cil/eval/maniskill_policy_rollout.py
CHANGED
|
@@ -22,7 +22,12 @@ from dovla_cil.models.dovla import (
|
|
| 22 |
from dovla_cil.utils.io import read_json, write_json
|
| 23 |
|
| 24 |
|
| 25 |
-
_NUMPY_RESIDUAL_REDUCERS = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
_FIELD_CONDITIONED_RESIDUAL_REDUCERS = {"field_softmax"}
|
| 27 |
_RESIDUAL_REDUCERS = (
|
| 28 |
{"none"} | _NUMPY_RESIDUAL_REDUCERS | _FIELD_CONDITIONED_RESIDUAL_REDUCERS
|
|
@@ -194,7 +199,8 @@ def evaluate_maniskill_policy_rollout(
|
|
| 194 |
if retrieval_residual_reduce not in _RESIDUAL_REDUCERS:
|
| 195 |
raise ValueError(
|
| 196 |
"retrieval_residual_reduce must be 'none', 'mean_by_type', "
|
| 197 |
-
"'median_by_type', 'kernel_mean_by_type',
|
|
|
|
| 198 |
)
|
| 199 |
if not 0.0 <= retrieval_type_min_success <= 1.0:
|
| 200 |
raise ValueError("retrieval_type_min_success must be in [0, 1]")
|
|
@@ -820,9 +826,15 @@ def _reduce_residual_candidates_by_type(
|
|
| 820 |
) -> tuple[list[list[list[float]]], list[str]] | tuple[
|
| 821 |
list[list[list[float]]], list[str], list[float]
|
| 822 |
]:
|
| 823 |
-
if mode not in {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 824 |
raise ValueError(
|
| 825 |
-
"mode must be 'mean_by_type', 'median_by_type',
|
|
|
|
| 826 |
)
|
| 827 |
if len(residuals) != len(candidate_types):
|
| 828 |
raise ValueError("residuals and candidate_types must have the same length")
|
|
@@ -852,7 +864,7 @@ def _reduce_residual_candidates_by_type(
|
|
| 852 |
if not values:
|
| 853 |
continue
|
| 854 |
stack = np.stack(values, axis=0)
|
| 855 |
-
if mode
|
| 856 |
reduced = np.mean(stack, axis=0)
|
| 857 |
reduced_bonus = float(np.mean(value_bonuses)) if value_bonuses else 0.0
|
| 858 |
elif mode == "kernel_mean_by_type":
|
|
@@ -887,6 +899,23 @@ def _reduce_residual_candidates_by_type(
|
|
| 887 |
reduced_residuals.append(reduced.astype(np.float32).tolist())
|
| 888 |
reduced_types.append(candidate_type)
|
| 889 |
reduced_bonuses.append(reduced_bonus)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 890 |
if bonuses is None:
|
| 891 |
return reduced_residuals, reduced_types
|
| 892 |
return reduced_residuals, reduced_types, reduced_bonuses
|
|
|
|
| 22 |
from dovla_cil.utils.io import read_json, write_json
|
| 23 |
|
| 24 |
|
| 25 |
+
_NUMPY_RESIDUAL_REDUCERS = {
|
| 26 |
+
"mean_by_type",
|
| 27 |
+
"median_by_type",
|
| 28 |
+
"kernel_mean_by_type",
|
| 29 |
+
"compose_mean_by_type",
|
| 30 |
+
}
|
| 31 |
_FIELD_CONDITIONED_RESIDUAL_REDUCERS = {"field_softmax"}
|
| 32 |
_RESIDUAL_REDUCERS = (
|
| 33 |
{"none"} | _NUMPY_RESIDUAL_REDUCERS | _FIELD_CONDITIONED_RESIDUAL_REDUCERS
|
|
|
|
| 199 |
if retrieval_residual_reduce not in _RESIDUAL_REDUCERS:
|
| 200 |
raise ValueError(
|
| 201 |
"retrieval_residual_reduce must be 'none', 'mean_by_type', "
|
| 202 |
+
"'median_by_type', 'kernel_mean_by_type', 'compose_mean_by_type', "
|
| 203 |
+
"or 'field_softmax'"
|
| 204 |
)
|
| 205 |
if not 0.0 <= retrieval_type_min_success <= 1.0:
|
| 206 |
raise ValueError("retrieval_type_min_success must be in [0, 1]")
|
|
|
|
| 826 |
) -> tuple[list[list[list[float]]], list[str]] | tuple[
|
| 827 |
list[list[list[float]]], list[str], list[float]
|
| 828 |
]:
|
| 829 |
+
if mode not in {
|
| 830 |
+
"mean_by_type",
|
| 831 |
+
"median_by_type",
|
| 832 |
+
"kernel_mean_by_type",
|
| 833 |
+
"compose_mean_by_type",
|
| 834 |
+
}:
|
| 835 |
raise ValueError(
|
| 836 |
+
"mode must be 'mean_by_type', 'median_by_type', 'kernel_mean_by_type', "
|
| 837 |
+
"or 'compose_mean_by_type'"
|
| 838 |
)
|
| 839 |
if len(residuals) != len(candidate_types):
|
| 840 |
raise ValueError("residuals and candidate_types must have the same length")
|
|
|
|
| 864 |
if not values:
|
| 865 |
continue
|
| 866 |
stack = np.stack(values, axis=0)
|
| 867 |
+
if mode in {"mean_by_type", "compose_mean_by_type"}:
|
| 868 |
reduced = np.mean(stack, axis=0)
|
| 869 |
reduced_bonus = float(np.mean(value_bonuses)) if value_bonuses else 0.0
|
| 870 |
elif mode == "kernel_mean_by_type":
|
|
|
|
| 899 |
reduced_residuals.append(reduced.astype(np.float32).tolist())
|
| 900 |
reduced_types.append(candidate_type)
|
| 901 |
reduced_bonuses.append(reduced_bonus)
|
| 902 |
+
if mode == "compose_mean_by_type":
|
| 903 |
+
base_count = len(reduced_residuals)
|
| 904 |
+
for left_index in range(base_count):
|
| 905 |
+
left_type = reduced_types[left_index]
|
| 906 |
+
if left_type == "policy_residual":
|
| 907 |
+
continue
|
| 908 |
+
left = np.asarray(reduced_residuals[left_index], dtype=np.float32)
|
| 909 |
+
for right_index in range(left_index + 1, base_count):
|
| 910 |
+
right_type = reduced_types[right_index]
|
| 911 |
+
if right_type == "policy_residual":
|
| 912 |
+
continue
|
| 913 |
+
right = np.asarray(reduced_residuals[right_index], dtype=np.float32)
|
| 914 |
+
reduced_residuals.append((left + right).astype(np.float32).tolist())
|
| 915 |
+
reduced_types.append(f"{left_type}+{right_type}")
|
| 916 |
+
reduced_bonuses.append(
|
| 917 |
+
0.5 * (reduced_bonuses[left_index] + reduced_bonuses[right_index])
|
| 918 |
+
)
|
| 919 |
if bonuses is None:
|
| 920 |
return reduced_residuals, reduced_types
|
| 921 |
return reduced_residuals, reduced_types, reduced_bonuses
|