File size: 19,942 Bytes
1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d fa3502a 1199e9d fa3502a 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be fa3502a 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d fa3502a 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d bc864be 1199e9d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | #!/usr/bin/env python3
from __future__ import annotations
import argparse
import csv
import json
import os
import re
import subprocess
from collections import Counter
from pathlib import Path
from utils.dataset_pool import count_complete
VIDEO_EXTS = {'.mp4', '.mkv', '.webm', '.mov'}
ARRAY_RANGE_RE = re.compile(r'^(\d+)_\[(.+)\]$')
PROCESSED_REQUIRED_COLUMNS = {
'video_id',
'download_status',
'process_status',
'upload_status',
'archive_name',
}
GPU_PARTITIONS = ['gpu', 'gpu-redhat', 'cgpu']
DEFAULT_VIDEOS_PER_DWPOSE_JOB = 20
def run_command(cmd: list[str]) -> str:
try:
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
except OSError:
return ''
return (proc.stdout or '').strip()
def count_claims(directory: Path) -> int:
if not directory.exists():
return 0
return sum(1 for _ in directory.glob('*.claim'))
def aggregate_claims_by_job_key(directory: Path) -> dict[str, int]:
counts: Counter[str] = Counter()
if not directory.exists():
return {}
for path in directory.glob('*.claim'):
try:
lines = path.read_text(encoding='utf-8').splitlines()
except OSError:
continue
job_key = ''
for line in lines:
if line.startswith('job_key='):
job_key = line.split('=', 1)[1].strip()
break
if job_key:
counts[job_key] += 1
return dict(counts)
def read_videos_per_dwpose_job(root_dir: Path) -> int:
worker = root_dir / 'slurm' / 'process_dwpose_array.slurm'
if not worker.exists():
return DEFAULT_VIDEOS_PER_DWPOSE_JOB
try:
for line in worker.read_text().splitlines():
if line.startswith('VIDEOS_PER_JOB='):
m = re.search(r'\$\{VIDEOS_PER_JOB:-([0-9]+)\}', line)
if m:
return int(m.group(1))
except Exception:
pass
return DEFAULT_VIDEOS_PER_DWPOSE_JOB
def sum_file_sizes(paths: list[Path]) -> int:
total = 0
for path in paths:
try:
total += path.stat().st_size
except FileNotFoundError:
continue
return total
def count_uploaded(progress_path: Path) -> tuple[int, int]:
if not progress_path.exists():
return 0, 0
try:
data = json.loads(progress_path.read_text())
except Exception:
return 0, 0
archives = data.get('archives', {})
uploaded_folders = data.get('uploaded_folders', {})
return len(archives), len(uploaded_folders)
def expand_task_count(jobid_token: str) -> int:
m = ARRAY_RANGE_RE.match(jobid_token)
if not m:
return 1
body = m.group(2)
if '%' in body:
body = body.split('%', 1)[0]
total = 0
for part in body.split(','):
part = part.strip()
if not part:
continue
if '-' in part:
a, b = part.split('-', 1)
try:
total += int(b) - int(a) + 1
except ValueError:
total += 1
else:
total += 1
return max(total, 1)
def queue_status(username: str) -> dict[str, object]:
output = run_command(['squeue', '-u', username, '-h', '-o', '%i|%j|%T|%P'])
job_counts: Counter[str] = Counter()
partition_counts: Counter[str] = Counter()
active_tasks_by_partition: Counter[str] = Counter()
running_dwpose = 0
running_download = 0
pending_download = 0
pending_dwpose = 0
if output:
for line in output.splitlines():
parts = line.split('|')
if len(parts) != 4:
continue
jobid_token, job, state, partition = parts
count = expand_task_count(jobid_token)
job_counts[f'{job}|{state}'] += count
partition_counts[f'{job}|{partition}|{state}'] += count
if state in {'RUNNING', 'PENDING', 'CONFIGURING'}:
active_tasks_by_partition[partition] += count
if job == 'dwpose' and state == 'RUNNING':
running_dwpose += count
if job == 'download' and state == 'RUNNING':
running_download += count
if job == 'download' and state in {'PENDING', 'CONFIGURING'}:
pending_download += count
if job == 'dwpose' and state in {'PENDING', 'CONFIGURING'}:
pending_dwpose += count
total_download = running_download + pending_download
return {
'running_dwpose': running_dwpose,
'running_download': running_download,
'pending_dwpose_jobs': pending_dwpose,
'pending_download_jobs': pending_download,
'total_download_jobs': total_download,
'job_state_counts': dict(job_counts),
'job_partition_state_counts': dict(partition_counts),
'active_tasks_by_partition': dict(active_tasks_by_partition),
}
def gpu_partition_capacity(partitions: list[str], active_tasks_by_partition: dict[str, int]) -> list[dict[str, object]]:
qos_limit_by_part: dict[str, int] = {}
qos_output = run_command(['sacctmgr', 'show', 'qos', 'format=Name,MaxSubmitPU', '-P'])
if qos_output:
for line in qos_output.splitlines():
if not line.strip() or '|' not in line:
continue
name, max_submit = line.split('|', 1)
name = name.strip()
max_submit = max_submit.strip()
if name in partitions and max_submit:
try:
qos_limit_by_part[name] = int(max_submit)
except ValueError:
pass
rows: list[dict[str, object]] = []
for partition in partitions:
free_gpus = 0
nodes_output = run_command(['sinfo', '-h', '-N', '-p', partition, '-o', '%N'])
nodes = [line.strip() for line in nodes_output.splitlines() if line.strip()]
for node in nodes:
node_line = run_command(['scontrol', 'show', 'node', node, '-o'])
if not node_line:
continue
state_m = re.search(r'\bState=([^ ]+)', node_line)
state = state_m.group(1).lower() if state_m else ''
if any(flag in state for flag in ('drain', 'drained', 'down', 'fail', 'inval')):
continue
cfg_m = re.search(r'\bCfgTRES=.*?(?:,|^)gres/gpu=(\d+)', node_line)
alloc_m = re.search(r'\bAllocTRES=.*?(?:,|^)gres/gpu=(\d+)', node_line)
total = int(cfg_m.group(1)) if cfg_m else 0
used = int(alloc_m.group(1)) if alloc_m else 0
free = total - used
if free > 0:
free_gpus += free
active_tasks = int(active_tasks_by_partition.get(partition, 0))
qos_limit = qos_limit_by_part.get(partition)
submit_slots = free_gpus
if qos_limit is not None:
submit_slots = min(submit_slots, max(0, qos_limit - active_tasks))
rows.append({
'partition': partition,
'free_gpus': free_gpus,
'active_tasks': active_tasks,
'qos_limit': qos_limit,
'submit_slots': submit_slots,
})
return rows
def filesystem_avail_bytes(path: Path) -> int:
try:
proc = subprocess.run(['df', '-B1', str(path)], check=False, capture_output=True, text=True)
lines = (proc.stdout or '').splitlines()
if len(lines) < 2:
return 0
fields = lines[1].split()
if len(fields) < 4:
return 0
return int(fields[3])
except Exception:
return 0
def human_bytes(num: int) -> str:
value = float(num)
for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']:
if value < 1024.0:
return f'{value:.1f}{unit}'
value /= 1024.0
return f'{value:.1f}EB'
def read_source_manifest_count(path: Path) -> int:
if not path.exists():
return 0
count = 0
with path.open('r', encoding='utf-8-sig', newline='') as f:
reader = csv.reader(f)
for row in reader:
if not row:
continue
if not (row[0] or '').strip():
continue
count += 1
return count
def read_processed_progress(path: Path) -> dict[str, object]:
result = {
'csv_exists': path.exists(),
'csv_ok': False,
'csv_error': '',
'processed_rows': 0,
'download_ok_rows': 0,
'download_skipped_rows': 0,
'download_running_rows': 0,
'download_pending_rows': 0,
'process_ok_rows': 0,
'process_running_rows': 0,
'upload_uploaded_rows': 0,
}
if not path.exists():
result['csv_error'] = 'missing'
return result
try:
with path.open('r', encoding='utf-8-sig', newline='') as f:
reader = csv.DictReader(f)
fieldnames = list(reader.fieldnames or [])
missing = sorted(PROCESSED_REQUIRED_COLUMNS - set(fieldnames))
if missing:
result['csv_error'] = f'missing_columns:{",".join(missing)}'
return result
rows = list(reader)
result['processed_rows'] = len(rows)
for row in rows:
d = (row.get('download_status') or '').strip()
p = (row.get('process_status') or '').strip()
u = (row.get('upload_status') or '').strip()
if d == 'ok':
result['download_ok_rows'] += 1
elif d == 'skipped':
result['download_skipped_rows'] += 1
elif d == 'running':
result['download_running_rows'] += 1
else:
result['download_pending_rows'] += 1
if p == 'ok':
result['process_ok_rows'] += 1
elif p == 'running':
result['process_running_rows'] += 1
if u == 'uploaded':
result['upload_uploaded_rows'] += 1
result['csv_ok'] = True
return result
except Exception as exc:
result['csv_error'] = str(exc)
return result
def run_sync(runtime_root: Path) -> str:
sync_script = Path('/cache/home/sf895/SignVerse-2M/scripts/sync_processed_csv_from_runtime.py')
if not sync_script.exists():
return 'missing_sync_script'
cmd = [
'python3', str(sync_script),
'--source-metadata-csv', str(runtime_root / 'SignVerse-2M-metadata_ori.csv'),
'--output-metadata-csv', str(runtime_root / 'SignVerse-2M-metadata_processed.csv'),
'--raw-video-dir', str(runtime_root / 'raw_video'),
'--scratch-raw-video-dir', str(Path(f'/scratch/{os.environ.get("USER", "sf895")}/SignVerse-2M-runtime/raw_video')),
'--raw-caption-dir', str(runtime_root / 'raw_caption'),
'--raw-metadata-dir', str(runtime_root / 'raw_metadata'),
'--dataset-dir', str(runtime_root / 'dataset'),
'--scratch-dataset-dir', str(Path(f'/scratch/{os.environ.get("USER", "sf895")}/SignVerse-2M-runtime/dataset')),
'--progress-path', str(runtime_root / 'archive_upload_progress.json'),
'--status-journal-path', str(runtime_root / 'upload_status_journal.jsonl'),
]
try:
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
except OSError as exc:
return f'error:{exc}'
if proc.returncode == 0:
return (proc.stdout or '').strip() or 'ok'
err = (proc.stderr or proc.stdout or '').strip()
return f'failed:{err}'
def main() -> None:
parser = argparse.ArgumentParser(description='Report SignVerse runtime status.')
parser.add_argument('--runtime-root', default='/home/sf895/SignVerse-2M-runtime')
parser.add_argument('--username', default='sf895')
parser.add_argument('--no-sync', action='store_true')
parser.add_argument('--json', action='store_true')
parser.add_argument('--include-partitions', action='store_true')
parser.add_argument('--scan-complete', action='store_true')
parser.add_argument('--scan-runtime-size', action='store_true')
args = parser.parse_args()
runtime_root = Path(args.runtime_root)
root_dir = Path('/cache/home/sf895/SignVerse-2M')
raw_dir = runtime_root / 'raw_video'
scratch_raw_dir = Path(f'/scratch/{os.environ.get("USER", "sf895")}/SignVerse-2M-runtime/raw_video')
dataset_dir = runtime_root / 'dataset'
scratch_dataset_dir = Path(f'/scratch/{os.environ.get("USER", "sf895")}/SignVerse-2M-runtime/dataset')
claims_dir = runtime_root / 'slurm' / 'state' / 'claims'
download_claims_dir = runtime_root / 'slurm' / 'state' / 'download_claims'
progress_path = runtime_root / 'archive_upload_progress.json'
source_csv = runtime_root / 'SignVerse-2M-metadata_ori.csv'
processed_csv = runtime_root / 'SignVerse-2M-metadata_processed.csv'
sync_result = 'skipped'
if not args.no_sync:
sync_result = run_sync(runtime_root)
raw_complete: dict[str, Path] = {}
raw_temp: list[Path] = []
for current_raw_dir in [raw_dir, scratch_raw_dir]:
if not current_raw_dir.exists():
continue
for path in current_raw_dir.iterdir():
if not path.is_file():
continue
if path.suffix.lower() in VIDEO_EXTS:
raw_complete.setdefault(path.stem, path)
else:
raw_temp.append(path)
raw_size = sum_file_sizes(list(raw_complete.values()))
runtime_size = 0
if runtime_root.exists():
proc = subprocess.run(['du', '-sb', str(runtime_root)], check=False, capture_output=True, text=True)
if proc.returncode == 0 and proc.stdout.strip():
try:
runtime_size = int(proc.stdout.split()[0])
except Exception:
runtime_size = 0
source_rows = read_source_manifest_count(source_csv)
progress = read_processed_progress(processed_csv)
videos_per_dwpose_job = read_videos_per_dwpose_job(root_dir)
payload = {
'sync_result': sync_result,
'download_normal': len(raw_temp) == 0,
'raw_videos': len(raw_complete),
'raw_temp_files': len(raw_temp),
'sent_to_gpu': count_claims(claims_dir),
'processed_complete': count_complete(dataset_dir, scratch_dataset_dir),
'active_downloads': count_claims(download_claims_dir),
'uploaded_archives': 0,
'uploaded_folders': 0,
'raw_size_bytes': raw_size,
'runtime_size_bytes': runtime_size,
'filesystem_avail_bytes': filesystem_avail_bytes(runtime_root),
'source_rows': source_rows,
'csv_exists': progress['csv_exists'],
'csv_ok': progress['csv_ok'],
'csv_error': progress['csv_error'],
'processed_rows': progress['processed_rows'],
'download_ok_rows': progress['download_ok_rows'],
'download_skipped_rows': progress['download_skipped_rows'],
'download_running_rows': progress['download_running_rows'],
'download_pending_rows': progress['download_pending_rows'],
'process_ok_rows': progress['process_ok_rows'],
'process_running_rows': progress['process_running_rows'],
'upload_uploaded_rows': progress['upload_uploaded_rows'],
}
uploaded_archives, uploaded_folders = count_uploaded(progress_path)
payload['uploaded_archives'] = uploaded_archives
payload['uploaded_folders'] = uploaded_folders
payload.update(queue_status(args.username))
process_claims_by_job = aggregate_claims_by_job_key(claims_dir)
payload['videos_per_dwpose_job'] = videos_per_dwpose_job
payload['process_claim_job_keys'] = len(process_claims_by_job)
payload['process_claim_videos_actual'] = sum(process_claims_by_job.values())
payload['process_claim_videos_max_per_job'] = max(process_claims_by_job.values(), default=0)
payload['running_dwpose_jobs'] = payload['running_dwpose']
payload['running_dwpose_videos_estimated'] = payload['running_dwpose'] * videos_per_dwpose_job
payload['pending_dwpose_videos_estimated'] = payload['pending_dwpose_jobs'] * videos_per_dwpose_job
payload['total_dwpose_jobs'] = payload['running_dwpose'] + payload['pending_dwpose_jobs']
payload['total_dwpose_videos_estimated'] = payload['running_dwpose_videos_estimated'] + payload['pending_dwpose_videos_estimated']
if args.include_partitions:
payload['gpu_partition_capacity'] = gpu_partition_capacity(GPU_PARTITIONS, payload.get('active_tasks_by_partition', {}))
else:
payload['gpu_partition_capacity'] = []
payload['job_partition_state_counts'] = {}
payload['active_tasks_by_partition'] = {}
payload['csv_row_match'] = (payload['processed_rows'] == payload['source_rows']) if payload['csv_ok'] else False
if args.json:
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
return
print(f"sync_result={payload['sync_result']}")
print(f"download_normal={payload['download_normal']}")
print(f"raw_videos={payload['raw_videos']}")
print(f"raw_temp_files={payload['raw_temp_files']}")
print(f"sent_to_gpu={payload['sent_to_gpu']}")
print(f"running_dwpose={payload['running_dwpose']}")
print(f"running_dwpose_jobs={payload['running_dwpose_jobs']}")
print(f"pending_dwpose_jobs={payload['pending_dwpose_jobs']}")
print(f"total_dwpose_jobs={payload['total_dwpose_jobs']}")
print(f"videos_per_dwpose_job={payload['videos_per_dwpose_job']}")
print(f"process_claim_job_keys={payload['process_claim_job_keys']}")
print(f"process_claim_videos_actual={payload['process_claim_videos_actual']}")
print(f"process_claim_videos_max_per_job={payload['process_claim_videos_max_per_job']}")
print(f"running_dwpose_videos_estimated={payload['running_dwpose_videos_estimated']}")
print(f"pending_dwpose_videos_estimated={payload['pending_dwpose_videos_estimated']}")
print(f"total_dwpose_videos_estimated={payload['total_dwpose_videos_estimated']}")
print(f"processed_complete={payload['processed_complete']}")
print(f"active_downloads={payload['active_downloads']}")
print(f"running_download_jobs={payload['running_download']}")
print(f"pending_download_jobs={payload['pending_download_jobs']}")
print(f"total_download_jobs={payload['total_download_jobs']}")
print(f"uploaded_archives={payload['uploaded_archives']}")
print(f"uploaded_folders={payload['uploaded_folders']}")
print(f"source_rows={payload['source_rows']}")
print(f"processed_rows={payload['processed_rows']}")
print(f"csv_ok={payload['csv_ok']}")
print(f"csv_row_match={payload['csv_row_match']}")
print(f"csv_error={payload['csv_error']}")
print(f"download_ok_rows={payload['download_ok_rows']}")
print(f"download_skipped_rows={payload['download_skipped_rows']}")
print(f"download_running_rows={payload['download_running_rows']}")
print(f"download_pending_rows={payload['download_pending_rows']}")
print(f"process_ok_rows={payload['process_ok_rows']}")
print(f"process_running_rows={payload['process_running_rows']}")
print(f"upload_uploaded_rows={payload['upload_uploaded_rows']}")
for key in sorted(payload.get('job_partition_state_counts', {})):
print(f"job_partition_state[{key}]={payload['job_partition_state_counts'][key]}")
for row in payload.get('gpu_partition_capacity', []):
qos_limit = row['qos_limit'] if row['qos_limit'] is not None else 'na'
print(
f"gpu_partition[{row['partition']}]=free_gpus={row['free_gpus']},"
f"active_tasks={row['active_tasks']},qos_limit={qos_limit},submit_slots={row['submit_slots']}"
)
print(f"raw_size={human_bytes(payload['raw_size_bytes'])}")
print(f"runtime_size={human_bytes(payload['runtime_size_bytes'])}")
print(f"filesystem_avail={human_bytes(payload['filesystem_avail_bytes'])}")
if __name__ == '__main__':
main()
|