keypa commited on
Commit
15fb079
·
verified ·
1 Parent(s): ddbb504

Upload build_agentic_images.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. build_agentic_images.py +29 -6
build_agentic_images.py CHANGED
@@ -97,16 +97,25 @@ def _url_to_relpath(url):
97
  return m.group(1) if m else url
98
 
99
 
100
- def local_parquet_shards(dataset, needed_max_idx, counts):
101
- """Download (resume-safe, CDN-cached) the leading shards covering needed_max_idx."""
102
- n = shards_covering(counts, needed_max_idx)
103
- urls = get_parquet_shard_urls(dataset)[:n]
 
 
 
 
 
 
 
104
  paths = []
105
- for u in urls:
106
  rel = _url_to_relpath(u)
 
107
  p = hf_hub_download(repo_id=dataset, repo_type="dataset",
108
  filename=rel, revision="refs/convert/parquet")
109
  paths.append(p)
 
110
  return paths
111
 
112
 
@@ -169,7 +178,21 @@ def aguvis_manifest_path(name):
169
 
170
 
171
  def load_aguvis_manifest(name):
172
- with open(aguvis_manifest_path(name)) as f:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  return json.load(f)
174
 
175
 
 
97
  return m.group(1) if m else url
98
 
99
 
100
+ def local_parquet_shards(dataset, needed_max_idx, counts=None):
101
+ """Resume-safe, CDN-cached download of the shards covering needed_max_idx.
102
+
103
+ `counts` is ignored on purpose (kept for call-site compatibility); we always
104
+ ask HF for the full shard path set and let hf_hub_download's cache do the work.
105
+ """
106
+ if counts is None:
107
+ counts = [None] # placeholder; hf_hub_download does not need row counts
108
+ n = shards_covering(counts, needed_max_idx) if counts[0] is not None else None
109
+ urls = get_parquet_shard_urls(dataset)
110
+ urls = urls[:n] if n else urls
111
  paths = []
112
+ for i, u in enumerate(urls):
113
  rel = _url_to_relpath(u)
114
+ # idempotent: re-uses the global HF hub cache
115
  p = hf_hub_download(repo_id=dataset, repo_type="dataset",
116
  filename=rel, revision="refs/convert/parquet")
117
  paths.append(p)
118
+ print(f" [dl] {dataset} shard {i+1}/{len(urls)} -> {os.path.basename(p)}")
119
  return paths
120
 
121
 
 
178
 
179
 
180
  def load_aguvis_manifest(name):
181
+ """Load the per-subset manifest. Falls back to fetching from HF Hub if missing."""
182
+ path = aguvis_manifest_path(name)
183
+ if not os.path.exists(path):
184
+ os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
185
+ print(f" [aguvis] {name}-l1.json not on disk; fetching from HF hub ...")
186
+ fetched = hf_hub_download(
187
+ repo_id="xlangai/aguvis-stage2",
188
+ repo_type="dataset",
189
+ filename=f"{name}-l1.json",
190
+ local_files_only=False,
191
+ )
192
+ # Copy into the expected local path so reruns are instant and idempotent
193
+ import shutil
194
+ shutil.copyfile(fetched, path)
195
+ with open(path) as f:
196
  return json.load(f)
197
 
198