Repository navigation
Unsloth Studio logs: give each training run its own log file - #8764
LeoBorcherding wants to merge 1 commit into
Conversation
The training worker is a spawn child, so its stdout and stderr are the ones it inherited and its output lands wherever the parent's happened to point: interleaved into a shared server session log on the desktop, and only in the journal on a headless host. A run that died left no file of its own, which is why "my training failed" arrives in a support thread with nothing attached and no path to ask for. Each run now tees into logs/train/<run_id>.log, with faulthandler aimed at the same file so a native crash in a GPU runtime leaves a stack trace rather than an exit code. The console keeps everything it printed before, and isatty() answers for the console rather than the file so an interactive run does not lose its progress bars. The run id had to be plumbed in: it lives on the service and nothing in the worker config carried it across the spawn boundary. Both spawn sites set it, and the Xet -> HTTP respawn reuses the id and opens the file in append mode, so a retry adds to the log holding the reason it was retried instead of erasing it. The path is by convention, so anything that lists the directory finds every run without a lookup and without this change having to land first. The worker also prints "Run log: <path>", mirroring the server's own "Session log:" line that the desktop diagnostics collector keys off. Retention keeps the newest 50, more than the server's 20: a run log is small next to the session log it used to hide in, and runs are the thing people come back to ask about. That loop is a local copy on purpose -- the same helper is being factored out in the log-volume branch, and this should adopt utils/log_retention.prune_log_dir once that lands, rather than the two branches having to merge in order.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5cf5e59f43
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try: | ||
| import faulthandler | ||
| faulthandler.enable(file = log_fh, all_threads = True) |
There was a problem hiding this comment.
Keep fatal traces in collected diagnostics
When a training worker suffers a native GPU/runtime crash, this second faulthandler.enable() redirects the already-enabled handler away from inherited stderr and exclusively into log_fh. I checked the desktop collection path in studio/src-tauri/src/diagnostics/report.rs: it includes Tauri logs and captured phase logs but neither scans logs/train nor follows the printed Run log: path. Consequently, Copy Diagnostics and headless stderr/journal output lose the only native traceback in precisely the crash scenario this change is intended to diagnose; preserve a collected stderr copy or explicitly add the run log to diagnostics.
Useful? React with 👍 / 👎.
| _run_log_path = None | ||
| try: | ||
| from utils.train_run_log import setup_run_log | ||
| _run_log_path = setup_run_log(config.get("job_id") or "unknown-run") |
There was a problem hiding this comment.
Start teeing before worker startup diagnostics
For workers that use the Xet fallback or detect an unreachable Hugging Face endpoint, the explicit stderr notices are printed earlier in run_training_process, before this call replaces stdout/stderr, so those messages never reach the per-run log. More generally, a hang or failure during the network/offline startup probe occurs before the run log is even created, leaving no per-run artifact for that startup failure; initialize the tee before these probes and notices.
Useful? React with 👍 / 👎.
|
Closing this one. With the log viewer in #8690 the acute problem (no way to reach a failed run's output) is solved on the desktop, where the worker's stdout is captured in the phase log. Leaving a note for later: it does not reach logs/server/server-*.log, so on a headless install without the Tauri shell there is still no file holding a failed run's traceback. Narrow enough to revisit if it comes up. |
Why
The training worker is a spawn child, so its stdout and stderr are the ones it inherited and
its output lands wherever the parent's happened to point: interleaved into a shared server
session log on the desktop, and only in the journal on a headless host. A run that died left
no file of its own, which is why "my training failed" arrives in a support thread with
nothing attached and no path to ask for.
What
Each run tees into
logs/train/<run_id>.log, with faulthandler aimed at the same file so anative crash in a GPU runtime leaves a stack trace rather than an exit code. The console
keeps everything it printed before, and
isatty()answers for the console rather than thefile so an interactive run does not lose its progress bars.
The run id had to be plumbed in: it lives on the service and nothing in the worker config
carried it across the spawn boundary. Both spawn sites set it, and the Xet -> HTTP respawn
reuses the id and opens in append mode, so a retry adds to the log holding the reason it was
retried instead of erasing it.
The path is by convention, so anything listing the directory finds every run without a lookup
and without a UI change having to land first. The worker also prints
Run log: <path>,mirroring the
Session log:line the desktop diagnostics collector keys off.Testing
Verified by hand: file created at the expected path, stdout and stderr both captured, respawn
appends rather than truncates,
UNSLOTH_STUDIO_NO_FILE_LOG=1opts out, unsafe run idssanitised, empty id falls back. Not yet run against a real failing training job.
Note for review
Retention keeps the newest 50 via a local copy of the prune loop, not
utils/log_retention.prune_log_dirfrom the log-volume PR. That is deliberate so the twobranches stay independent and can merge in either order; adopting the shared helper is a
three-line follow-up once that one lands.