Skip to content

Studio: limit model download speed - #16819

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
NilayYadav:download-speed-limit
Nov 6, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
NilayYadav:download-speed-limit

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Model downloads always ran at full line speed, which can crowd out everything else on a shared or metered connection.

Settings > General > Downloads now has a "Download speed limit" field in Mbit/s. It is empty by default, which means no limit. While a limit is set, downloads go over HTTPS, because Xet transfers cannot be paced, and the transport row says so. This covers the Model hub and picking a model in chat, which downloads it the same way first. A file over the 50 GB HTTPS ceiling still uses Xet, without the limit.

Fixes #15603

Screenshots

Before (main) After (this PR)

Before / after (isolated Studio installs, merge base vs PR head)

Settings > General > Downloads. BEFORE has only the transport row; AFTER has the Mbit/s field, and after saving 8 the transport row says downloads use HTTPS while a speed limit is set (API read back: {"mbps": 8.0}).

Settings Downloads before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-06T09:35:54.843742Z cf4eae1 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[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: f19bdc3e9f

ℹ️ 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 5, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 6, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 6, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 6, 2026

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

ℹ️ 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 +265 to +266
if download_registry.http_size_ceiling_reason(largest_file_bytes) is None:
return (False, "HTTP (download speed limit)")

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 Preserve the Xet exception when the size probe fails

If the initial file-size probe times out, _repo_siblings() returns an empty listing and largest_file_bytes becomes None. This condition treats that unknown size as HTTP-eligible and overrides even an explicit Xet request. For a download containing a file above the HTTPS ceiling, the worker can subsequently recover metadata but then fail because Hugging Face refuses that file over HTTP; register_worker() only retries downloads that started on Xet. Resolve the size before committing to HTTP, or retry ceiling failures on Xet, so a transient metadata failure does not defeat the large-file exception.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Below the bar: it needs a transient metadata failure at start and a single file above the 50 GB HTTPS ceiling in the same download. With the size known (the normal case) the exception holds, and a user hitting it can retry once metadata answers.

Comment on lines +130 to +134
print(
"download speed limit needs huggingface_hub 1.x; downloading at full speed",
file = sys.stderr,
)
return

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 Reject limits that the installed Hub version cannot enforce

On supported Python 3.9 Studio installations, studio/backend/requirements/studio.txt pins huggingface-hub==0.36.2, which lacks set_client_factory, so enabling a limit always reaches this unthrottled fallback. However, the settings endpoint still accepts the limit and capabilities report speed_limited: true, leaving the UI claiming that a cap is active while downloads consume full bandwidth. Support pacing through the legacy requests backend, or expose the unsupported capability and reject or disable the setting rather than acknowledge an unenforced limit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not reachable: Studio cannot be installed on Python < 3.11 (studio.txt pins usearch==2.26.6, which requires 3.11, and matplotlib==3.10.9, which requires 3.10), so the huggingface_hub 0.36.2 marker never resolves inside a Studio venv and this fallback cannot run.

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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: cf4eae159b

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

RioPlay commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to the speed-limit handling added here: a settings-read exception can be mistaken for an intentionally disabled limit.

Before: the getter at the reviewed base revision returns None after a read exception, allowing transport selection and worker launch to proceed without the configured cap.

With #17645: an unreadable setting stops the operation with a sanitized retryable error, prevents worker creation, and releases the job claim for recovery. Normal readable settings keep their existing behavior. The PR links committed regression tests and gives the exact command to run them.

Live testing with the patch installed still produced reduced responsiveness and intermittent connectivity dropouts during an uncapped Xet download. A short capped HTTP test remained responsive, but its settings and duration differed. This is not a controlled before/after performance comparison or evidence that the patch resolves Xet-related slowdowns.

The PR now records the test procedure and limitations. A 1 Gbit/s download is at most 125 MB/s before overhead, so bandwidth alone does not prove a disk bottleneck. No disk benchmark or private diagnostic upload was performed.

danielhanchen pushed a commit that referenced this pull request Nov 14, 2026
A temporary settings-read error can make Studio start a download without
its saved bandwidth limit. This PR prevents that specific failure; it
does not throttle normal Xet downloads or claim to fix their
responsiveness problems.

### Before and after

**Before:** the [settings
getter](https://github.com/unslothai/unsloth/blob/3221ed08b0846c7a8d04415752abaa58ffb0864b/studio/backend/utils/download_speed_limit.py#L28)
catches a read exception and returns `None`. The [download
lifecycle](https://github.com/unslothai/unsloth/blob/3221ed08b0846c7a8d04415752abaa58ffb0864b/studio/backend/hub/services/download_lifecycle.py#L259)
interprets that as an intentionally disabled limit, so a configured cap
can silently disappear.

**With this patch:** an unreadable setting stops the download with a
sanitized error and retry guidance. Initial transport selection returns
HTTP 503. If a later read fails during launch or a transport retry, no
downloader is spawned and the job claim is released so the operation can
be retried after recovery.

**When settings can be read:** the configured limit, intentionally
disabled limit, normal transport selection, and existing oversized-file
Xet exception retain their prior behavior. This patch does not change
Xet concurrency, memory budgets, or native transfer pacing.

### Reproduction and regression checks

The [committed
tests](https://github.com/unslothai/unsloth/blob/56ac0e00d6848ac07b616d3b04a3b23b18394980/studio/backend/tests/test_download_speed_limit.py#L60)
simulate a settings-read exception and check transport selection,
prevention of worker creation, claim cleanup, sanitized errors, and
recovery. They also check that a normal read returns the configured
limit. No private logs or model download are needed.

From the repository root, with backend test dependencies installed:

```sh
PYTHONPATH=studio/backend python -m pytest -q studio/backend/tests/test_download_speed_limit.py
```

Local result at `56ac0e00d6`: **37 passed**. This is a local result, not
a claim that upstream CI has passed.

### Desktop test procedure and observations

With the patched production modules installed:
1. In a separate process importing the installed modules, inject a
settings-read exception. Transport selection returns 503, no worker
starts, and normal reads recover after the injected failure is removed.
This fault was not injected into the running desktop app.
2. In Studio, resume a GGUF download using HTTP with an 8 Mbit/s cap for
about 45 seconds, interact with the download panel, then cancel. The
panel remains responsive and cancellation completes.
3. Download the same variant through uncapped Xet into a fresh folder on
the same drive for about six minutes. Progress passes halfway. Overall
computer responsiveness degrades and intermittent connectivity dropouts
are reported in another app, without a full lockup. Separate short HTTPS
probes continue succeeding; those probes do not measure the other app's
existing connection and do not disprove the reported dropouts. The
download was stopped before completion.

The earlier unpatched experience involved more severe lockups and
connectivity problems that stopped after the Studio-spawned Python
processes were terminated. That is a reported observation, not a matched
baseline run. The patched test still showed degradation. Differences in
cache state, duration, transport, and bandwidth settings mean the change
in severity cannot be attributed to this patch.

### Interpretation and remaining scope

A 1 Gbit/s transfer is at most 125 MB/s before protocol overhead.
Network traffic approaching link capacity therefore does not, by itself,
establish that the disk's transfer-rate limit was exceeded. Passive disk
counters showed queued I/O, but no disk benchmark was performed and the
cause of the responsiveness degradation remains unresolved.

There is no evidence that the settings-read failure or a bypassed saved
cap caused the original incident. This PR fixes the independently
reproducible bandwidth-policy failure. Investigation of Xet-related
slowdowns and intermittent connectivity remains separate.

Follow-up to #16819; related to #15603. No personal logs, local paths,
machine identifiers, or configuration databases are attached.
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.

[Feature] Limit model downloading speed

3 participants