anhtld commited on
Commit
e77b98d
·
verified ·
1 Parent(s): afca915

auto-sync 2026-07-03T15:40:37Z workspace

Browse files
workspace/cil/chart_features.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import hashlib
 
4
  from typing import Any
5
 
6
  try:
@@ -10,7 +11,9 @@ except ImportError: # pragma: no cover
10
 
11
 
12
  CONTEXT_HASH_WIDTH = 8
13
- CHART_FEATURE_MODES = ("base", "base_context")
 
 
14
 
15
 
16
  def build_chart_feature(
@@ -23,8 +26,10 @@ def build_chart_feature(
23
 
24
  `base` preserves the original behavior: the chart token is the flattened
25
  base action chunk. `base_context` appends stable hashes of task/language
26
- metadata that are visible at proposal time. It intentionally does not read
27
- outcomes, labels, hidden chart branches, or evaluator-only fields.
 
 
28
  """
29
 
30
  if np is None: # pragma: no cover
@@ -44,6 +49,12 @@ def build_chart_feature(
44
  ],
45
  dtype=np.float32,
46
  )
 
 
 
 
 
 
47
  return np.concatenate([base, context]).astype(np.float32, copy=False)
48
 
49
 
@@ -54,3 +65,36 @@ def chart_feature_dim(base_action: Any, *, mode: str = "base") -> int:
54
  def _stable_hash_features(text: str, width: int) -> list[float]:
55
  digest = hashlib.sha256(text.encode("utf-8")).digest()
56
  return [float(digest[index] / 127.5 - 1.0) for index in range(width)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
2
 
3
  import hashlib
4
+ from pathlib import Path
5
  from typing import Any
6
 
7
  try:
 
11
 
12
 
13
  CONTEXT_HASH_WIDTH = 8
14
+ OBSERVATION_EMBED_DIM = 32
15
+ CHART_FEATURE_MODES = ("base", "base_context", "base_context_obs")
16
+ _EMBEDDING_CACHE: dict[str, Any] = {}
17
 
18
 
19
  def build_chart_feature(
 
26
 
27
  `base` preserves the original behavior: the chart token is the flattened
28
  base action chunk. `base_context` appends stable hashes of task/language
29
+ metadata that are visible at proposal time. `base_context_obs` additionally
30
+ appends a precomputed observation embedding referenced by metadata. These
31
+ modes intentionally do not read outcomes, labels, hidden chart branches, or
32
+ evaluator-only fields.
33
  """
34
 
35
  if np is None: # pragma: no cover
 
49
  ],
50
  dtype=np.float32,
51
  )
52
+ if mode == "base_context_obs":
53
+ obs = _load_observation_embedding(
54
+ metadata.get("observation_embedding_path"),
55
+ chart_root=metadata.get("_chart_root"),
56
+ )
57
+ context = np.concatenate([context, obs.astype(np.float32, copy=False)])
58
  return np.concatenate([base, context]).astype(np.float32, copy=False)
59
 
60
 
 
65
  def _stable_hash_features(text: str, width: int) -> list[float]:
66
  digest = hashlib.sha256(text.encode("utf-8")).digest()
67
  return [float(digest[index] / 127.5 - 1.0) for index in range(width)]
68
+
69
+
70
+ def _load_observation_embedding(value: Any, *, chart_root: Any = None) -> Any:
71
+ if np is None: # pragma: no cover
72
+ raise ImportError("build_chart_feature requires numpy")
73
+ if not value:
74
+ return np.zeros(OBSERVATION_EMBED_DIM, dtype=np.float32)
75
+ path_text, dataset, row_index = _parse_embedding_ref(str(value))
76
+ path = Path(path_text)
77
+ if not path.is_absolute() and chart_root:
78
+ path = Path(str(chart_root)) / path
79
+ cache_key = str(path.resolve())
80
+ if cache_key not in _EMBEDDING_CACHE:
81
+ with np.load(path, allow_pickle=False) as data:
82
+ _EMBEDDING_CACHE[cache_key] = np.asarray(data[dataset], dtype=np.float32)
83
+ matrix = _EMBEDDING_CACHE[cache_key]
84
+ vector = np.asarray(matrix[int(row_index)], dtype=np.float32).reshape(-1)
85
+ if vector.shape[0] == OBSERVATION_EMBED_DIM:
86
+ return vector
87
+ output = np.zeros(OBSERVATION_EMBED_DIM, dtype=np.float32)
88
+ width = min(OBSERVATION_EMBED_DIM, vector.shape[0])
89
+ output[:width] = vector[:width]
90
+ return output
91
+
92
+
93
+ def _parse_embedding_ref(value: str) -> tuple[str, str, int]:
94
+ if "#" not in value:
95
+ return value, "embeddings", 0
96
+ path_text, ref = value.split("#", 1)
97
+ parts = [part for part in ref.split("/") if part]
98
+ if len(parts) != 2:
99
+ raise ValueError(f"invalid observation embedding ref: {value}")
100
+ return path_text, parts[0], int(parts[1])
workspace/data/cil_charts_rgb_refs/test/charts_00000.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e1dab883a6d5ccf9fab9111d291de115a0fc4de77487bc7a740c207adb62e74e
3
  size 6138612
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2145c0ec6fd38abb9b128e973e18f7f3174d34fb4b0f5b1cebc9161cf98d4932
3
  size 6138612
workspace/data/cil_charts_rgb_refs/test/index.json CHANGED
@@ -15,10 +15,11 @@
15
  "wrong_direction": 410,
16
  "wrong_gripper": 410
17
  },
18
- "content_hash": "a249a4d627b8113988660be3aecd867ba1b7b8b8d00f66eb0e3070439a395554",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": false,
 
22
  "epsilon": 0.05,
23
  "format": "cil_charts_npz",
24
  "group_hashes": [
@@ -449,8 +450,19 @@
449
  "num_groups_scanned": 2873,
450
  "num_groups_skipped_by_split": 2463,
451
  "num_rows": 6560,
 
 
 
 
 
 
 
 
452
  "retrieval_index_allowed": false,
453
  "schema_version": 1,
 
 
 
454
  "shards": [
455
  {
456
  "num_rows": 6560,
 
15
  "wrong_direction": 410,
16
  "wrong_gripper": 410
17
  },
18
+ "content_hash": "d258ed27d587e6f41ef6ffd520832087fe7626b5e5cba2bd6352f50a1f45125a",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": false,
22
+ "embedding_content_hash": "981d3b1b0aa9dc962e5a22fd695fa9befd21e1334f23b8c3843591e8be89ef83",
23
  "epsilon": 0.05,
24
  "format": "cil_charts_npz",
25
  "group_hashes": [
 
450
  "num_groups_scanned": 2873,
451
  "num_groups_skipped_by_split": 2463,
452
  "num_rows": 6560,
453
+ "observation_embedding_manifest": {
454
+ "dataset": "embeddings",
455
+ "dim": 32,
456
+ "extractor": "rgb_jpeg_stats_v1",
457
+ "num_embeddings": 410,
458
+ "path": "observation_embeddings_rgb_stats.npz",
459
+ "reads_outcomes": false
460
+ },
461
  "retrieval_index_allowed": false,
462
  "schema_version": 1,
463
+ "shard_content_hashes": {
464
+ "charts_00000.npz": "2145c0ec6fd38abb9b128e973e18f7f3174d34fb4b0f5b1cebc9161cf98d4932"
465
+ },
466
  "shards": [
467
  {
468
  "num_rows": 6560,
workspace/data/cil_charts_rgb_refs/train/charts_00000.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6f3211ef91cac305045b540e71fa40156ee697abff9db3c8f994149a2fc1b663
3
  size 30561279
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a68210ead1392615bf3389335c89e41178957c7973440409dc9d820ebc9b422c
3
  size 30561279
workspace/data/cil_charts_rgb_refs/train/index.json CHANGED
@@ -15,10 +15,11 @@
15
  "wrong_direction": 2044,
16
  "wrong_gripper": 2044
17
  },
18
- "content_hash": "2cad4dbf330d10ecaeb4ed4e86ceb162850223d2d9618170b6800b1c73e3d531",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": true,
 
22
  "epsilon": 0.05,
23
  "format": "cil_charts_npz",
24
  "group_hashes": [
@@ -2083,8 +2084,19 @@
2083
  "num_groups_scanned": 2873,
2084
  "num_groups_skipped_by_split": 829,
2085
  "num_rows": 32704,
 
 
 
 
 
 
 
 
2086
  "retrieval_index_allowed": true,
2087
  "schema_version": 1,
 
 
 
2088
  "shards": [
2089
  {
2090
  "num_rows": 32704,
 
15
  "wrong_direction": 2044,
16
  "wrong_gripper": 2044
17
  },
18
+ "content_hash": "1d15143588697e89f7fc2f6375b2745e4d479c726c9a947ff7eb7b2705280e1a",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": true,
22
+ "embedding_content_hash": "00859bfac7590abb24a3e7cc4c26fbb17122ba52d9f63369b8bb71a6ad1bc302",
23
  "epsilon": 0.05,
24
  "format": "cil_charts_npz",
25
  "group_hashes": [
 
2084
  "num_groups_scanned": 2873,
2085
  "num_groups_skipped_by_split": 829,
2086
  "num_rows": 32704,
2087
+ "observation_embedding_manifest": {
2088
+ "dataset": "embeddings",
2089
+ "dim": 32,
2090
+ "extractor": "rgb_jpeg_stats_v1",
2091
+ "num_embeddings": 2044,
2092
+ "path": "observation_embeddings_rgb_stats.npz",
2093
+ "reads_outcomes": false
2094
+ },
2095
  "retrieval_index_allowed": true,
2096
  "schema_version": 1,
2097
+ "shard_content_hashes": {
2098
+ "charts_00000.npz": "a68210ead1392615bf3389335c89e41178957c7973440409dc9d820ebc9b422c"
2099
+ },
2100
  "shards": [
2101
  {
2102
  "num_rows": 32704,
workspace/data/cil_charts_rgb_refs/val/charts_00000.npz CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:538fac2468d1bde33b9e76f5233e331040a8c76ff5fd224727bd8140686f4071
3
  size 6273000
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4b8ec1d9d6619ef9c4563e1eb46ddedc253043d1dd9da29a82d6f773e6a0336
3
  size 6273000
workspace/data/cil_charts_rgb_refs/val/index.json CHANGED
@@ -15,10 +15,11 @@
15
  "wrong_direction": 419,
16
  "wrong_gripper": 419
17
  },
18
- "content_hash": "bad9b7241350f81c31e394e231d066a14138a61bb8e23a68e13e15eb5ac65d64",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": false,
 
22
  "epsilon": 0.05,
23
  "format": "cil_charts_npz",
24
  "group_hashes": [
@@ -458,8 +459,19 @@
458
  "num_groups_scanned": 2873,
459
  "num_groups_skipped_by_split": 2454,
460
  "num_rows": 6704,
 
 
 
 
 
 
 
 
461
  "retrieval_index_allowed": false,
462
  "schema_version": 1,
 
 
 
463
  "shards": [
464
  {
465
  "num_rows": 6704,
 
15
  "wrong_direction": 419,
16
  "wrong_gripper": 419
17
  },
18
+ "content_hash": "577761809f93f760fc7de6558a25d8085b2a0e51ca5d969680e99bcfa8586850",
19
  "dataset": "/scratch/knguy52/dovla/experiments/six_task_h16_collection",
20
  "deployment_candidate_excludes_expert": true,
21
  "deployment_clean": false,
22
+ "embedding_content_hash": "e4374b56912fdb6814eb0320518733d1602a90e0dd2f9268f65c8a148751f963",
23
  "epsilon": 0.05,
24
  "format": "cil_charts_npz",
25
  "group_hashes": [
 
459
  "num_groups_scanned": 2873,
460
  "num_groups_skipped_by_split": 2454,
461
  "num_rows": 6704,
462
+ "observation_embedding_manifest": {
463
+ "dataset": "embeddings",
464
+ "dim": 32,
465
+ "extractor": "rgb_jpeg_stats_v1",
466
+ "num_embeddings": 419,
467
+ "path": "observation_embeddings_rgb_stats.npz",
468
+ "reads_outcomes": false
469
+ },
470
  "retrieval_index_allowed": false,
471
  "schema_version": 1,
472
+ "shard_content_hashes": {
473
+ "charts_00000.npz": "d4b8ec1d9d6619ef9c4563e1eb46ddedc253043d1dd9da29a82d6f773e6a0336"
474
+ },
475
  "shards": [
476
  {
477
  "num_rows": 6704,