Spaces:
Sleeping
Sleeping
PERDYPTO commited on
Update pipeline.py
Browse files- pipeline.py +51 -14
pipeline.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
# PIPELINE_API.PY — COORDINATOR‑WORKER PIPELINE (FINAL)
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
-
import
|
| 7 |
import sys
|
| 8 |
import json
|
| 9 |
import time
|
|
@@ -58,20 +58,20 @@ REMOTE_STATE = f"{REMOTE_ROOT}/state"
|
|
| 58 |
REMOTE_FINAL = f"{REMOTE_ROOT}/final"
|
| 59 |
|
| 60 |
# ----------------------------------------------------------------------
|
| 61 |
-
# DATASETS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# ----------------------------------------------------------------------
|
| 63 |
DATASETS = [
|
| 64 |
-
{
|
| 65 |
-
"name": "swallowcode_v2",
|
| 66 |
-
"dataset": "tokyotech-llm/swallow-code-v2",
|
| 67 |
-
"config": "swallowcode-v2",
|
| 68 |
-
"split": "train",
|
| 69 |
-
"kind": "generic",
|
| 70 |
-
"text_fields": ["text", "content", "code"],
|
| 71 |
-
"repo_fields": ["repo_name", "repo"],
|
| 72 |
-
"path_fields": ["path", "filepath"],
|
| 73 |
-
"license_fields": ["license"],
|
| 74 |
-
},
|
| 75 |
{
|
| 76 |
"name": "the_stack_dedup_python",
|
| 77 |
"dataset": "bigcode/the-stack-dedup",
|
|
@@ -418,6 +418,43 @@ def load_stream(cfg):
|
|
| 418 |
# extract_record will pull only the fields we need from each row.
|
| 419 |
return load_dataset(cfg["dataset"], **kwargs)
|
| 420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
# ----------------------------------------------------------------------
|
| 422 |
# WORKER FUNCTION
|
| 423 |
# ----------------------------------------------------------------------
|
|
@@ -451,7 +488,7 @@ def worker_task(cfg, task_id, total_tasks, interpreters, result_queue):
|
|
| 451 |
result_queue.put(("accepted_batch", batch, stats.copy()))
|
| 452 |
batch.clear()
|
| 453 |
|
| 454 |
-
for row in ds:
|
| 455 |
stats["processed"] += 1
|
| 456 |
|
| 457 |
try:
|
|
|
|
| 3 |
# PIPELINE_API.PY — COORDINATOR‑WORKER PIPELINE (FINAL)
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
import sys
|
| 8 |
import json
|
| 9 |
import time
|
|
|
|
| 58 |
REMOTE_FINAL = f"{REMOTE_ROOT}/final"
|
| 59 |
|
| 60 |
# ----------------------------------------------------------------------
|
| 61 |
+
# DATASETS
|
| 62 |
+
# swallowcode_v2 has been removed: its JSON shards contain a sparse
|
| 63 |
+
# error-reporting column (struct<type: string, message: string>) that
|
| 64 |
+
# is null in the first batches datasets' streaming JSON reader samples
|
| 65 |
+
# for schema inference, then populated with real struct data in later
|
| 66 |
+
# batches. Arrow can't cast a struct into a column it already committed
|
| 67 |
+
# to typing as null, so the whole shard iterator crashes with:
|
| 68 |
+
# TypeError: Couldn't cast array of type struct<type: string, message: string> to null
|
| 69 |
+
# This killed both worker processes immediately on startup and hung
|
| 70 |
+
# the coordinator forever since no task_done ever arrived for those
|
| 71 |
+
# tasks. Rather than patch around a dataset with an unstable schema,
|
| 72 |
+
# it has been dropped from the pool entirely.
|
| 73 |
# ----------------------------------------------------------------------
|
| 74 |
DATASETS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
{
|
| 76 |
"name": "the_stack_dedup_python",
|
| 77 |
"dataset": "bigcode/the-stack-dedup",
|
|
|
|
| 418 |
# extract_record will pull only the fields we need from each row.
|
| 419 |
return load_dataset(cfg["dataset"], **kwargs)
|
| 420 |
|
| 421 |
+
# ----------------------------------------------------------------------
|
| 422 |
+
# RESILIENT ROW ITERATION — schema-mismatch-safe
|
| 423 |
+
# ----------------------------------------------------------------------
|
| 424 |
+
def safe_row_iter(ds, dataset_name, task_id, stats):
|
| 425 |
+
"""
|
| 426 |
+
datasets' streaming JSON reader infers an Arrow schema from the first
|
| 427 |
+
batch it samples. If a column is all-null in that batch but a later
|
| 428 |
+
batch has real (e.g. struct) data in that same column, Arrow raises
|
| 429 |
+
TypeError and kills the whole iterator — which previously took the
|
| 430 |
+
entire worker process down with it, and hung the coordinator forever
|
| 431 |
+
since no task_done ever arrived.
|
| 432 |
+
|
| 433 |
+
We can't fix the source dataset's schema from here, but we can stop
|
| 434 |
+
a single bad batch from killing the process: iterate manually with
|
| 435 |
+
next() instead of a for-loop (a for-loop can't recover from an
|
| 436 |
+
exception raised mid-iteration), catch the error, log it, and treat
|
| 437 |
+
the rest of this shard as exhausted rather than crash.
|
| 438 |
+
"""
|
| 439 |
+
it = iter(ds)
|
| 440 |
+
while True:
|
| 441 |
+
try:
|
| 442 |
+
row = next(it)
|
| 443 |
+
except StopIteration:
|
| 444 |
+
return
|
| 445 |
+
except TypeError as e:
|
| 446 |
+
# Arrow schema-cast failure inside datasets' JSON backend.
|
| 447 |
+
stats["other_reject"] += 1
|
| 448 |
+
print(f"[WARN] {dataset_name} T{task_id} schema-cast error, "
|
| 449 |
+
f"stopping this shard early: {e}")
|
| 450 |
+
return
|
| 451 |
+
except Exception as e:
|
| 452 |
+
stats["other_reject"] += 1
|
| 453 |
+
print(f"[WARN] {dataset_name} T{task_id} row iteration error: {e}")
|
| 454 |
+
return
|
| 455 |
+
else:
|
| 456 |
+
yield row
|
| 457 |
+
|
| 458 |
# ----------------------------------------------------------------------
|
| 459 |
# WORKER FUNCTION
|
| 460 |
# ----------------------------------------------------------------------
|
|
|
|
| 488 |
result_queue.put(("accepted_batch", batch, stats.copy()))
|
| 489 |
batch.clear()
|
| 490 |
|
| 491 |
+
for row in safe_row_iter(ds, dataset_name, task_id, stats):
|
| 492 |
stats["processed"] += 1
|
| 493 |
|
| 494 |
try:
|