Metadata-Version: 2.5
Name: hpcnav-job
Version: 0.1.0
Summary: HPC Navigator inside your jobs: crash-loop guard, time cap, checkpoints that resume, and progress (standard library only)
Project-URL: Homepage, https://sydney-informatics-hub.github.io/hpc-navigator/
Project-URL: Source, https://github.com/Sydney-Informatics-Hub/hpc-navigator
Project-URL: Issues, https://github.com/Sydney-Informatics-Hub/hpc-navigator/issues
Author: Sydney Informatics Hub, The University of Sydney
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: checkpoint,gpu,hpc,kubernetes,run:ai,slurm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# hpcnav-job

The in-job part of [HPC Navigator](https://sydney-informatics-hub.github.io/hpc-navigator/).
Runs inside a researcher's job: progress, checkpoints, GPU samples and the guards, written as
JSON Lines files on shared storage, so the job needs no network access and keeps working while
the laptop sleeps. Standard library only, Python >= 3.9; PyTorch and Hugging Face helpers import
only when used.

## In a training script

```python
import hpcnav_job

ckpt = hpcnav_job.Checkpointer("/shared/run1/ckpt", reporter=hpcnav_job.default_reporter())
state, _, step = ckpt.load_torch()  # newest checkpoint that loads, or (None, None, None)
stop = hpcnav_job.graceful_stop()  # on SIGTERM: finish the step, then save and exit 143
hpcnav_job.progress(step, total, unit="steps")  # in the loop; at most one event per 30 s
```

and in the loop: `if stop: ckpt.save_torch(state, step); stop.exit()`. With the Hugging Face
Trainer: `Trainer(..., callbacks=[hpcnav_job.hf.hpcnav_callback()])`.

## Around any command

```bash
hpcnav-run --log "$WORKDIR/logs/run1.log" --done-marker "$WORKDIR/run1/DONE" --expected-hours 6 -- python train.py
```

`hpcnav-run` (installed with this package; for an image without pip, copy [`wrappers/hpcnav-run`](https://github.com/Sydney-Informatics-Hub/hpc-navigator/blob/main/wrappers/hpcnav-run) from the repository to shared storage) forwards SIGTERM, copies
output to the log, exits 0 after logging the real code so a crash can't loop, stops after 3
failed starts in a row, and caps the run at 1.5 x the expected hours. With Python and this
package in the image it also samples the GPU each minute, can stop an idle job
(`--idle-minutes 30`), and records what ran. Without Python the crash-loop guard and time cap
still work, in bash.

Set `HPCNAV_EVENTS_DIR` (Apollo: `$WORKDIR/.hpcnav/events`) so events and guard files are kept;
`HPCNAV_SITE`, `HPCNAV_PROJECT` and `HPCNAV_WORKLOAD` are set by `hpcnav submit` and
are optional by hand.

Apache-2.0. Source and issues: https://github.com/Sydney-Informatics-Hub/hpc-navigator
