Skip to content

fix(models): default the HF config file lock to HF_HOME instead of ~/.cache/huggingface - #6162

Merged
Jian-SA merged 3 commits into
NVIDIA-NeMo:mainfrom
linmuchuiyang:fix/config-lock-dir-follows-hf-home
Oct 12, 2026
Merged

Jian-SA merged 3 commits into
NVIDIA-NeMo:mainfrom
linmuchuiyang:fix/config-lock-dir-follows-hf-home

Conversation

@linmuchuiyang

Copy link
Copy Markdown
Contributor

What does this PR do ?

Make safe_load_config_with_retry() create its file lock under HF_HOME (via huggingface_hub.constants.HF_HOME) instead of Path.home()/.cache/huggingface, and name the MEGATRON_CONFIG_LOCK_DIR override in the retries-exhausted error when the last failure was a lock timeout.

Why: the lock protects the Hugging Face config cache, but its default location ignored HF_HOME, so on containerised clusters it landed in /root/.cache/huggingface on the ephemeral container layer. On an 8-node × 4-GPU HF→Megatron import of DeepSeek-V4-Pro (nemo:26.08, pyxis/enroot, HF_HOME on a shared filesystem) every rank timed out 4 × 60 s:

filelock._error.Timeout: The file lock '/root/.cache/huggingface/.megatron_config_lock_fe96e83596e6dfb94d32c391d3b8772e.lock' could not be acquired.
ValueError: Failed to load configuration from deepseek-ai/DeepSeek-V4-Pro after 4 attempts. This might be due to network issues or concurrent access conflicts. Last error: ...

Setting MEGATRON_CONFIG_LOCK_DIR to a shared directory fixed it, but the override was only documented in the docstring and not mentioned by the error. With this change the default follows HF_HOME (identical behaviour when HF_HOME is unset; MEGATRON_CONFIG_LOCK_DIR still takes precedence) and the error tells the user what to do.

Changelog

  • src/megatron/bridge/models/hf_pretrained/safe_config_loader.py: default lock directory os.getenv("MEGATRON_CONFIG_LOCK_DIR") or huggingface_hub.constants.HF_HOME; docstring updated; MEGATRON_CONFIG_LOCK_DIR hint appended to the final ValueError when last_exception is a filelock.Timeout.
  • tests/unit_tests/utils/test_safe_config_loader.py: expected default path now Path(hf_constants.HF_HOME); new test_default_lock_directory_follows_hf_home (patched HF_HOME, lock created there, directory created) and test_lock_timeout_error_mentions_override.

GitHub Actions CI

External contributor without CI trigger permissions; happy to have a maintainer trigger CI. Local validation in the nemo:26.08 container (Bridge c932511): tests/unit_tests/utils/test_safe_config_loader.py 24/24 passed; end-to-end with the real filelock and HF_HOME set, safe_load_config_with_retry("deepseek-ai/DeepSeek-V4-Pro", trust_remote_code=True) succeeds offline and the lock file appears under HF_HOME; ruff check / ruff format --check clean.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation? — docstring; no separate docs page mentions the lock directory.
  • Does the PR affect components that are optional to install? — no (huggingface_hub is already a hard dependency via transformers).

Additional Information

….cache/huggingface

safe_load_config_with_retry() serialises AutoConfig.from_pretrained() behind
a filelock. Without MEGATRON_CONFIG_LOCK_DIR the lock file was created under
Path.home()/.cache/huggingface, which ignores HF_HOME and, in enroot/pyxis
containers, lands on the ephemeral per-container layer. On an 8-node x 4-GPU
HF->Megatron import of DeepSeek-V4-Pro every rank timed out 4 x 60 s on
'/root/.cache/huggingface/.megatron_config_lock_<hash>.lock' with an error
that did not mention the override.

- Default the lock directory to huggingface_hub.constants.HF_HOME so the lock
  lives next to the cache it protects (unchanged behaviour when HF_HOME is
  unset; MEGATRON_CONFIG_LOCK_DIR still wins).
- Mention MEGATRON_CONFIG_LOCK_DIR in the retries-exhausted error when the
  last failure was a filelock.Timeout.
- Update the unit tests for the new default and add tests for the HF_HOME
  default and for the hint.

Signed-off-by: linmuchuiyang <6169320+linmuchuiyang@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33 yaoyu-33 added area:model Model implementations and HF bridge logic bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer labels Sep 20, 2026
@Jian-SA

Jian-SA commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

/ok to test a8d17b7

1 similar comment
@Jian-SA

Jian-SA commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

/ok to test a8d17b7

@github-actions

Copy link
Copy Markdown
Contributor

Automatic Claude reviews have been retired. To request a pull-request review, post a comment containing:

/review

Add model=claude to use a Claude reviewer (the default is model=codex). mode=light|strict selects the review depth; for example, /review model=claude mode=strict. Comment /review help for all options.

@Jian-SA

Jian-SA commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No verified findings. The loader change follows HF_HOME while preserving override precedence, lock naming, and timeout behavior. The diagnostic hint is conditional on the final exception being filelock.Timeout.

Review completed by source inspection; tests were not executed.

Suggested test cases

Review generated by codex

@Jian-SA
Jian-SA enabled auto-merge (squash) October 12, 2026 02:52
@linmuchuiyang

Copy link
Copy Markdown
Contributor Author

Thanks for the branch update and the review. On the current head the only red check is link-check, and its single error is a transient 503 Service Unavailable for examples/models/stepfun/step37/README.md (the earlier 404s on the nemotron pages were from the stale base and are gone after the update). A re-run should clear it; the PR itself does not touch docs. Nothing else pending from my side.

@Jian-SA

Jian-SA commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

/ok to test 7c801b1

@Jian-SA
Jian-SA merged commit fe8b0c5 into NVIDIA-NeMo:main Oct 12, 2026
72 of 73 checks passed
@linmuchuiyang
linmuchuiyang deleted the fix/config-lock-dir-follows-hf-home branch October 12, 2026 09:16
kamran-nvidia added a commit that referenced this pull request Oct 12, 2026
Bring in the latest main (#6162, #6163, #6382) on top of the earlier
conflict resolution; the merge is clean and the regenerated model
verification catalog check still passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Kamran Jafari <kjafarisadeg@nvidia.com>

This branch was successfully deployed

1 active deployment
test — 7c801b13 Deployed Oct 12, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #22765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:model Model implementations and HF bridge logic bug Something isn't working community-request needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants