Skip to content

Prefetch the models on a CPU lane, co-schedule the small legs, reorder around both - #9568

Closed
danielhanchen wants to merge 7 commits into
ci/kaggle-merge-studiofrom
ci/kaggle-prefetch
Closed

danielhanchen wants to merge 7 commits into
ci/kaggle-merge-studiofrom
ci/kaggle-prefetch

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Three changes to one schedule, measured rather than assumed.

PREFETCH. Downloading a model is CPU and network work that today holds a T4
idle for its whole duration. A lane in the driver's own interpreter warms the
HF cache from t=0: gpt-oss first (~12 GB, and the leg the order is built
around), then the small model. It takes no card and no virtualenv, so it starts
at t=0 rather than after a venv build, and it deliberately does not set HF_HOME
because the legs read the image default and the point is to land where they
read.

It is not a correctness mechanism. A failed prefetch is a no-op: the leg
downloads the model itself exactly as before, so the cost is seconds. Retries
are a watchdog rather than an except: Xet handles 408/429/5xx itself with
backoff (5 attempts, 3s base, a 6 minute cap per delay), so a stalled transfer
sits inside one call for minutes without raising. Each attempt gets a
wall-clock budget and the last one sets HF_HUB_DISABLE_XET to fall back to
classic HTTP, because retrying a stalling transport is how a retry loop eats
the session.

ORDER. gptoss moves to position three, first pick of the second wave.
Simulated over every permutation against the durations measured on run
32611343797, across a range of the unknown gpt-oss download time D:

canary, control, gptoss, frontier prefetch worst 528.1s mean 504.1s
gptoss, frontier, canary, control none worst 563.1s mean 563.1s
gptoss, frontier, canary, control prefetch worst 603.1s mean 603.1s
frontier, canary, control, gptoss prefetch worst 651.1s mean 585.2s

Prefetching without reordering is a regression: gptoss starts at t=0 so there
is no window in front of it. Putting gptoss last is worse still for any D under
~120s, since ending on the longest leg idles the other card for its whole
duration. The chosen order is never worse than today at any D tested, and
degrades to ~568s if the prefetch fails outright.

CO-SCHEDULING. The peaks in that run's evidence: canary, control and frontier
each reserve 0.70 GB of a 14.56 GB card; gptoss reserves 12.78. One leg per
card was leaving a card 95% empty for three quarters of the run. Cards now
admit legs against a 13.0 GB budget, so two small legs share and gptoss is
alone by arithmetic rather than by a special case. Capped at two per card
because VRAM is not the scarce resource: a session has 4 vCPUs and a leg is
~87% install, import and download.

That raises the live-virtualenv ceiling from 2 to 4, and each carries its own
torch and NVIDIA runtime. /kaggle/working is 19.5 GB and is also the artifact
Kaggle ships home, so the venvs move to the ~1 TB overlay; only evidence stays
where Kaggle collects it. Four torch trees would not have fit, and the failure
would have arrived as an install dying midway for reasons that look nothing
like a full disk.

Studio's two models were being pulled inside run_studio_gpu.py, which is the
TEST half, so the merged kernel hid its clone, pip and browser and then paid
full price for its downloads with both cards idle. They move to the install
cell, under Studio's own HF_HOME, read off the payload's own argv rather than a
second copy of the defaults.

The job summary gains a prefetch table: bytes, download seconds, achieved MB/s
and the transport actually used, per repo. That is the instrument. The gpt-oss
download time has never been measured -- an earlier "~282s" was subtraction --
and it is what decides whether this reorder paid for itself.

Guards, each mutation-tested by reintroducing the bug: no card is asked to hold
more than 13.0 GB; two small legs really do share one (every other guard is a
bound satisfied by co-scheduling nothing); gptoss never shares; the admission
ledger balances; virtualenvs are never built on the artifact volume, checked at
creation because teardown hides where they were built; the prefetch lane takes
no card; it does not redirect HF_HOME; a failing prefetch does not fail the
kernel; the last attempt falls back to classic HTTP; the declared VRAM matches
the peaks committed in measured_vram.json; the report table is wired into the
summary and not merely rendered.

Stacked on #9561; base will retarget to main once that merges.

…r around both

Three changes to one schedule, measured rather than assumed.

PREFETCH. Downloading a model is CPU and network work that today holds a T4
idle for its whole duration. A lane in the driver's own interpreter warms the
HF cache from t=0: gpt-oss first (~12 GB, and the leg the order is built
around), then the small model. It takes no card and no virtualenv, so it starts
at t=0 rather than after a venv build, and it deliberately does not set HF_HOME
because the legs read the image default and the point is to land where they
read.

It is not a correctness mechanism. A failed prefetch is a no-op: the leg
downloads the model itself exactly as before, so the cost is seconds. Retries
are a watchdog rather than an except: Xet handles 408/429/5xx itself with
backoff (5 attempts, 3s base, a 6 minute cap per delay), so a stalled transfer
sits inside one call for minutes without raising. Each attempt gets a
wall-clock budget and the last one sets HF_HUB_DISABLE_XET to fall back to
classic HTTP, because retrying a stalling transport is how a retry loop eats
the session.

ORDER. gptoss moves to position three, first pick of the second wave.
Simulated over every permutation against the durations measured on run
32611343797, across a range of the unknown gpt-oss download time D:

  canary, control, gptoss, frontier   prefetch   worst 528.1s   mean 504.1s
  gptoss, frontier, canary, control   none       worst 563.1s   mean 563.1s
  gptoss, frontier, canary, control   prefetch   worst 603.1s   mean 603.1s
  frontier, canary, control, gptoss   prefetch   worst 651.1s   mean 585.2s

Prefetching without reordering is a regression: gptoss starts at t=0 so there
is no window in front of it. Putting gptoss last is worse still for any D under
~120s, since ending on the longest leg idles the other card for its whole
duration. The chosen order is never worse than today at any D tested, and
degrades to ~568s if the prefetch fails outright.

CO-SCHEDULING. The peaks in that run's evidence: canary, control and frontier
each reserve 0.70 GB of a 14.56 GB card; gptoss reserves 12.78. One leg per
card was leaving a card 95% empty for three quarters of the run. Cards now
admit legs against a 13.0 GB budget, so two small legs share and gptoss is
alone by arithmetic rather than by a special case. Capped at two per card
because VRAM is not the scarce resource: a session has 4 vCPUs and a leg is
~87% install, import and download.

That raises the live-virtualenv ceiling from 2 to 4, and each carries its own
torch and NVIDIA runtime. /kaggle/working is 19.5 GB and is also the artifact
Kaggle ships home, so the venvs move to the ~1 TB overlay; only evidence stays
where Kaggle collects it. Four torch trees would not have fit, and the failure
would have arrived as an install dying midway for reasons that look nothing
like a full disk.

Studio's two models were being pulled inside run_studio_gpu.py, which is the
TEST half, so the merged kernel hid its clone, pip and browser and then paid
full price for its downloads with both cards idle. They move to the install
cell, under Studio's own HF_HOME, read off the payload's own argv rather than a
second copy of the defaults.

The job summary gains a prefetch table: bytes, download seconds, achieved MB/s
and the transport actually used, per repo. That is the instrument. The gpt-oss
download time has never been measured -- an earlier "~282s" was subtraction --
and it is what decides whether this reorder paid for itself.

Guards, each mutation-tested by reintroducing the bug: no card is asked to hold
more than 13.0 GB; two small legs really do share one (every other guard is a
bound satisfied by co-scheduling nothing); gptoss never shares; the admission
ledger balances; virtualenvs are never built on the artifact volume, checked at
creation because teardown hides where they were built; the prefetch lane takes
no card; it does not redirect HF_HOME; a failing prefetch does not fail the
kernel; the last attempt falls back to classic HTTP; the declared VRAM matches
the peaks committed in measured_vram.json; the report table is wired into the
summary and not merely rendered.

@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: 1e5cb2b8e4

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

Comment on lines +855 to +856
with pending_lock:
_admit(gpu_index, name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Admit seeded legs before launching secondary workers

With the default two-GPU order, GPU 1's seeded control worker sleeps for five seconds while its unseeded secondary worker can immediately reserve and start gptoss. When the seed wakes, _admit() rejects control because 12.78 + 0.70 GB exceeds the budget, but this return value is ignored and control runs anyway, putting both legs on the same card and risking the exact OOM the admission ledger is intended to prevent. Reserve each seed before secondary workers can consume the queue, or do not run a seed whose admission failed.

Useful? React with 👍 / 👎.

# transport the hub chose (Xet when the repo has Xet metadata and
# hf_xet is installed, which since huggingface_hub 0.32 is the default
# and is therefore live here whether or not anyone chose it).
_plan = (False, False, 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 Leave time for the forced HTTP attempt

When Xet stalls—the scenario this watchdog is designed to handle—the default 900-second first attempt plus backoff leaves roughly 897 seconds for the second auto attempt, which then consumes the remainder of the 1800-second total deadline. The next loop iteration exits before the third, HTTP-disabled attempt starts, so the advertised transport fallback is unreachable under a sustained stall. The timeout allocation needs to reserve a meaningful budget for the final HTTP attempt.

Useful? React with 👍 / 👎.

Comment on lines +96 to +99
for dirpath, _dirnames, filenames in os.walk(os.path.join(root, "hub", folder)):
for name in filenames:
try:
total += os.stat(os.path.join(dirpath, name)).st_size

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 Count cached model bytes only once

On the standard Hugging Face cache layout used by Kaggle, model data exists as files under blobs/ and as symlinks under snapshots/. Walking the entire repository directory and calling os.stat() follows those symlinks, so a freshly downloaded blob is generally counted once directly and again through its snapshot link; the reported GB and MB/s can therefore be inflated by about 2×, corrupting the measurement used to evaluate this scheduling change. Count unique inodes or only the blob files instead.

Useful? React with 👍 / 👎.

shimmyshimmer and others added 3 commits August 23, 2026 23:28
…ore any worker sees it

Run 32667451396 went green while doing three things wrong.

The prefetch fetched unsloth/gpt-oss-20b. That is an MXFP4 checkpoint, sm_75
cannot read MXFP4, and unsloth redirects to -unsloth-bnb-4bit at load time, so
55.1 GB was downloaded that no leg ever opens while the leg fetched the real
one for itself. The guard that should have caught this compared the list
against the payload's DEFAULT_MODEL, which is the name asked for and not the
one loaded, so it agreed with the bug. LOAD_REDIRECTS now records the
redirect, the guard applies it, and a second assertion pins that the redirect
being claimed is one the payload actually shows.

The prefetch also had no allow_patterns, so Qwen3.5-2B-GGUF came down entire:
69.1 GB of every quant in the repo to serve the one UD-Q4_K_XL file Studio
loads. The variant is read off argv next to the model names, for the same
reason they are - a hardcoded quant would filter on the wrong one the moment a
dispatch overrode it. The glob is loose at both ends because a split GGUF is
named ...UD-Q4_K_XL-00001-of-00002.gguf.

Together that is ~128 GB fetched to serve ~14 GB of weights on a 4-core box,
and it shows up in the durations: the Studio install went 258s to 673.5s and
the legs went 180-384s to 691-780s.

Third, control and gptoss shared one card for 691s - 13.48 GB against a 13.0 GB
budget. A seed's seat was taken inside its own worker, AFTER a 5s start
stagger, so card 1 sat unreserved while a free worker looked at it, saw an
empty card and put gptoss there. When the seed worker woke, _admit correctly
refused and the caller discarded the answer. Seats are now taken before any
worker thread exists.

test_no_card_is_ever_asked_to_hold_more_than_it_has asserts that exact budget
and passed throughout, because with default stub durations every leg finishes
inside the 5s stagger and no overlap is ever recorded. The new guard picks
durations that hold the window open instead.

Prefetch order goes Qwen-first here too. Three legs and Studio's training
assertion want the small model and the first of them starts at t=0, so it is
the only fetch with no lead time in front of it.
The list moved to Qwen-first but the comment above it still argued for
gpt-oss-first, which is the version of this that gets 'fixed' back by the next
reader who trusts the prose over the code.

@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: 296205fc47

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

Comment on lines +145 to +146
if disable_xet:
os.environ["HF_HUB_DISABLE_XET"] = "1"

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 Apply the HTTP fallback in a fresh Hub process

When the first attempt has imported huggingface_hub, the library has already cached HF_HUB_DISABLE_XET in its constants module, so changing only os.environ for the third attempt does not disable Xet. Thus, even when the third attempt is reached—for example, after two fast failures—it can retry the same Xet transport while being reported as http; run that attempt in a fresh process with the variable set before import, or update the library's cached setting explicitly.

Useful? React with 👍 / 👎.

@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: b922c9c855

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

Comment on lines +171 to +172
variant = picked["--chat-variant"]
chat = (picked["--chat-model"], [f"*{variant}*"]) if variant else picked["--chat-model"]

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 Make the prefetch variant filter case-insensitive

When --chat-variant is supplied with different casing (for example q8_0), Studio accepts it because its GGUF selection paths normalize variants and filenames to lowercase, but this generated Hugging Face glob preserves the caller's casing. On Kaggle's Linux filesystem, allow_patterns glob matching is case-sensitive, so the lowercase pattern misses an uppercase Q8_0 filename, snapshot_download can report success after downloading no weights, and the model is downloaded later during the GPU test phase instead of the install prefetch.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

--per-run-timeout 3900 \

P2 Badge Keep the payload deadline below the Kaggle session ceiling

When the new Studio install lane takes more than roughly 3,400 seconds, it can still be considered healthy under this 3,900-second papermill timeout, but the GPU test half then starts too late to finish before the launch step's unchanged 3,600-second Kaggle ceiling. The launcher explicitly describes --kernel-timeout-sec as Kaggle's hard session ceiling (.github/scripts/kaggle_t4_ci/launch.py:1079-1083) and passes it to kaggle kernels push -t (:533-545); for example, a 3,500-second install leaves only about 100 seconds for the normally ~200-second test, producing missing Studio coverage instead of the intended report. Increase the session ceiling to cover the serial install/test schedule or lower/budget the child phases accordingly.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 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-09-01T01:53:56.545190Z 0ff0b64 New commits
ℹ️ 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: 0ff0b64bdf

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

# it stops a future second kernel prefetching a model it will never
# load -- which would be pure network cost, on a lane whose entire
# justification is that it is free.
prefetch_repos = () if args.no_prefetch else PREFETCH_REPOS,

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 Restrict prefetching to models in the selected plan

When the supported --legs debugging path builds a narrowed kernel such as --legs control, this unconditional argument still starts the full PREFETCH_REPOS lane, including the roughly 12 GB gpt-oss checkpoint that no selected payload will load. Conversely, a gptoss-only run first downloads the unrelated Qwen model, consuming its useful prefetch window and competing with the leg's own download. Derive the prefetch list from names (in particular, include the gpt-oss repository only when that leg is present) rather than enabling the global list for every non---no-prefetch build.

Useful? React with 👍 / 👎.

Comment on lines +455 to +460
prefetch = _prefetch_builder().prefetch_cell(
_models_from(payload_args),
hf_home = None,
attempt_timeout = 600,
total_timeout = 1200,
)

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 Add prefetch metrics to the standalone Studio summary

When Studio runs through the standalone kaggle-t4-studio-gpu-ci.yml workflow, this new prefetch emits its records into kernel.log, but that workflow invokes kaggle_studio_ci/report.py, while only kaggle_t4_ci/report.py appends prefetch_table to its summary. Consequently successful, failed, and accidentally empty Studio prefetches are invisible in the normal standalone job summary, defeating the instrumentation intended to show whether moving these downloads helped; have the Studio reporter call the shared prefetch renderer it already loads.

Useful? React with 👍 / 👎.

Comment on lines +217 to +219
print(f"{PREFETCH_SENTINEL} " + json.dumps({{
"repo": repo, "ok": bool(ok), "seconds": seconds,
"download_seconds": download_seconds, "bytes": moved,

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 Identify the cache lane in each prefetch record

In the default merged --with-studio kernel, both prefetch lanes download unsloth/Qwen2.5-0.5B-Instruct: the T4 lane writes to the image cache while the Studio lane writes to its private HF_HOME. These records contain only the repo name, and the lanes run concurrently, so the summary can show two indistinguishable Qwen rows in nondeterministic order; a reader cannot tell which cache produced either byte count or timing and therefore cannot evaluate either optimization. Include a lane/cache identifier in the emitted record and render it in the table.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member Author

Closing this as absorbed into #9700, not as rejected. Everything here is landing; it is landing from one branch instead of four.

Why

ci/kaggle-latest-compile (#9700) carries this PR's content already. Checked three ways rather than by reading the titles:

Line-level check of each PR's own payload against #9700's tree: 634/657 added lines for #9561, 1198/1236 for #9568, 2088/2135 for #9596. Every miss was read individually and each is a line #9700 edited further; no concept is absent (AFTER_GPU, CPU_LANE, MAX_LEGS_PER_CARD, _ov_dir, --chat-model / --train-model, export_gguf, studio_concurrent, SMOKE_FILES, PREBUILT_MARKER all present).

The one thing that was not absorbed, and now is

e1873c1d on ci/kaggle-studio-concurrent corrected the GRPO note from "one in four" to the measured 4 in 9, and #9700 still had the stale text. Carried over in beae2337, with one sentence deliberately dropped: the original ends "a nightly kernel is where this belongs, and that scheduling does not exist yet", which is false on #9700 because that branch built the nightly and dispatches grpo,multi_gpu on the schedule.

Landing these separately would mean resolving the same 15 files twice from divergent copies, and the merge could silently reinstate the symlink-following _repo_bytes that reports roughly 2x the bytes actually transferred. One carrier avoids both.

The branch is not deleted, so nothing here is lost if #9700 has to be split back up.

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