Skip to content

Studio: report bad decision datasets before the model downloads - #16498

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
NilayYadav:decision-dataset-early-validation
Nov 4, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
NilayYadav:decision-dataset-early-validation

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

A decision training run with a broken dataset only failed after the backbone had finished downloading and loading, which is 19 to 55 GB for Clef. A dataset with no labels or only invalid questions gave its error at the very end of that wait, and a single bad JSONL line gave a raw parser message with no file or line.

Rows are now checked without the model as soon as they are read, and the run stops there. Local files are checked before any model work starts. Hub and S3 datasets still download alongside the model, and a bad result ends the model download in progress. A bad line is reported as the file name and line number. Datasets with at least one usable decision still train, about a second slower to reach the first step on a one minute start, and partly bad datasets keep the same skip warning.

Runs that turn a plain language model into a decision model on a Hub or S3 dataset still report the problem after the load, because that download happens inside the model loader.

After a bad dataset or a stop ends the run while the checkpoint is still downloading, the worker now exits right after reporting it. Before, interpreter shutdown waited on the download threads, so the worker kept downloading and Studio refused a new run until the parent's watchdog killed it. The hard exit only applies to a worker process, never the in-process MLX adapter, and a download stall that arrives after the run already ended no longer respawns it over HTTP.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Reached Codex review convergence at NilayYadav#1095 on 0909a4b.

danielhanchen added a commit that referenced this pull request Nov 3, 2026
…he stop (#16525)

## Summary


`studio/backend/tests/test_inference_worker_shutdown_exit.py::test_shutdown_exit_still_relays_the_mirrored_stderr_tail`
(added in #16338) fails intermittently in `(Python 3.13, g-r)`. In the
last 30 PRs it hit #16495, #16496, #16498, #16500 and #16509:

```
assert "the last line before shutdown" in result.stderr
E   assert 'the last line before shutdown' in ''
```

That is a real product bug, not a flaky test. The worker can drop its
last stderr lines when it exits, which are the lines the parent reports
when a worker dies.

**Cause.** `_tail_sink_to_stderr`, the mirror pump thread, decided it
was done from two separate steps: a read that came back empty, then a
check that `stop` was set. If the pump is descheduled between those two
steps, the worker writes its last lines to the sink and calls
`stop_worker_stderr_mirror()` in the gap. The pump then sees "empty
read, and stop is set", exits, and never relays them.

I instrumented the stop sequence in a child that runs the test's exact
script, 900 times on 24 threads. On a failing run:
- the sink held all 1720 bytes at stop time;
- the pump made exactly one read, which returned empty and was logged
after the stop;
- it emitted 0 bytes, and both threads ended cleanly within 4 ms.

So nothing timed out and nothing was cut off; the lines were simply
never read.

## Change

`studio/backend/utils/worker_stderr.py`, `_tail_sink_to_stderr`: the
pump records `stop.is_set()` before each read and only finishes on an
empty read that began after the stop was set. Bytes written before
`stop.set()` are therefore always read. Nothing else changes: the poll
interval, compaction, the relay, the join timeouts, and what a live
worker mirrors.

`studio/backend/tests/test_inference_worker_shutdown_exit.py`: new
`test_the_pump_reads_once_more_after_an_empty_read_that_raced_the_stop`.
It drives the pump with a reader whose first read returns empty and sets
`stop` in that same call, so the race is forced deterministically rather
than left to scheduling.

## Testing

| check | main | this branch |
|---|---|---|
| instrumented child, 300 / 600 / 900 parallel runs | 1 lost the whole
tail in each batch | 0 of 900 |
| new deterministic test | fails (`b'' == b'the last line before
shutdown\n'`) | passes |
| `test_shutdown_exit_still_relays_the_mirrored_stderr_tail`, `--count
40 -n 16` | 1 failed of 40 | 240 of 240 passed (`--count 80 -n 16`,
three times) |

- `test_inference_worker_shutdown_exit.py` and
`test_inference_worker_stderr_tail.py`: 77 passed.
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T12:08:54.456214Z 94b6c7a Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0909a4bfd5

ℹ️ 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".

parsed = _clef_question(question)
internal = {"t": parsed["type"], "crit": parsed.get("criteria")}
else:
internal = _internal(question)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serialize Laya initialization before checking rows concurrently

On the torch Laya path with Hub/S3 data, this _internal() call now runs in the dataset thread while FastDecisionModel.from_pretrained() may also make its first _laya() call. _laya() publishes unsloth._laya in sys.modules before exec_module() finishes and returns that module to another caller without waiting. Either thread can therefore receive a partially initialized module and raise AttributeError on agent or common, aborting a valid training run. Previously, model loading completed before row conversion began. Keep this schema-only precheck independent of the Laya import, or serialize its first initialization.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only reachable when a Hub dataset's rows check and the model load first import Laya in the same few milliseconds inside one job; jobs run in their own spawned process and local datasets wait for the check first, so this timing-only window is out of scope here.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62485c13a8

ℹ️ 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".


# A daemon thread, so bad rows end the run without waiting out the model download.
context = copy_context()
thread = account_thread(target = context.run, args = (run,), daemon = True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cancel the inner checkpoint download on early dataset failure

When Hub/S3 rows are rejected while an uncached Hub checkpoint is downloading, making this outer thread a daemon does not stop the download. snapshot_download() uses a ThreadPoolExecutor, whose workers are joined during interpreter shutdown even when created by a daemon thread. Consequently, the spawned Studio worker can report the dataset error but remain alive and continue downloading. TrainingBackend.is_training_active() still treats that live process as active, blocking retries until the download finishes or the default 120-second terminal watchdog fires. Explicitly cancel the download or terminate the failed worker promptly rather than relying on daemon=True.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataset error is still reported and the run ends; the leftover download only delays shutdown, and main ran the full download before reading rows at all, so this is no worse than main.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: eee20674c6

ℹ️ 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".

@danielhanchen danielhanchen self-assigned this Nov 4, 2026
…point download running

Interpreter shutdown joins the hub download's executor threads, so the worker kept
downloading after reporting the error and refused the next run until the parent's
watchdog killed it.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7fecbb2378

ℹ️ 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".

… ended

The in-process MLX adapter passes a plain queue from a thread, so ending the download
there would kill the host. A stall queued behind an error or completion no longer
triggers the Xet-to-HTTP respawn.

[skip ci]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7fecbb2378

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 4, 2026
@unslothai unslothai deleted a comment from NilayYadav Nov 4, 2026
@unslothai unslothai deleted a comment from NilayYadav Nov 4, 2026
@unslothai unslothai deleted a comment from NilayYadav Nov 4, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 5d89708caa

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

pre-commit.ci run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 94b6c7a682

ℹ️ 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".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 4, 2026
@danielhanchen
danielhanchen merged commit 096fa32 into unslothai:main Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants