Fix pipeline bugs and sync cluster code changes
Browse files- pipeline02: fix ffprobe multi-stream parsing (int() crash on '1080\n\n1920x1080');
integrate processed_complete counter increment on successful processing
- pipeline03: fix cleanup_local_assets() missing stats_npz argument (caused every
upload to exit with RuntimeError after successful upload); add counter decrement
on local cleanup
- runtime_status.py: guard du -sb behind --scan-runtime-size flag (was blocking
unconditionally); add fast_count_complete(), --scan-csv and --scan-complete flags
- reproduce_independently_slurm.sh: add run_upload_drain_stage() and upload
configuration vars (UPLOAD_PARALLEL_SHARDS, UPLOAD_PARTITION, etc.)
- utils/dataset_pool.py: prefer scratch over home when scratch has .complete marker;
better conflict resolution for duplicate video dirs across home/scratch
- utils/stats_npz.py: add adjust_processed_complete_counter(),
processed_complete_counter_path(), read_processed_complete_counter()
- reproduce_independently_slurm.sh +27 -6
- scripts/pipeline02_extract_dwpose_from_video.py +17 -5
- scripts/pipeline03_upload_to_huggingface.py +17 -2
- scripts/runtime_status.py +38 -4
- utils/dataset_pool.py +15 -5
- utils/stats_npz.py +42 -0
|
@@ -30,6 +30,7 @@ PIPELINE01="${PIPELINE01:-$ROOT_DIR/scripts/pipeline01_download_video_fix_captio
|
|
| 30 |
PIPELINE02="${PIPELINE02:-$ROOT_DIR/scripts/pipeline02_extract_dwpose_from_video.py}"
|
| 31 |
PIPELINE03="${PIPELINE03:-$ROOT_DIR/scripts/pipeline03_upload_to_huggingface.py}"
|
| 32 |
PIPELINE_SYNC="${PIPELINE_SYNC:-$ROOT_DIR/scripts/sync_processed_csv_from_runtime.py}"
|
|
|
|
| 33 |
|
| 34 |
STAGE="${STAGE:-all}"
|
| 35 |
LIMIT="${LIMIT:-}"
|
|
@@ -38,6 +39,11 @@ FPS="${FPS:-24}"
|
|
| 38 |
WORKERS="${WORKERS:-}"
|
| 39 |
TARGET_BYTES="${TARGET_BYTES:-$((10 * 1024 * 1024 * 1024))}"
|
| 40 |
TARGET_FOLDERS="${TARGET_FOLDERS:-40}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
DOWNLOAD_BATCH_SIZE="${DOWNLOAD_BATCH_SIZE:-1}"
|
| 42 |
DOWNLOAD_WORKERS="${DOWNLOAD_WORKERS:-60}"
|
| 43 |
USE_SLURM_DOWNLOAD="${USE_SLURM_DOWNLOAD:-1}"
|
|
@@ -616,6 +622,25 @@ run_upload_stage() {
|
|
| 616 |
run_in_dwpose "${cmd[@]}"
|
| 617 |
}
|
| 618 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
prune_processed_raw_videos() {
|
| 620 |
python - <<PY
|
| 621 |
from pathlib import Path
|
|
@@ -1421,12 +1446,8 @@ upload_loop() {
|
|
| 1421 |
continue
|
| 1422 |
fi
|
| 1423 |
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
require_target=0
|
| 1427 |
-
fi
|
| 1428 |
-
if ! run_upload_stage "$require_target"; then
|
| 1429 |
-
echo "[upload] pipeline03 failed; retry after sleep"
|
| 1430 |
sleep "$IDLE_SLEEP_SECONDS"
|
| 1431 |
else
|
| 1432 |
run_sync_csv_stage >/dev/null 2>&1 || true
|
|
|
|
| 30 |
PIPELINE02="${PIPELINE02:-$ROOT_DIR/scripts/pipeline02_extract_dwpose_from_video.py}"
|
| 31 |
PIPELINE03="${PIPELINE03:-$ROOT_DIR/scripts/pipeline03_upload_to_huggingface.py}"
|
| 32 |
PIPELINE_SYNC="${PIPELINE_SYNC:-$ROOT_DIR/scripts/sync_processed_csv_from_runtime.py}"
|
| 33 |
+
UPLOAD_DRAIN_SCRIPT="${UPLOAD_DRAIN_SCRIPT:-$ROOT_DIR/slurm/submit_upload_parallel_drain.sh}"
|
| 34 |
|
| 35 |
STAGE="${STAGE:-all}"
|
| 36 |
LIMIT="${LIMIT:-}"
|
|
|
|
| 39 |
WORKERS="${WORKERS:-}"
|
| 40 |
TARGET_BYTES="${TARGET_BYTES:-$((10 * 1024 * 1024 * 1024))}"
|
| 41 |
TARGET_FOLDERS="${TARGET_FOLDERS:-40}"
|
| 42 |
+
UPLOAD_PARALLEL_SHARDS="${UPLOAD_PARALLEL_SHARDS:-8}"
|
| 43 |
+
UPLOAD_ARRAY_PARALLEL="${UPLOAD_ARRAY_PARALLEL:-8}"
|
| 44 |
+
UPLOAD_PARTITION="${UPLOAD_PARTITION:-main}"
|
| 45 |
+
UPLOAD_START_STAGGER_MIN="${UPLOAD_START_STAGGER_MIN:-1}"
|
| 46 |
+
UPLOAD_START_STAGGER_MAX="${UPLOAD_START_STAGGER_MAX:-3}"
|
| 47 |
DOWNLOAD_BATCH_SIZE="${DOWNLOAD_BATCH_SIZE:-1}"
|
| 48 |
DOWNLOAD_WORKERS="${DOWNLOAD_WORKERS:-60}"
|
| 49 |
USE_SLURM_DOWNLOAD="${USE_SLURM_DOWNLOAD:-1}"
|
|
|
|
| 622 |
run_in_dwpose "${cmd[@]}"
|
| 623 |
}
|
| 624 |
|
| 625 |
+
run_upload_drain_stage() {
|
| 626 |
+
local cmd=(
|
| 627 |
+
env
|
| 628 |
+
ROOT_DIR="$ROOT_DIR"
|
| 629 |
+
RUNTIME_ROOT="$RUNTIME_ROOT"
|
| 630 |
+
TARGET_BYTES="$TARGET_BYTES"
|
| 631 |
+
TARGET_FOLDERS="$TARGET_FOLDERS"
|
| 632 |
+
PARALLEL_SHARDS="$UPLOAD_PARALLEL_SHARDS"
|
| 633 |
+
ARRAY_PARALLEL="$UPLOAD_ARRAY_PARALLEL"
|
| 634 |
+
PARTITION="$UPLOAD_PARTITION"
|
| 635 |
+
START_STAGGER_MIN="$UPLOAD_START_STAGGER_MIN"
|
| 636 |
+
START_STAGGER_MAX="$UPLOAD_START_STAGGER_MAX"
|
| 637 |
+
REPO_ID="$REPO_ID"
|
| 638 |
+
REPO_REVISION="$REPO_REVISION"
|
| 639 |
+
bash "$UPLOAD_DRAIN_SCRIPT"
|
| 640 |
+
)
|
| 641 |
+
run_in_dwpose "${cmd[@]}"
|
| 642 |
+
}
|
| 643 |
+
|
| 644 |
prune_processed_raw_videos() {
|
| 645 |
python - <<PY
|
| 646 |
from pathlib import Path
|
|
|
|
| 1446 |
continue
|
| 1447 |
fi
|
| 1448 |
|
| 1449 |
+
if ! run_upload_drain_stage; then
|
| 1450 |
+
echo "[upload] upload drain failed; retry after sleep"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1451 |
sleep "$IDLE_SLEEP_SECONDS"
|
| 1452 |
else
|
| 1453 |
run_sync_csv_stage >/dev/null 2>&1 || true
|
|
@@ -29,7 +29,12 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
| 29 |
if str(REPO_ROOT) not in sys.path:
|
| 30 |
sys.path.insert(0, str(REPO_ROOT))
|
| 31 |
|
| 32 |
-
from utils.stats_npz import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
from utils.raw_video_pool import iter_raw_video_files
|
| 34 |
from utils.dataset_pool import dataset_dir_for_video, find_dataset_video_dir
|
| 35 |
|
|
@@ -250,9 +255,11 @@ def probe_video_dimensions(video_path: Path) -> Tuple[int, int]:
|
|
| 250 |
str(video_path),
|
| 251 |
]
|
| 252 |
proc = subprocess.run(command, check=True, capture_output=True, text=True)
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
| 256 |
width_s, height_s = dims.split("x", 1)
|
| 257 |
return int(width_s), int(height_s)
|
| 258 |
|
|
@@ -588,13 +595,15 @@ def process_video(
|
|
| 588 |
optimized_frame_batch_size: int,
|
| 589 |
optimized_detect_resolution: int,
|
| 590 |
optimized_frame_stride: int,
|
|
|
|
| 591 |
) -> None:
|
| 592 |
video_id = video_path.stem
|
| 593 |
output_dataset_dir = dataset_dir_for_video(video_path, raw_video_dir, scratch_raw_video_dir, dataset_dir, scratch_dataset_dir)
|
| 594 |
output_npz_dir = output_dataset_dir / video_id / "npz"
|
| 595 |
complete_marker = output_npz_dir / COMPLETE_MARKER_NAME
|
|
|
|
| 596 |
poses_npz_path = output_npz_dir / "poses.npz"
|
| 597 |
-
if output_npz_dir.exists() and
|
| 598 |
print(f"Skip {video_id}: NPZ files already exist")
|
| 599 |
return
|
| 600 |
|
|
@@ -716,6 +725,8 @@ def process_video(
|
|
| 716 |
f"video_id={video_id}\nfps={fps}\nframes={total_frames}\noutput_mode={'single_poses_npy' if single_poses_npz else 'per_frame_npz'}\ndecode_mode={'stream' if stream_frames else 'jpg-spill'}\noptimized_mode={optimized_mode}\noptimized_detect_resolution={optimized_detect_resolution}\noptimized_frame_stride={optimized_frame_stride}\ncompleted_at={time.strftime('%Y-%m-%d %H:%M:%S')}\n",
|
| 717 |
encoding="utf-8",
|
| 718 |
)
|
|
|
|
|
|
|
| 719 |
|
| 720 |
|
| 721 |
def worker(rank: int, worker_count: int, video_paths: Sequence[Path], args: argparse.Namespace) -> None:
|
|
@@ -769,6 +780,7 @@ def worker(rank: int, worker_count: int, video_paths: Sequence[Path], args: argp
|
|
| 769 |
optimized_frame_batch_size=args.optimized_frame_batch_size,
|
| 770 |
optimized_detect_resolution=args.optimized_detect_resolution,
|
| 771 |
optimized_frame_stride=args.optimized_frame_stride,
|
|
|
|
| 772 |
)
|
| 773 |
update_video_stats_best_effort(
|
| 774 |
args.stats_npz,
|
|
|
|
| 29 |
if str(REPO_ROOT) not in sys.path:
|
| 30 |
sys.path.insert(0, str(REPO_ROOT))
|
| 31 |
|
| 32 |
+
from utils.stats_npz import (
|
| 33 |
+
adjust_processed_complete_counter,
|
| 34 |
+
load_stats,
|
| 35 |
+
processed_complete_counter_path,
|
| 36 |
+
update_video_stats_best_effort,
|
| 37 |
+
)
|
| 38 |
from utils.raw_video_pool import iter_raw_video_files
|
| 39 |
from utils.dataset_pool import dataset_dir_for_video, find_dataset_video_dir
|
| 40 |
|
|
|
|
| 255 |
str(video_path),
|
| 256 |
]
|
| 257 |
proc = subprocess.run(command, check=True, capture_output=True, text=True)
|
| 258 |
+
raw = proc.stdout or ""
|
| 259 |
+
# ffprobe may emit multiple lines for videos with multiple streams; take the first valid one
|
| 260 |
+
dims = next((line.strip() for line in raw.splitlines() if "x" in line.strip()), "").strip()
|
| 261 |
+
if not dims or "x" not in dims:
|
| 262 |
+
raise RuntimeError(f"Unable to parse ffprobe dimensions for {video_path.name}: {raw!r}")
|
| 263 |
width_s, height_s = dims.split("x", 1)
|
| 264 |
return int(width_s), int(height_s)
|
| 265 |
|
|
|
|
| 595 |
optimized_frame_batch_size: int,
|
| 596 |
optimized_detect_resolution: int,
|
| 597 |
optimized_frame_stride: int,
|
| 598 |
+
stats_npz: Path,
|
| 599 |
) -> None:
|
| 600 |
video_id = video_path.stem
|
| 601 |
output_dataset_dir = dataset_dir_for_video(video_path, raw_video_dir, scratch_raw_video_dir, dataset_dir, scratch_dataset_dir)
|
| 602 |
output_npz_dir = output_dataset_dir / video_id / "npz"
|
| 603 |
complete_marker = output_npz_dir / COMPLETE_MARKER_NAME
|
| 604 |
+
was_complete = complete_marker.exists()
|
| 605 |
poses_npz_path = output_npz_dir / "poses.npz"
|
| 606 |
+
if output_npz_dir.exists() and was_complete and not force:
|
| 607 |
print(f"Skip {video_id}: NPZ files already exist")
|
| 608 |
return
|
| 609 |
|
|
|
|
| 725 |
f"video_id={video_id}\nfps={fps}\nframes={total_frames}\noutput_mode={'single_poses_npy' if single_poses_npz else 'per_frame_npz'}\ndecode_mode={'stream' if stream_frames else 'jpg-spill'}\noptimized_mode={optimized_mode}\noptimized_detect_resolution={optimized_detect_resolution}\noptimized_frame_stride={optimized_frame_stride}\ncompleted_at={time.strftime('%Y-%m-%d %H:%M:%S')}\n",
|
| 726 |
encoding="utf-8",
|
| 727 |
)
|
| 728 |
+
if not was_complete:
|
| 729 |
+
adjust_processed_complete_counter(processed_complete_counter_path(stats_npz), 1)
|
| 730 |
|
| 731 |
|
| 732 |
def worker(rank: int, worker_count: int, video_paths: Sequence[Path], args: argparse.Namespace) -> None:
|
|
|
|
| 780 |
optimized_frame_batch_size=args.optimized_frame_batch_size,
|
| 781 |
optimized_detect_resolution=args.optimized_detect_resolution,
|
| 782 |
optimized_frame_stride=args.optimized_frame_stride,
|
| 783 |
+
stats_npz=args.stats_npz,
|
| 784 |
)
|
| 785 |
update_video_stats_best_effort(
|
| 786 |
args.stats_npz,
|
|
@@ -24,7 +24,12 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
| 24 |
if str(REPO_ROOT) not in sys.path:
|
| 25 |
sys.path.insert(0, str(REPO_ROOT))
|
| 26 |
|
| 27 |
-
from utils.stats_npz import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
from utils.dataset_pool import find_dataset_video_dir, list_unuploaded_folder_paths as list_unuploaded_folder_paths_pool
|
| 29 |
|
| 30 |
|
|
@@ -418,11 +423,15 @@ def cleanup_local_assets(
|
|
| 418 |
scratch_raw_video_dir: Path | None,
|
| 419 |
raw_caption_dir: Path,
|
| 420 |
raw_metadata_dir: Path,
|
|
|
|
| 421 |
) -> None:
|
| 422 |
for video_id in video_ids:
|
| 423 |
dataset_video_dir = find_dataset_video_dir(video_id, dataset_dir, scratch_dataset_dir)
|
|
|
|
| 424 |
if dataset_video_dir.exists():
|
| 425 |
shutil.rmtree(dataset_video_dir, ignore_errors=True)
|
|
|
|
|
|
|
| 426 |
for raw_dir in [raw_video_dir, scratch_raw_video_dir]:
|
| 427 |
if raw_dir is None:
|
| 428 |
continue
|
|
@@ -445,6 +454,7 @@ def prune_uploaded_runtime_residue(
|
|
| 445 |
scratch_raw_video_dir: Path | None,
|
| 446 |
raw_caption_dir: Path,
|
| 447 |
raw_metadata_dir: Path,
|
|
|
|
| 448 |
) -> None:
|
| 449 |
uploaded = set(progress.get("uploaded_folders", {}))
|
| 450 |
for video_id in uploaded:
|
|
@@ -461,8 +471,11 @@ def prune_uploaded_runtime_residue(
|
|
| 461 |
if metadata_path.exists():
|
| 462 |
metadata_path.unlink(missing_ok=True)
|
| 463 |
dataset_video_dir = find_dataset_video_dir(video_id, dataset_dir, scratch_dataset_dir)
|
| 464 |
-
|
|
|
|
| 465 |
shutil.rmtree(dataset_video_dir, ignore_errors=True)
|
|
|
|
|
|
|
| 466 |
|
| 467 |
|
| 468 |
def format_size(num_bytes: int) -> str:
|
|
@@ -525,6 +538,7 @@ def main() -> None:
|
|
| 525 |
args.scratch_raw_video_dir,
|
| 526 |
args.raw_caption_dir,
|
| 527 |
args.raw_metadata_dir,
|
|
|
|
| 528 |
)
|
| 529 |
remaining_folder_paths = list_unuploaded_folder_paths(args.dataset_dir, args.scratch_dataset_dir, progress)
|
| 530 |
remaining_folder_paths = filter_folders_for_shard(remaining_folder_paths, args.parallel_shards, args.shard_index)
|
|
@@ -665,6 +679,7 @@ def main() -> None:
|
|
| 665 |
args.scratch_raw_video_dir,
|
| 666 |
args.raw_caption_dir,
|
| 667 |
args.raw_metadata_dir,
|
|
|
|
| 668 |
)
|
| 669 |
if archive_path.exists():
|
| 670 |
archive_path.unlink(missing_ok=True)
|
|
|
|
| 24 |
if str(REPO_ROOT) not in sys.path:
|
| 25 |
sys.path.insert(0, str(REPO_ROOT))
|
| 26 |
|
| 27 |
+
from utils.stats_npz import (
|
| 28 |
+
adjust_processed_complete_counter,
|
| 29 |
+
apply_status_journal_to_stats,
|
| 30 |
+
processed_complete_counter_path,
|
| 31 |
+
update_many_video_stats_with_retry,
|
| 32 |
+
)
|
| 33 |
from utils.dataset_pool import find_dataset_video_dir, list_unuploaded_folder_paths as list_unuploaded_folder_paths_pool
|
| 34 |
|
| 35 |
|
|
|
|
| 423 |
scratch_raw_video_dir: Path | None,
|
| 424 |
raw_caption_dir: Path,
|
| 425 |
raw_metadata_dir: Path,
|
| 426 |
+
stats_npz: Path,
|
| 427 |
) -> None:
|
| 428 |
for video_id in video_ids:
|
| 429 |
dataset_video_dir = find_dataset_video_dir(video_id, dataset_dir, scratch_dataset_dir)
|
| 430 |
+
had_complete = (dataset_video_dir / "npz" / COMPLETE_MARKER_NAME).exists()
|
| 431 |
if dataset_video_dir.exists():
|
| 432 |
shutil.rmtree(dataset_video_dir, ignore_errors=True)
|
| 433 |
+
if had_complete:
|
| 434 |
+
adjust_processed_complete_counter(processed_complete_counter_path(stats_npz), -1)
|
| 435 |
for raw_dir in [raw_video_dir, scratch_raw_video_dir]:
|
| 436 |
if raw_dir is None:
|
| 437 |
continue
|
|
|
|
| 454 |
scratch_raw_video_dir: Path | None,
|
| 455 |
raw_caption_dir: Path,
|
| 456 |
raw_metadata_dir: Path,
|
| 457 |
+
stats_npz: Path | None = None,
|
| 458 |
) -> None:
|
| 459 |
uploaded = set(progress.get("uploaded_folders", {}))
|
| 460 |
for video_id in uploaded:
|
|
|
|
| 471 |
if metadata_path.exists():
|
| 472 |
metadata_path.unlink(missing_ok=True)
|
| 473 |
dataset_video_dir = find_dataset_video_dir(video_id, dataset_dir, scratch_dataset_dir)
|
| 474 |
+
had_complete = (dataset_video_dir / "npz" / COMPLETE_MARKER_NAME).exists()
|
| 475 |
+
if dataset_video_dir.exists():
|
| 476 |
shutil.rmtree(dataset_video_dir, ignore_errors=True)
|
| 477 |
+
if had_complete and stats_npz is not None:
|
| 478 |
+
adjust_processed_complete_counter(processed_complete_counter_path(stats_npz), -1)
|
| 479 |
|
| 480 |
|
| 481 |
def format_size(num_bytes: int) -> str:
|
|
|
|
| 538 |
args.scratch_raw_video_dir,
|
| 539 |
args.raw_caption_dir,
|
| 540 |
args.raw_metadata_dir,
|
| 541 |
+
args.stats_npz,
|
| 542 |
)
|
| 543 |
remaining_folder_paths = list_unuploaded_folder_paths(args.dataset_dir, args.scratch_dataset_dir, progress)
|
| 544 |
remaining_folder_paths = filter_folders_for_shard(remaining_folder_paths, args.parallel_shards, args.shard_index)
|
|
|
|
| 679 |
args.scratch_raw_video_dir,
|
| 680 |
args.raw_caption_dir,
|
| 681 |
args.raw_metadata_dir,
|
| 682 |
+
args.stats_npz,
|
| 683 |
)
|
| 684 |
if archive_path.exists():
|
| 685 |
archive_path.unlink(missing_ok=True)
|
|
@@ -10,7 +10,8 @@ import subprocess
|
|
| 10 |
from collections import Counter
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
-
from utils.
|
|
|
|
| 14 |
|
| 15 |
VIDEO_EXTS = {'.mp4', '.mkv', '.webm', '.mov'}
|
| 16 |
ARRAY_RANGE_RE = re.compile(r'^(\d+)_\[(.+)\]$')
|
|
@@ -248,6 +249,23 @@ def read_source_manifest_count(path: Path) -> int:
|
|
| 248 |
return count
|
| 249 |
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
def read_processed_progress(path: Path) -> dict[str, object]:
|
| 252 |
result = {
|
| 253 |
'csv_exists': path.exists(),
|
|
@@ -334,6 +352,7 @@ def main() -> None:
|
|
| 334 |
parser.add_argument('--no-sync', action='store_true')
|
| 335 |
parser.add_argument('--json', action='store_true')
|
| 336 |
parser.add_argument('--include-partitions', action='store_true')
|
|
|
|
| 337 |
parser.add_argument('--scan-complete', action='store_true')
|
| 338 |
parser.add_argument('--scan-runtime-size', action='store_true')
|
| 339 |
args = parser.parse_args()
|
|
@@ -369,7 +388,7 @@ def main() -> None:
|
|
| 369 |
|
| 370 |
raw_size = sum_file_sizes(list(raw_complete.values()))
|
| 371 |
runtime_size = 0
|
| 372 |
-
if runtime_root.exists():
|
| 373 |
proc = subprocess.run(['du', '-sb', str(runtime_root)], check=False, capture_output=True, text=True)
|
| 374 |
if proc.returncode == 0 and proc.stdout.strip():
|
| 375 |
try:
|
|
@@ -378,7 +397,22 @@ def main() -> None:
|
|
| 378 |
runtime_size = 0
|
| 379 |
|
| 380 |
source_rows = read_source_manifest_count(source_csv)
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
videos_per_dwpose_job = read_videos_per_dwpose_job(root_dir)
|
| 383 |
|
| 384 |
payload = {
|
|
@@ -387,7 +421,7 @@ def main() -> None:
|
|
| 387 |
'raw_videos': len(raw_complete),
|
| 388 |
'raw_temp_files': len(raw_temp),
|
| 389 |
'sent_to_gpu': count_claims(claims_dir),
|
| 390 |
-
'processed_complete':
|
| 391 |
'active_downloads': count_claims(download_claims_dir),
|
| 392 |
'uploaded_archives': 0,
|
| 393 |
'uploaded_folders': 0,
|
|
|
|
| 10 |
from collections import Counter
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
+
from utils.stats_npz import processed_complete_counter_path, read_processed_complete_counter
|
| 14 |
+
|
| 15 |
|
| 16 |
VIDEO_EXTS = {'.mp4', '.mkv', '.webm', '.mov'}
|
| 17 |
ARRAY_RANGE_RE = re.compile(r'^(\d+)_\[(.+)\]$')
|
|
|
|
| 249 |
return count
|
| 250 |
|
| 251 |
|
| 252 |
+
def fast_count_complete(dataset_dir: Path, scratch_dataset_dir: Path) -> int:
|
| 253 |
+
roots = [str(p) for p in (dataset_dir, scratch_dataset_dir) if p.exists()]
|
| 254 |
+
if not roots:
|
| 255 |
+
return 0
|
| 256 |
+
cmd = ['find', *roots, '-path', '*/npz/.complete']
|
| 257 |
+
try:
|
| 258 |
+
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
|
| 259 |
+
except OSError:
|
| 260 |
+
return 0
|
| 261 |
+
if proc.returncode not in (0, 1):
|
| 262 |
+
return 0
|
| 263 |
+
out = proc.stdout
|
| 264 |
+
if not out:
|
| 265 |
+
return 0
|
| 266 |
+
return sum(1 for line in out.splitlines() if line.strip())
|
| 267 |
+
|
| 268 |
+
|
| 269 |
def read_processed_progress(path: Path) -> dict[str, object]:
|
| 270 |
result = {
|
| 271 |
'csv_exists': path.exists(),
|
|
|
|
| 352 |
parser.add_argument('--no-sync', action='store_true')
|
| 353 |
parser.add_argument('--json', action='store_true')
|
| 354 |
parser.add_argument('--include-partitions', action='store_true')
|
| 355 |
+
parser.add_argument('--scan-csv', action='store_true')
|
| 356 |
parser.add_argument('--scan-complete', action='store_true')
|
| 357 |
parser.add_argument('--scan-runtime-size', action='store_true')
|
| 358 |
args = parser.parse_args()
|
|
|
|
| 388 |
|
| 389 |
raw_size = sum_file_sizes(list(raw_complete.values()))
|
| 390 |
runtime_size = 0
|
| 391 |
+
if args.scan_runtime_size and runtime_root.exists():
|
| 392 |
proc = subprocess.run(['du', '-sb', str(runtime_root)], check=False, capture_output=True, text=True)
|
| 393 |
if proc.returncode == 0 and proc.stdout.strip():
|
| 394 |
try:
|
|
|
|
| 397 |
runtime_size = 0
|
| 398 |
|
| 399 |
source_rows = read_source_manifest_count(source_csv)
|
| 400 |
+
if args.scan_csv:
|
| 401 |
+
progress = read_processed_progress(processed_csv)
|
| 402 |
+
else:
|
| 403 |
+
progress = {
|
| 404 |
+
'csv_exists': processed_csv.exists(),
|
| 405 |
+
'csv_ok': False,
|
| 406 |
+
'csv_error': 'skipped',
|
| 407 |
+
'processed_rows': 0,
|
| 408 |
+
'download_ok_rows': 0,
|
| 409 |
+
'download_skipped_rows': 0,
|
| 410 |
+
'download_running_rows': 0,
|
| 411 |
+
'download_pending_rows': 0,
|
| 412 |
+
'process_ok_rows': 0,
|
| 413 |
+
'process_running_rows': 0,
|
| 414 |
+
'upload_uploaded_rows': 0,
|
| 415 |
+
}
|
| 416 |
videos_per_dwpose_job = read_videos_per_dwpose_job(root_dir)
|
| 417 |
|
| 418 |
payload = {
|
|
|
|
| 421 |
'raw_videos': len(raw_complete),
|
| 422 |
'raw_temp_files': len(raw_temp),
|
| 423 |
'sent_to_gpu': count_claims(claims_dir),
|
| 424 |
+
'processed_complete': read_processed_complete_counter(processed_complete_counter_path(runtime_root / 'stats.npz')),
|
| 425 |
'active_downloads': count_claims(download_claims_dir),
|
| 426 |
'uploaded_archives': 0,
|
| 427 |
'uploaded_folders': 0,
|
|
@@ -31,7 +31,14 @@ def iter_dataset_video_dirs(home_dataset_dir: Path, scratch_dataset_dir: Path |
|
|
| 31 |
for folder_path in sorted(dataset_dir.iterdir()):
|
| 32 |
if not folder_path.is_dir():
|
| 33 |
continue
|
| 34 |
-
seen.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
for video_id, folder_path in sorted(seen.items()):
|
| 36 |
yield video_id, folder_path
|
| 37 |
|
|
@@ -50,12 +57,15 @@ def count_complete(home_dataset_dir: Path, scratch_dataset_dir: Path | None = No
|
|
| 50 |
|
| 51 |
def find_dataset_video_dir(video_id: str, home_dataset_dir: Path, scratch_dataset_dir: Path | None = None) -> Path:
|
| 52 |
home_path = home_dataset_dir / video_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
if home_path.exists():
|
| 54 |
return home_path
|
| 55 |
-
if
|
| 56 |
-
|
| 57 |
-
if scratch_path.exists():
|
| 58 |
-
return scratch_path
|
| 59 |
return home_path
|
| 60 |
|
| 61 |
|
|
|
|
| 31 |
for folder_path in sorted(dataset_dir.iterdir()):
|
| 32 |
if not folder_path.is_dir():
|
| 33 |
continue
|
| 34 |
+
existing = seen.get(folder_path.name)
|
| 35 |
+
if existing is None:
|
| 36 |
+
seen[folder_path.name] = folder_path
|
| 37 |
+
continue
|
| 38 |
+
existing_complete = (existing / "npz" / COMPLETE_MARKER_NAME).exists()
|
| 39 |
+
candidate_complete = (folder_path / "npz" / COMPLETE_MARKER_NAME).exists()
|
| 40 |
+
if candidate_complete and not existing_complete:
|
| 41 |
+
seen[folder_path.name] = folder_path
|
| 42 |
for video_id, folder_path in sorted(seen.items()):
|
| 43 |
yield video_id, folder_path
|
| 44 |
|
|
|
|
| 57 |
|
| 58 |
def find_dataset_video_dir(video_id: str, home_dataset_dir: Path, scratch_dataset_dir: Path | None = None) -> Path:
|
| 59 |
home_path = home_dataset_dir / video_id
|
| 60 |
+
scratch_path = scratch_dataset_dir / video_id if scratch_dataset_dir is not None else None
|
| 61 |
+
home_complete = (home_path / "npz" / COMPLETE_MARKER_NAME).exists()
|
| 62 |
+
scratch_complete = bool(scratch_path is not None and (scratch_path / "npz" / COMPLETE_MARKER_NAME).exists())
|
| 63 |
+
if scratch_complete and not home_complete:
|
| 64 |
+
return scratch_path
|
| 65 |
if home_path.exists():
|
| 66 |
return home_path
|
| 67 |
+
if scratch_path is not None and scratch_path.exists():
|
| 68 |
+
return scratch_path
|
|
|
|
|
|
|
| 69 |
return home_path
|
| 70 |
|
| 71 |
|
|
@@ -36,6 +36,48 @@ def _lock_path(stats_path: Path) -> Path:
|
|
| 36 |
return stats_path.with_suffix(stats_path.suffix + ".lock")
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def _load_stats_unlocked(stats_path: Path) -> Dict[str, Dict[str, str]]:
|
| 40 |
if not stats_path.exists() or stats_path.stat().st_size == 0:
|
| 41 |
return {}
|
|
|
|
| 36 |
return stats_path.with_suffix(stats_path.suffix + ".lock")
|
| 37 |
|
| 38 |
|
| 39 |
+
def processed_complete_counter_path(stats_path: Path) -> Path:
|
| 40 |
+
return stats_path.parent / "processed_complete.count"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _counter_lock_path(counter_path: Path) -> Path:
|
| 44 |
+
return counter_path.with_suffix(counter_path.suffix + ".lock")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def read_processed_complete_counter(counter_path: Path) -> int:
|
| 48 |
+
if not counter_path.exists():
|
| 49 |
+
return 0
|
| 50 |
+
try:
|
| 51 |
+
return int(counter_path.read_text(encoding="utf-8").strip() or "0")
|
| 52 |
+
except Exception:
|
| 53 |
+
return 0
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def write_processed_complete_counter(counter_path: Path, value: int) -> int:
|
| 57 |
+
counter_path.parent.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
normalized = max(0, int(value))
|
| 59 |
+
tmp_path = counter_path.parent / f".{counter_path.name}.{os.getpid()}.tmp"
|
| 60 |
+
try:
|
| 61 |
+
tmp_path.write_text(f"{normalized}\n", encoding="utf-8")
|
| 62 |
+
os.replace(tmp_path, counter_path)
|
| 63 |
+
finally:
|
| 64 |
+
if tmp_path.exists():
|
| 65 |
+
tmp_path.unlink(missing_ok=True)
|
| 66 |
+
return normalized
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def adjust_processed_complete_counter(counter_path: Path, delta: int) -> int:
|
| 70 |
+
lock_path = _counter_lock_path(counter_path)
|
| 71 |
+
lock_path.parent.mkdir(parents=True, exist_ok=True)
|
| 72 |
+
with lock_path.open("a+", encoding="utf-8") as handle:
|
| 73 |
+
fcntl.flock(handle.fileno(), fcntl.LOCK_EX)
|
| 74 |
+
try:
|
| 75 |
+
current = read_processed_complete_counter(counter_path)
|
| 76 |
+
return write_processed_complete_counter(counter_path, current + int(delta))
|
| 77 |
+
finally:
|
| 78 |
+
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
def _load_stats_unlocked(stats_path: Path) -> Dict[str, Dict[str, str]]:
|
| 82 |
if not stats_path.exists() or stats_path.stat().st_size == 0:
|
| 83 |
return {}
|