Skip to content

Unsloth Studio: Cosmos3 guardrail refusal names the gated nvidia/Cosmos-1.0-Guardrail repo - #16742

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:cosmos3-guardrail-gated-hint
Nov 7, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:cosmos3-guardrail-gated-hint

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

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 raw 401 Cannot access gated repo. The guardrail downloads its own weights from nvidia/Cosmos-1.0-Guardrail, a gated Hugging Face repo, and it calls snapshot_download with no token. So the Hugging Face token saved in Unsloth Settings never reached that download. Only an ambient hf auth login / HF_TOKEN did, and on a multi-user install a managed account's load fell back to the owner's ambient login.

The change

  • The guardrail download now gets the load's own token: the Settings token when there is one, anonymous for a managed account without one, and the ambient login otherwise, exactly like the rest of the load. It is set for building the Cosmos3 pipeline only (guardrail_hub_token) and cleared afterwards, including when the load fails. Other families are untouched.
  • If Hugging Face still refuses that repo (401/403 on 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.
  • Both refusals are now one or two sentences:
    • Package missing: '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.
    • Access refused: '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

  • Live against the Hub with snapshot_download("nvidia/Cosmos-1.0-Guardrail", allow_patterns=["blocklist/*"]), the call the guardrail makes, under guardrail_hub_token, with no ambient login:
    • no token: 401 ... Please log in
    • Settings token (an account without guardrail access): 403 ... you are not in the authorized list, so the token now reaches the download.
    • Both produce the access refusal above.
  • Overlapping loads (cancel and reload) each keep their own token: the token lives in a context variable read by one permanent wrapper, so out-of-order exits cannot leave one account's token installed.
  • Unit tests: the routed token for a Settings token, a managed account (False), no token and a blank token, through load_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.
  • Studio regression switchboard, base vs head: no functional regression (rerun at the final head).

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-Nano without cosmos-guardrail, merge base 4ee2f916c vs head ede83684f (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).

Load refusal toast, before and after

Video page with the toast, before and after

…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.
@LeoBorcherding

LeoBorcherding commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

Codex is clean at this head (8627c13) on the fork mirror: LeoBorcherding#773

Fork mirror CI at 8627c13 is complete: 45 checks pass. The one red job, Repo tests (CPU, rest), is 6 cases of test_fp8_loss_ignores_model_output_flags_only_on_its_head failing with "Unsloth cannot find any torch accelerator" on the fork's runner. That is the runner, not this PR: the same job passes on this repo's runners (#16737 at 2676a6d) and fails the same way on every Cosmos3 mirror.

@danielhanchen danielhanchen self-assigned this Nov 7, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T13:43:37.741078Z 0e5e559 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: 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".

Comment on lines +145 to +149
module.snapshot_download = functools.partial(download, token = token)
try:
yield
finally:
module.snapshot_download = download

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 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 👍 / 👎.

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.

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]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 0e5e5596c5

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
@danielhanchen
danielhanchen merged commit 997441a into unslothai:main Nov 7, 2026
danielhanchen added a commit that referenced this pull request Nov 7, 2026
… 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.
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 10, 2026
…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):

![Video picker, 96 GB,
light](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/picker_96gb_light.png)
![Video picker, 96 GB,
dark](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/picker_96gb_dark.png)

Tesla T4, 15 GB (Nano greyed, hover says why):

![Video picker, T4,
light](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/picker_t4_light.png)
![Video picker, T4,
dark](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/picker_t4_dark.png)

Model hub, `nvidia/Cosmos3-Nano`:

![Hub,
light](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/hub_light.png)
![Hub,
dark](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/hub_dark.png)

Picking Nano with no `cosmos-guardrail` installed (before: Nano isn't in
the list):

![Nano pick
refusal](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1e20532eaa7c37da74293491bfbebd9d11c340a4/v2/refusal_light_dark.png)

## Memory and speed

![Cosmos3-Nano peak VRAM and generate time on RTX PRO 6000, A100 40 GB
and
L4](https://raw.githubusercontent.com/LeoBorcherding/unsloth/1afb12730d513c5deec5b687eb22631af7b544c3/charts/nano_vram_by_gpu.png)

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.

![Video picker before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16743/pr16743_before_after-edb0e5b37082.png)

---------

Co-authored-by: Daniel Han <[email protected]>
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