Skip to content

Only turn on HF_HUB_ENABLE_HF_TRANSFER in synthetic.py when hf_transfer is installed - #12406

Merged
danielhanchen merged 1 commit into
mainfrom
fix/synthetic-hf-transfer-only-when-installed
Oct 1, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/synthetic-hf-transfer-only-when-installed

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Problem

Core zoo (HF=4.57.6 + TRL<1) still fails on runs that already include unslothai/unsloth-zoo#1532 (zoo 2bbe3d81d), for example #12390 and #12389:

FAILED tests/test_gemma3_processor_token_type_ids.py::test_token_type_ids_mark_image_soft_tokens[1] - ValueError: Fast download using 'hf_transfer' is enabled (HF_HUB_ENABLE_HF_TRANSFER=1) but 'hf_transfer' package is not available in your environment.

unsloth-zoo#1532 stopped zoo from setting the flag when hf_transfer is missing. unsloth has its own copy of the same unconditional setter, in unsloth/dataprep/synthetic.py, and import unsloth reaches it through unsloth/dataprep/__init__.py. I traced every write to the variable during the zoo suite with a small pytest plugin. On main, the only write that turns it on is:

unsloth/dataprep/__init__.py, line 12:  from .synthetic import *
unsloth/dataprep/synthetic.py, line 26: os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"

On huggingface_hub < 1.0 (the 4.57.6 lane resolves 0.36.2), every plain HTTP download then raises unless hf_transfer is installed. That affects users too, not just CI: hf_transfer is optional and is not available on Windows on ARM at all. The setter dates back to the original synthetic.py (8babbeade, 2025-04-29). The offline guard from #5598 kept it unconditional otherwise.

Fix

synthetic.py only sets the flag when importlib.util.find_spec("hf_transfer") finds the package. It uses the same probe as unsloth-zoo#1532: it never imports the package, and treats a sys.modules stub with no __spec__ (where find_spec raises ValueError) as not installed. Offline mode still leaves the flag unset.

New tests/test_synthetic_hf_transfer_gate.py runs the module's own probe and guard from source, since the module needs torch and unsloth_zoo to import. It covers:

  • installed: the flag is set;
  • missing: the flag is unset;
  • spec-less stub: the flag is unset;
  • HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE with the package installed: the flag is unset.

On the relation to #12394: that PR installs hf_transfer in the Core CPU setup, which makes this lane green by giving CI the package. This PR fixes the product, so an environment without hf_transfer, like the users above, keeps working.

Verification

  • tests/test_synthetic_hf_transfer_gate.py plus the two existing synthetic test files: 36 passed.
  • With synthetic.py reverted, the missing and stub cases fail.
  • End to end, on transformers 4.57.6 and huggingface_hub 0.36.2 without hf_transfer, with the tracing plugin, over tests/test_relative_imports_resolve.py and tests/test_gemma3_processor_token_type_ids.py from unsloth-zoo main: main shows 1 traced write turning the flag on, from synthetic.py; this branch shows 0.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 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-10-01T08:39:23.009773Z 071dbad Manual request
🔒 Security Review ⚠️ Failed 2026-10-01T08:37:52.654961Z 071dbad PR opened
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 071dbadb63

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

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.

1 participant