hmb HF Staff commited on
Commit
2882de4
·
verified ·
1 Parent(s): e9fb70e

Update validate_workflow_curated.py

Browse files
Files changed (1) hide show
  1. validate_workflow_curated.py +36 -20
validate_workflow_curated.py CHANGED
@@ -39,6 +39,12 @@ TASK_INPUT_TYPES: dict[str, list[str]] = {
39
  "translation": ["text"],
40
  "text-classification": ["text"],
41
  "question-answering": ["text"],
 
 
 
 
 
 
42
  "image-to-image": ["image"],
43
  "image-to-text": ["image"],
44
  "image-to-video": ["image"],
@@ -63,6 +69,12 @@ TASK_OUTPUT_TYPES: dict[str, list[str]] = {
63
  "translation": ["text"],
64
  "text-classification": ["json"],
65
  "question-answering": ["text"],
 
 
 
 
 
 
66
  "image-to-image": ["image"],
67
  "image-to-text": ["text"],
68
  "image-to-video": ["video"],
@@ -168,7 +180,9 @@ def schema_cross_check(ep: dict, task: str) -> Optional[str]:
168
  def default_smoke_inputs(task: str) -> list[Any]:
169
  if task in ("text-to-image", "text-to-video", "text-to-3d", "text-to-speech", "text-to-audio"):
170
  return ["a small red square"]
171
- if task in ("text-generation", "summarization", "translation", "text-classification", "question-answering"):
 
 
172
  return ["hello world"]
173
  if task in ("image-to-image", "image-to-text", "image-to-video", "image-to-3d",
174
  "image-classification", "image-segmentation", "object-detection",
@@ -233,7 +247,6 @@ except Exception as e:
233
  if proc.returncode != 0:
234
  return False, proc.stderr.strip() or f"exit {proc.returncode}", latency
235
  return True, None, latency
236
- return True, None, int((time.monotonic() - started) * 1000)
237
 
238
 
239
  WAKE_POLL_INTERVAL = 10 # seconds between runtime polls
@@ -366,17 +379,24 @@ def validate_model(entry: dict, hf_token: Optional[str]) -> dict:
366
  def load_manifest(local_path: Optional[str], hf_token: Optional[str]) -> tuple[dict, str]:
367
  if local_path:
368
  with open(local_path, encoding="utf-8") as f:
369
- return json.load(f), local_path
370
- from huggingface_hub import hf_hub_download
 
 
 
 
 
 
 
 
 
 
371
 
372
- local = hf_hub_download(
373
- repo_id=CURATED_DATASET,
374
- filename=CURATED_FILENAME,
375
- repo_type="dataset",
376
- token=hf_token,
377
- )
378
- with open(local, encoding="utf-8") as f:
379
- return json.load(f), f"{CURATED_DATASET}/{CURATED_FILENAME}"
380
 
381
 
382
  def upload_manifest(payload: dict, hf_token: str) -> None:
@@ -432,9 +452,9 @@ def main() -> int:
432
  hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HF_JOBS_TOKEN")
433
 
434
  payload, src = load_manifest(args.source, hf_token)
435
- items = payload.get("items") if isinstance(payload, dict) else payload
436
  if not isinstance(items, list):
437
- logger.error("manifest at %s is malformed (no `items` array)", src)
438
  return 2
439
  if args.limit:
440
  items = items[: args.limit]
@@ -476,18 +496,14 @@ def main() -> int:
476
  order = {e.get("id", ""): i for i, e in enumerate(items)}
477
  new_items.sort(key=lambda e: order.get(e.get("id", ""), len(items)))
478
 
479
- out_payload = (
480
- {**payload, "items": new_items, "fetched_at": now_iso()}
481
- if isinstance(payload, dict)
482
- else new_items
483
- )
484
-
485
  statuses: dict[str, int] = {}
486
  for e in new_items:
487
  s = (e.get("validation") or {}).get("status", "unknown")
488
  statuses[s] = statuses.get(s, 0) + 1
489
  logger.info("results: %s", statuses)
490
 
 
 
491
  if args.dry_run:
492
  json.dump(out_payload, sys.stdout, indent=2)
493
  sys.stdout.write("\n")
 
39
  "translation": ["text"],
40
  "text-classification": ["text"],
41
  "question-answering": ["text"],
42
+ "zero-shot-classification": ["text"],
43
+ "token-classification": ["text"],
44
+ "fill-mask": ["text"],
45
+ "visual-question-answering": ["image"],
46
+ "feature-extraction": ["text"],
47
+ "image-text-to-text": ["image"],
48
  "image-to-image": ["image"],
49
  "image-to-text": ["image"],
50
  "image-to-video": ["image"],
 
69
  "translation": ["text"],
70
  "text-classification": ["json"],
71
  "question-answering": ["text"],
72
+ "zero-shot-classification": ["json"],
73
+ "token-classification": ["json"],
74
+ "fill-mask": ["json"],
75
+ "visual-question-answering": ["text"],
76
+ "feature-extraction": ["json"],
77
+ "image-text-to-text": ["text"],
78
  "image-to-image": ["image"],
79
  "image-to-text": ["text"],
80
  "image-to-video": ["video"],
 
180
  def default_smoke_inputs(task: str) -> list[Any]:
181
  if task in ("text-to-image", "text-to-video", "text-to-3d", "text-to-speech", "text-to-audio"):
182
  return ["a small red square"]
183
+ if task in ("text-generation", "summarization", "translation", "text-classification",
184
+ "question-answering", "feature-extraction", "zero-shot-classification",
185
+ "token-classification", "fill-mask"):
186
  return ["hello world"]
187
  if task in ("image-to-image", "image-to-text", "image-to-video", "image-to-3d",
188
  "image-classification", "image-segmentation", "object-detection",
 
247
  if proc.returncode != 0:
248
  return False, proc.stderr.strip() or f"exit {proc.returncode}", latency
249
  return True, None, latency
 
250
 
251
 
252
  WAKE_POLL_INTERVAL = 10 # seconds between runtime polls
 
379
  def load_manifest(local_path: Optional[str], hf_token: Optional[str]) -> tuple[dict, str]:
380
  if local_path:
381
  with open(local_path, encoding="utf-8") as f:
382
+ data = json.load(f)
383
+ else:
384
+ from huggingface_hub import hf_hub_download
385
+
386
+ local = hf_hub_download(
387
+ repo_id=CURATED_DATASET,
388
+ filename=CURATED_FILENAME,
389
+ repo_type="dataset",
390
+ token=hf_token,
391
+ )
392
+ with open(local, encoding="utf-8") as f:
393
+ data = json.load(f)
394
 
395
+ # tolerate a bare-array manifest by wrapping it back up
396
+ if isinstance(data, list):
397
+ data = {"snapshot_version": 1, "items": data}
398
+ src = local_path or f"{CURATED_DATASET}/{CURATED_FILENAME}"
399
+ return data, src
 
 
 
400
 
401
 
402
  def upload_manifest(payload: dict, hf_token: str) -> None:
 
452
  hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HF_JOBS_TOKEN")
453
 
454
  payload, src = load_manifest(args.source, hf_token)
455
+ items = payload.get("items")
456
  if not isinstance(items, list):
457
+ logger.error("manifest at %s is malformed (no items array)", src)
458
  return 2
459
  if args.limit:
460
  items = items[: args.limit]
 
496
  order = {e.get("id", ""): i for i, e in enumerate(items)}
497
  new_items.sort(key=lambda e: order.get(e.get("id", ""), len(items)))
498
 
 
 
 
 
 
 
499
  statuses: dict[str, int] = {}
500
  for e in new_items:
501
  s = (e.get("validation") or {}).get("status", "unknown")
502
  statuses[s] = statuses.get(s, 0) + 1
503
  logger.info("results: %s", statuses)
504
 
505
+ out_payload = {**payload, "items": new_items, "fetched_at": now_iso()}
506
+
507
  if args.dry_run:
508
  json.dump(out_payload, sys.stdout, indent=2)
509
  sys.stdout.write("\n")