Log to modgrad from Rust

A Rust training program logs to app.modgrad.com the same way as any other: print lines and pipe them, or post JSON. You need a project token from the quickstart.

Print the step on every metric line:

eprintln!("step {step}: loss={loss:.4} lr={lr:e}");

Pipe the output into a run over SSH:

cargo run --release -p my-trainer 2>&1 | ssh ssh.modgrad.com run my-run

or with pipe.py and a token, which also records the exit code:

curl -s https://app.modgrad.com/pipe.py -o modgrad_pipe.py
export MODGRAD_TOKEN=<token>
python3 modgrad_pipe.py my-run -- cargo run --release -p my-trainer

The SDK’s minictm example prints step 200: loss=2.310 avg50=2.400 acc=11/32; the parser reads the step, loss, avg50, and 11/32 as acc and acc_total. Other formats: log raw text.

Post JSON rows

For exact or nested keys, write one JSON object per line (NDJSON) and post it:

use serde_json::json;
use std::io::Write;

let mut out = std::fs::File::create("rows.ndjson")?;
for (step, loss) in losses.iter().enumerate() {
    writeln!(out, "{}", json!({"step": step, "train": {"loss": loss}}))?;
}
curl -X POST https://app.modgrad.com/api/v1/runs/my-run/log \
  -H "Authorization: Bearer $MODGRAD_TOKEN" --data-binary @rows.ndjson

Use --data-binary: -d strips the newlines between rows. One body takes up to 4,096 rows. Nested objects become train/loss. Any HTTP client works the same way; see the HTTP API.