Skip to content

Studio: persist local-checkpoint tier probe verdicts across workers - #17496

Merged
danielhanchen merged 3 commits into
mainfrom
perf/r34-tier-probe-verdict-cache
Nov 12, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
perf/r34-tier-probe-verdict-cache

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Studio picks the transformers tier for a model inside the worker it spawns for that model: activate_transformers_for_subprocess in the inference, export, training and token preview workers. _probe_tier keeps its verdicts in the in-process dict _probe_tier_cache, but that dict is always empty in a new worker. A local checkpoint whose config.json was saved by transformers 5.x, and whose model_type the default tier already knows (for example llama), reaches _probe_tier(..., include_default=True, floor="default") on every load. That spawns python -c to import transformers and run AutoConfig.from_pretrained, which costs 3.5 to 4 s. These checkpoints are common: Studio's merged 16-bit exports (save_pretrained_merged) and full fine-tune outputs (trainer.save_model) both write a config.json stamped with the default transformers version, which is 5.5.0 on Python 3.10 and newer. So every chat load, export or further training run of such a model paid this probe again, even though the answer had not changed. LoRA outputs are not affected, because PEFT writes only adapter_config.json, and Hub ids are left as they are.

Change

  • studio/backend/utils/transformers_version.py: _probe_tier also keeps verdicts on disk in <studio>/cache/transformers_tier_probe.json, but only for local directories.
  • The key is the sha256 of the config.json bytes, the probe mode (floor, include_default) and the tier walk order. The entry also records the installed transformers version of every tier the walk probed. For a sidecar that is the transformers-*.dist-info version in its target dir. For the default tier it is importlib.metadata.version("transformers"), which does not import transformers. On lookup each recorded version is read again. If a walked tier was upgraded or removed, or the config was rewritten, the model is probed again. A pinned latest sidecar changes the walk order, so it changes the key.
  • Only a verdict the probe settled is stored: a tier that parsed the config, or the floor after every tier failed to parse it. Results that are cached in memory today are the only ones persisted. Transient results (None), walks with a skipped tier, UNSLOTH_DISABLE_TIER_PROBE, and walks where any tier's version cannot be read are never stored.
  • config.json is hashed again after the probe, and the verdict is stored only if the hash is unchanged.
  • Writes go through a temp file and os.replace. The file holds at most 256 entries, oldest dropped first. A missing, corrupt or unreadable file reads as empty, so the probe runs as today. Two workers writing at once can drop each other's new entry, which only means one more probe later.
  • A cached latest verdict is ignored when that tier is disabled, needs repair or is unpinned, the same rule the in-memory cache follows.
  • A disk hit is used only if the cached tier's own ensure_fn still returns True, as a live probe requires. A damaged sidecar that cannot be repaired right now (offline, rebuild lock held, latest inside a worker) therefore walks on to the next tier as today instead of failing activation.
  • Walk order, ensure_fn calls, skipped tier handling and floor rules are unchanged.

Results

get_transformers_activation_tier on a local llama config.json with transformers_version: 5.1.0. Each run is a fresh Python process, the way a worker starts, sharing one Studio home per arm:

Run main this PR
First load 3.89 s 3.93 s
Second load, run 1 4.08 s 0.025 s
Second load, run 2 3.55 s 0.032 s
Second load, run 3 3.56 s 0.018 s

The tier is default in every run, on both sides.

Tests

  • New studio/backend/tests/test_transformers_tier_probe_disk_cache.py (21 cases). A second process reuses a default, an escalated (550) and a floor verdict without probing. A rewritten config, an upgraded sidecar that was walked, or an upgraded default transformers triggers a new probe, while an upgrade to a tier the walk never reached does not. A floor 530 caller does not reuse a default verdict. Transient results, skipped tiers, a sidecar with no readable version, Hub ids, a config rewritten during the probe and UNSLOTH_DISABLE_TIER_PROBE are never persisted. A cached tier whose sidecar is unavailable walks on to the next tier. A corrupt or wrong-shape cache file falls back to probing and is replaced. The file stays bounded. 10 of these fail on main (the ones that need the disk cache), and the 10 that check behaviour that must not change pass on both.
  • test_transformers_version.py, test_transformers_version_optional_tiktoken.py and test_transformers_latest.py: 484 passed on main and 484 passed on this branch, with no failures on either side; with the new file, 505 passed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-12T13:55:29.541116Z
We couldn’t complete this review. Comment @codex review to try again.
eb9e003 Draft marked ready
ℹ️ 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

Copy link
Copy Markdown

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

Reviewed commit: 700e620c68

ℹ️ 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 Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 03d002aa26

ℹ️ 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 marked this pull request as ready for review November 12, 2026 13:55
@danielhanchen
danielhanchen merged commit 82f21d1 into main Nov 12, 2026
@danielhanchen
danielhanchen deleted the perf/r34-tier-probe-verdict-cache branch November 12, 2026 13:55
danielhanchen added a commit that referenced this pull request Nov 12, 2026
…#17592)

## Summary

`Repo tests (CPU, studio)` fails on main since #17213, and on every PR
based on it (seen in staging runs for #17496 and #17557):

```
tests/studio/test_desktop_reliability_frontend_contract.py::test_fixed_sheets_start_below_the_custom_titlebar
E   assert 'set("--studio-custom-titlebar-height", usesCustomTitlebar ? "34px" : null)' in '...'
```

#17213 (F11 fullscreen) hides the custom titlebar in fullscreen, so the
`<html>` mirror in `provider.tsx` now reads:

```ts
const customTop = customTitlebarHidden ? "0px" : "34px";
set("--studio-custom-titlebar-height", usesCustomTitlebar ? customTop : null);
```

That is correct: in fullscreen the titlebar band is gone, and portalled
sheets should start at the top edge. The test pinned the old line
character for character, so it failed on a change that keeps everything
it was written to protect. The mirror is still there, and it still gives
34px whenever the titlebar shows.

## Change

`tests/studio/test_desktop_reliability_frontend_contract.py`:

- `_mirrored_titlebar_heights()` finds the
`set("--studio-custom-titlebar-height", usesCustomTitlebar ? <value> :
null)` call and resolves `<value>`. A string literal is read directly; a
local such as `customTop` is read from its `const` declaration.
- `test_fixed_sheets_start_below_the_custom_titlebar` now asserts that
the mirror exists, that it yields `34px`, and that it yields nothing
other than `34px` or the fullscreen `0px`. The rest of the test is
unchanged.
- `test_the_titlebar_mirror_reader_follows_a_local` covers the reader:
the old literal form, the new local form, and a different property that
must not match.

No app code changes.

## Testing

- `tests/studio/test_desktop_reliability_frontend_contract.py`: 46
passed (1 failed on main).
- With the mirror line removed from `provider.tsx`, the test fails. With
the shown height changed from `34px` to `30px`, it also fails.
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.

1 participant