File size: 905 Bytes
a15535e | 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 | #!/usr/bin/env python
"""Re-attach to an in-flight HF Jobs run and stream its logs.
Usage::
$env:HF_TOKEN = "hf_..."
python scripts/tail_training_job.py 69ec88dfd70108f37acde39d
"""
from __future__ import annotations
import os
import sys
from huggingface_hub import HfApi
from submit_training_job import tail_logs # type: ignore[import-not-found]
def main() -> int:
if len(sys.argv) < 2:
print("usage: python scripts/tail_training_job.py <job_id> [namespace]", file=sys.stderr)
return 2
job_id = sys.argv[1]
namespace = sys.argv[2] if len(sys.argv) > 2 else "akhiilll"
token = os.environ.get("HF_TOKEN")
if not token:
print("ERROR: set HF_TOKEN in the environment first.", file=sys.stderr)
return 2
api = HfApi()
return tail_logs(api, token, job_id, namespace=namespace)
if __name__ == "__main__":
raise SystemExit(main())
|