Repository navigation
fix(models): default the HF config file lock to HF_HOME instead of ~/.cache/huggingface - #6162
Conversation
….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>
|
/ok to test a8d17b7 |
1 similar comment
|
/ok to test a8d17b7 |
|
Automatic Claude reviews have been retired. To request a pull-request review, post a comment containing: Add |
|
/review |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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
- test_default_lock_directory_follows_hf_home: lock path uses the patched
HF_HOME, and the directory is created. - test_custom_lock_directory_env_var: the explicit override takes precedence.
- test_lock_timeout_error_mentions_override: exhausted lock acquisition includes
MEGATRON_CONFIG_LOCK_DIRin the error. - test_error_message_includes_details: network failures retain the model path, attempt count, and original error.
- No perf tests impacted.
Review generated by codex
|
Thanks for the branch update and the review. On the current head the only red check is |
|
/ok to test 7c801b1 |
What does this PR do ?
Make
safe_load_config_with_retry()create its file lock underHF_HOME(viahuggingface_hub.constants.HF_HOME) instead ofPath.home()/.cache/huggingface, and name theMEGATRON_CONFIG_LOCK_DIRoverride 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/huggingfaceon the ephemeral container layer. On an 8-node × 4-GPU HF→Megatron import of DeepSeek-V4-Pro (nemo:26.08, pyxis/enroot,HF_HOMEon a shared filesystem) every rank timed out 4 × 60 s:Setting
MEGATRON_CONFIG_LOCK_DIRto 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 followsHF_HOME(identical behaviour whenHF_HOMEis unset;MEGATRON_CONFIG_LOCK_DIRstill takes precedence) and the error tells the user what to do.Changelog
src/megatron/bridge/models/hf_pretrained/safe_config_loader.py: default lock directoryos.getenv("MEGATRON_CONFIG_LOCK_DIR") or huggingface_hub.constants.HF_HOME; docstring updated;MEGATRON_CONFIG_LOCK_DIRhint appended to the finalValueErrorwhenlast_exceptionis afilelock.Timeout.tests/unit_tests/utils/test_safe_config_loader.py: expected default path nowPath(hf_constants.HF_HOME); newtest_default_lock_directory_follows_hf_home(patchedHF_HOME, lock created there, directory created) andtest_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.py24/24 passed; end-to-end with the realfilelockandHF_HOMEset,safe_load_config_with_retry("deepseek-ai/DeepSeek-V4-Pro", trust_remote_code=True)succeeds offline and the lock file appears underHF_HOME;ruff check/ruff format --checkclean.Before your PR is "Ready for review"
Pre checks:
huggingface_hubis already a hard dependency viatransformers).Additional Information
MEGATRON_CONFIG_LOCK_DIRoverride).