Run your own code
View MarkdownThis page runs a script from your own directory on a GPU, then downloads the file it wrote. It assumes you have
installed the CLI and signed in. Every command here runs in CI as the
cli/quickstart example.
-
Put your code in a directory. Any directory works; this one holds a small PyTorch training loop that saves its final metrics to
/nodus/outputs/metrics.json.train.py """Fit a small linear model, print progress and save metrics.json as the declared output "metrics"."""import jsonimport pathlibimport torchdevice = "cuda" if torch.cuda.is_available() else "cpu"print("device:", torch.cuda.get_device_name() if device == "cuda" else "cpu")torch.manual_seed(0)x = torch.randn(1024, 16, device=device)y = x @ torch.randn(16, 1, device=device)w = torch.zeros(16, 1, device=device, requires_grad=True)opt = torch.optim.SGD([w], lr=0.1)for step in range(200):loss = ((x @ w - y) ** 2).mean()opt.zero_grad()loss.backward()opt.step()if step % 50 == 0:print(f"step {step} loss {loss.item():.4f}")print(f"final loss {loss.item():.6f}")out = pathlib.Path("/nodus/outputs")out.mkdir(parents=True, exist_ok=True)(out / "metrics.json").write_text(json.dumps({"final_loss": loss.item(), "steps": 200})) -
Run it. From that directory:
Terminal window nodus run --name cli-quickstart --gpu L4 --image nodus/pytorch \--output metrics=/nodus/outputs/metrics.json -- python train.pyTerminal window job/cli-quickstart created · est. $0.01–0.03 · starts in ~2–4 min (cold) · hold $0.50 · Ctrl+C to cancel, -d to detach✓ Scheduled l4-24g-x1-us · $0.52/h (rate frozen)✓ Provisioning 1m48s▶ Runningdevice: NVIDIA L4step 0 loss 15.8732...final loss 0.000001✓ Succeeded in 2m31s · $0.02 (boot $0.01 · running $0.01) · kept warm 60 s · nodus describe job/cli-quickstartBefore anything is charged you see the estimate and a hold: the most this run can cost before you are asked.
nodus runthen uploads the directory (files listed in.gitignoreor.nodusignorestay local), prints each phase, streams your program’s output on stdout and ends with the cost line. The CLI exits with your command’s exit code, so it works in scripts and CI. -
Get the output. The
--outputflag declaredmetrics; copy it back:Terminal window nodus cp job/cli-quickstart:outputs/metrics metrics.jsonThe file is checked against its SHA-256 digest and only written when it matches.
Leave it running
Section titled “Leave it running”Press Ctrl+C during a run and the CLI asks whether to cancel the Job; answer n to detach and leave it
running. Or start with -d to return as soon as the Job exists. A detached Job keeps running:
nodus get jobs # every Job in the project, with phase and cost so farnodus get jobs --mine -w # only yours, updating livenodus logs -f job/cli-quickstart # stream the output againnodus describe job/cli-quickstart # attempts, placement, cost, conditions and eventsnodus cancel job/cli-quickstart # stop it; you pay only for what ranControl the cost
Section titled “Control the cost”| Flag | Effect |
|---|---|
--max-cost 5 |
The Job stops gracefully before it spends more than $5 |
--timeout 2h |
The Job is stopped after two hours of wall-clock time |
--dry-run |
Print the estimate and exit without creating anything |
nodus billing shows your balance and this month’s spend; nodus billing usage --group-by day breaks it down.
Clean up
Section titled “Clean up”Finished Jobs are kept for 30 days so you can read their logs and outputs, then deleted. To delete one now:
nodus delete job/cli-quickstartNext steps
Section titled “Next steps”- Nodus for kubectl users: manifests,
apply,get -o,waitanddiff. - CLI reference: every command and flag, with tested examples.