Repository navigation
Unsloth Studio: Cosmos3 guardrail refusal names the gated nvidia/Cosmos-1.0-Guardrail repo - #16742
Conversation
…os-1.0-Guardrail repo Installing cosmos-guardrail as the refusal told users to still failed the load with a raw 401, because the guardrail downloads its weights from a gated repo. The refusal now says so, and a gated refusal of that download at load becomes the same guidance instead of the raw Hub error.
… user takes Drops the model_index.json internals and the bare "Studio", and shows hf auth login without backticks, which the load toast printed literally.
|
Codex is clean at this head ( Fork mirror CI at |
…rdrail download, shorten its refusals [skip ci]
[skip ci]
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3bc34b3b6
ℹ️ 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".
| module.snapshot_download = functools.partial(download, token = token) | ||
| try: | ||
| yield | ||
| finally: | ||
| module.snapshot_download = download |
There was a problem hiding this comment.
Keep guardrail tokens local to each load worker
On a Cosmos3 cancel-and-reload, VideoBackend.unload() allows a replacement load before the old from_pretrained worker exits. Both workers then modify this process-global function: if A exits before B, A restores the original downloader while B is still running, and B subsequently restores A's token-bound partial instead of the original. A two-worker reproduction confirmed that this leaves A's Settings token active after both scopes finish, allowing a later no-token load to use another account's credential. Make token dispatch load-local, or serialize the entire scope including no-token loads.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0e5e559: one permanent wrapper reads each load's token from a context variable (per-thread per the contextvars docs), so overlapping loads cannot restore each other's patch; test_overlapping_guardrail_loads_keep_their_own_tokens reproduces the leak on the previous version.
… variable so overlapping loads cannot leak it [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
… lint passes on main (#17041) ## Summary `Lint CI / Source lint` fails on main at its "No new risky loader call sites" step, so every PR based on main fails it too. For example, a staging run of #16965, which does not touch this file: ``` 1 risky loader call site(s) not in the baseline: studio/backend/core/inference/video_cosmos3.py:159 [dynamic-import] import_module ``` #16742 (the Cosmos3 guardrail refusal message) added `guardrail_hub_token`. It wraps the guardrail package's `snapshot_download` so each load sends its own token. It imports that module with `importlib.import_module(f"{GUARDRAIL_PACKAGE}.{GUARDRAIL_PACKAGE}")`. `scripts/lint_risky_loaders.py` flags any `import_module` whose name it cannot read as fixed, and an f-string reads as dynamic even though `GUARDRAIL_PACKAGE` is the constant `"cosmos_guardrail"`. The import itself is safe and the PR's behaviour is correct. Only the form trips the guard. ## Change `studio/backend/core/inference/video_cosmos3.py`: the import names the module outright, `importlib.import_module("cosmos_guardrail.cosmos_guardrail")`. That is the same module, and this is the lint's first suggested remedy ("load from a written-out name"). It keeps the baseline free of an entry that would have to be justified. No behaviour changes. ## Testing | | `python scripts/lint_risky_loaders.py` | |---|---| | main | exit 1, the site above | | this branch | exit 0, `117 risky loader call site(s), all recorded` | `studio/backend/tests/test_video_cosmos3.py`, which covers `guardrail_hub_token` through a `cosmos_guardrail.cosmos_guardrail` module stub: 195 passed.
…om the Hub (unslothai#16743) ## What Lists `nvidia/Cosmos3-Nano` in the Unsloth Studio Video page model picker next to Cosmos3-Edge, and makes the Model hub treat it as a Video page model instead of marking it "May not be supported". ## Why The backend fully supports Nano (unslothai#14554), but the picker and Hub only listed Edge, so the only way to load Nano was typing its repo id. Nano is the larger, higher-quality model and the only one with 720p. unslothai#14554 left Nano out on purpose: the installer didn't yet pin a diffusers that loads it (it does now, 0.42.1), and Nano's checkpoint turns on NVIDIA's guardrail, which Unsloth Studio doesn't install. So the row says what Nano needs: - a `needs cosmos-guardrail` chip on the row itself. The Video picker never draws a catalog description (its hover only shows the name and Hub link), so a description alone would have been invisible; - it's sized from its 32 GB of resident bf16 weights (backend `bf16_components_gb` 30.4 + 1.4, the same rule as Edge's 9 GB), so it's greyed out on hosts that can't hold it, with the reason on hover. That's the weights, not the render peak: on a 96 GB RTX PRO 6000 at `590119de67`, Nano peaked at 38.5 GB (832x480, 189 frames) and 49.7 GB (1280x720, 189 frames); - picking it without the guardrail is refused before anything downloads, with the install and opt-out steps. No backend change. ## Before / after Colab, Unsloth Studio at main `4ee2f916ca` vs this branch `f199960fd5`, searching "cosmos3" in the Video picker with the pointer on the Nano row. 96 GB RTX PRO 6000 (Nano fits):   Tesla T4, 15 GB (Nano greyed, hover says why):   Model hub, `nvidia/Cosmos3-Nano`:   Picking Nano with no `cosmos-guardrail` installed (before: Nano isn't in the list):  ## Memory and speed  What Nano actually uses, measured at `590119de67` (main; this PR doesn't touch the backend) on Colab. The picker's 32 GB is the resident weights. Without offload a render peaks at 36.0 to 62.4 GiB on the 96 GB card, depending on size and length. On a 24 GB L4, Unsloth Studio streamed the transformer and quantized it to int8, and Nano fit in 8.3 to 17.7 GiB at about 6 to 7 times the time. Each bar is drawn against its card's capacity. Not run: Nano on a T4, A100 80 GB and H100 (one A100 40 GB row only). ## Status Head `32b7696ab9`. Codex review is clean at `32b7696ab9` ([fork mirror](LeoBorcherding#772)). `32b7696` only rewords two comments in `model-catalog.ts`: at `f199960fd5` they said "Unsloth Studio", which `tests/studio/test_tauri_branding_contract.py` bans from frontend source (Unsloth Desktop displays itself as "Unsloth"); the fork mirror's CI caught it. New frontend tests: the chip test fails on `7cb1614043` and passes here; full frontend suite (14929 pass, 1 skipped), typecheck, catalog check and the branding contract pass. Screenshots were taken at `f199960fd5`; the comment-only change doesn't affect them. Not run: a Nano render (the backend path is unchanged); a 48 GB card, where Nano shows as fitting and 480p fits its measured peak but 720p at 189 frames (49.7 GB) may not; Nano with the guardrail installed, whose load currently stops on NVIDIA's gated guardrail repo, which unslothai#16742 addresses. ## Noticed, not changed - The Hub's "Likely fits · ~15.6 GB" chip is the generic 4-bit LLM estimate shown for every non-GGUF model, so it disagrees with the picker's 32 GB for any video model (Edge on main too). - A greyed row can still be clicked, and Nano then answers with the guardrail refusal rather than a fit warning. - The refusal toast (backend text) says bare "Studio" twice and quotes `model_index.json` internals. ## Before / after (maintainer check) Video page model picker searching "cosmos3", merge base vs this branch, two isolated Studio installs on a CPU-only host (picker listing only, no model loaded). After lists Cosmos3 Nano with its `needs cosmos-guardrail` chip beside Edge.  --------- Co-authored-by: Daniel Han <[email protected]>
The problem
Cosmos3-Nano only runs with NVIDIA's safety filter (the guardrail). When it's missing, Unsloth Studio says
pip install cosmos-guardrail. You do that, retry, and the load still fails, this time with a raw401 Cannot access gated repo. The guardrail downloads its own weights fromnvidia/Cosmos-1.0-Guardrail, a gated Hugging Face repo, and it callssnapshot_downloadwith no token. So the Hugging Face token saved in Unsloth Settings never reached that download. Only an ambienthf auth login/HF_TOKENdid, and on a multi-user install a managed account's load fell back to the owner's ambient login.The change
guardrail_hub_token) and cleared afterwards, including when the load fails. Other families are untouched.nvidia/Cosmos-1.0-Guardrail), the load shows the steps instead of the raw Hub error. Any other error, including a gate on a different repo, passes through unchanged.'nvidia/Cosmos3-Nano' needs NVIDIA's gated Cosmos guardrail: pip install cosmos-guardrail, restart, accept its licence at https://huggingface.co/nvidia/Cosmos-1.0-Guardrail, add that account's Hugging Face token in Settings, and load again. Or set UNSLOTH_COSMOS3_SAFETY_CHECKER=0 to run without it at your own responsibility.'nvidia/Cosmos3-Nano' needs NVIDIA's gated Cosmos guardrail: accept its licence at https://huggingface.co/nvidia/Cosmos-1.0-Guardrail, add that account's Hugging Face token in Settings, and load again. Or set UNSLOTH_COSMOS3_SAFETY_CHECKER=0 to run without it at your own responsibility.Backend only (
video.py,video_cosmos3.py). Cosmos3-Edge isn't affected: its checkpoint has the guardrail off.Verification
snapshot_download("nvidia/Cosmos-1.0-Guardrail", allow_patterns=["blocklist/*"]), the call the guardrail makes, underguardrail_hub_token, with no ambient login:401 ... Please log in403 ... you are not in the authorized list, so the token now reaches the download.False), no token and a blank token, throughload_pipeline. The scope is restored after a failed load. Gated 401 on the guardrail repo maps to the refusal, a gate on another repo keeps its error. The routing tests fail with the scope disabled.test_video_cosmos3.py: 194 passed.Not run
A load with an account that does have guardrail access (that path now sends the token and nothing is caught).
Before / after
Video page,
/video?model=nvidia/Cosmos3-Nanowithoutcosmos-guardrail, merge base4ee2f916cvs headede83684f(two fresh installs, CPU host with Developer mode CPU video on, which only opens the page; the refusal is the same network-free validation on every device).