Skip to content

Tighten the gated-base preflight comments - #8003

Merged
danielhanchen merged 3 commits into
mainfrom
diffusion-comment-trim
Aug 6, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
diffusion-comment-trim

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Comment-only follow-up to #7870, now that it has landed. Ten files, 311 insertions / 437 deletions, net -126 lines of comment text. No code changes.

What was cut

  • Multi-paragraph docstrings squashed to single paragraphs: _assert_base_repo_accessible, _cache_bytes, _union_over_cached_revs, _hub_cache_repo_dirs, _download_checkpoint_name, preflight_base_access on both backends, and hf_hub_download_with_xet_fallback.
  • Eight copies of the same three-line UNSLOTH_DIFFUSION_NO_MIRROR preamble in test_diffusion_gated_base.py, collapsed to one line each.

What was deliberately kept

Every comment recording a non-obvious fact survives, just shorter:

  • huggingface_hub 1.x makes response a required keyword-only argument and dereferences it unguarded, which is why the test builds the error through __new__
  • hf_raise_for_status folds an unauthenticated 401 into RepositoryNotFoundError because "401 is misleading"
  • expanduser() raises RuntimeError, not OSError, when it cannot resolve a home directory
  • blobs/ is append-only across republished revisions
  • the memory plan and the progress ratio deliberately fail in opposite directions: the plan unions per file so under-counting cannot leave an auto plan resident and OOMing, while _cache_bytes scopes to refs/main so the ratio cannot over-count a stale copy into a false "finalizing"

Verification

  • comment_tools.py check --changed --strip-docstrings: 10/10 OK, comments and docstrings only, no code touched. Re-run against current main, not just the original branch.
  • test_diffusion_backend, test_diffusion_gated_base, test_diffusion_routes, test_sd_cpp_backend, test_diffusion_prequant: 411 passed
  • hub/tests/ as a separate invocation: 172 passed
  • Formatted with scripts/run_ruff_format.py

Rebased onto main rather than pushed to the old branch: #7870 was squash-merged, so its head is not an ancestor of main and a PR from that branch would have re-shown the entire original diff.

Comment-only pass over the ten files #7870 touched, now that it has landed:
311 insertions, 437 deletions, net -126 lines of comment text. Multi-paragraph
docstrings squashed to single paragraphs, and eight copies of the same
three-line preamble in test_diffusion_gated_base.py collapsed to one line each.

Every non-obvious fact is kept, just shorter: huggingface_hub 1.x making
response a required keyword-only argument, hf_raise_for_status folding 401 into
RepositoryNotFoundError, expanduser raising RuntimeError rather than OSError,
blobs/ being append-only across republished revisions, and why the memory plan
and the progress ratio deliberately fail in opposite directions.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 3f697d630d

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

# fallback, which is what main does today.
# terminal (_get_model_file raises rather than falling back to the hub) and a sharded load
# raises per missing shard, so a partial snapshot would drop a build the hub id completes.
# Off the hub id a base only the other root holds costs a re-download, as main does today.

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 auth-failure branch in this comment

When a gated base exists only under the import-time cache root and its token is missing or expired, this live-root-pinned from_pretrained call cannot re-download the transformer: it raises a 401, and the caller falls back to the GGUF build unless an active LoRA forbids that fallback. Saying the Hub ID simply “costs a re-download” removes this important failure mode and misdescribes the behavior this deliberately indirect load path preserves; retain the previous re-download-or-401 distinction.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and fixed in abc895f. The trim collapsed two distinct outcomes into one: off the hub id a base only the other cache root holds costs a re-download, and separately 401s into the GGUF fallback when the base is gated and the token cannot read it. Restored the original wording verbatim, and the parallel comment in test_the_dense_builder_reads_transformer_from_the_hub_id_not_the_staged_snapshot keeps the same pair.

Comment on lines +437 to +438
"""The repo id AND its licence page: the Hub's 401/403 names neither, and the base comes from a
card tag, so the user never saw which repo it is."""

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 Keep the missing-repo attribution on the worker

A Hugging Face Hub 401/403 exception normally includes the requested resolve URL, which identifies the repository; it is the worker/UI error surfaced before this preflight that reduces the failure to a bare token message and leaves the card-derived base unidentified. Replacing “worker's” with “Hub's” therefore makes the helper's rationale factually incorrect and can mislead future work on which layer needs the richer error, so retain the worker attribution (the Hub response still does not provide the licence-page guidance).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and fixed in abc895f. A Hub 401/403 does name the repo: huggingface_hub raises it off the resolve URL, so the message carries the repo id in the URL it failed on. It is the worker layer that reduces that to a bare token message, which is why the repo id and licence URL have to be re-added here. Reverted to "the worker's 401/403".

Restore the second failure mode on the dense-transformer hub id (a re-download
or a 401 into the GGUF fallback), the worker attribution in the repo-access
message, the blob-reuse and failed-HEAD guarantees behind the other-root
reuse, the needless re-download of every moved asset, and the reachability
notes for the unresolvable-home and renamed-repo branches.
@danielhanchen

Copy link
Copy Markdown
Member Author

Both review items were right, and I took them as a signal to re-audit the whole trim for the same failure mode: a shortened comment that quietly drops a concrete fact. Five more cases, all restored in abc895f, all verified against huggingface_hub 0.36.2 and CPython 3.13 rather than from memory.

  • hf_xet_fallback.py, the reuse_other_cache_root docstring: the trim dropped "the blob is reused, and offline/401 hf_hub_download keeps the failed HEAD and serves the cached pointer". That is the guarantee that makes routing through the other root safe rather than a re-download plus a new failure. Confirmed in file_download._hf_hub_download_to_cache_dir: on head_call_error it returns the existing pointer path, and after a successful HEAD an existing pointer or blob short-circuits before any transfer.
  • diffusion.py, the GGUF other-root branch: same sentence, same reason. The sibling comment in diffusion_prequant._download_checkpoint_name kept it, so the trim had made two parallel comments disagree.
  • diffusion.py _prefetch_files: the trim kept only the token error and dropped "and every other moved asset into a needless re-download". The equivalent comment in sd_cpp_backend kept both outcomes, so again only one of a matched pair lost the fact.
  • diffusion.py _assert_base_repo_accessible: restored why the RuntimeError branch is reachable at all. Both ~other/models and ~/models with no HOME carry one slash, so they pass the count("/") != 1 guard above and reach expanduser(); pathlib.Path.expanduser raises RuntimeError("Could not determine home directory."), not OSError, whenever os.path.expanduser leaves the leading tilde in place. The same second case had been dropped from the test comment too.
  • _already_downloaded: the 404 is not excused for a renamed repo either, not just a removed one, which is what _repo_access_message reports.

I also pulled the qualifier back off the 2664 fix so it restores the original claim exactly instead of narrowing the 401 to a missing token; gating, not token absence, is what produces it.

Everything else I checked reads as a legitimate tightening. The dropped "Error no file named ..." literal and the "2 of 3 shards" example generalise to "a partial snapshot" without changing the claim, and "costs two metadata calls", "model_info answers anonymously for a gated repo" and "wrongly picks resident placement" each survive in the docstring that owns them.

AST gate is green across all 10 files against the pre-trim base: code and docstring-stripped ASTs identical, so this stays comment-only. Targeted suites pass, 411 in the five diffusion modules plus 172 in hub/tests.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

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

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

# re-download instead, or 401s into the GGUF fallback, which is what main does today.
# directory as terminal (_get_model_file raises instead of falling back to the hub) and a
# sharded load raises per missing shard, so a partial snapshot -- what a cancelled prefetch
# leaves -- would turn a working load into a hard failure. The hub id re-downloads instead.

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 auth-failure branch in the test rationale

When the staged base exists only under the import-time cache root and its gated-repo token is missing or expired, this live-root-pinned Hub-ID load does not re-download: from_pretrained raises a 401 and load_pipeline falls back to the GGUF build unless an active LoRA forbids that fallback. Fresh evidence in the final tree is that the production comment at _load_dense_quant_pipeline now restores this distinction, while this changed test rationale still claims the Hub ID only re-downloads; retain both outcomes here so the test does not document the wrong behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in a80e5fe: the test rationale now keeps both outcomes again, matching the _load_dense_quant_pipeline docstring. A gated base without a usable token raises out of from_pretrained (huggingface_hub hf_raise_for_status turns the 401/403 into RepositoryNotFoundError/GatedRepoError), load_pipeline catches it and builds the GGUF pipeline, and only a nonzero baked LoRA turns that into a hard failure.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: a80e5fe907

ℹ️ 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 merged commit 012f709 into main Aug 6, 2026
48 checks passed
@danielhanchen
danielhanchen deleted the diffusion-comment-trim branch August 6, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant