Repository navigation
[checkpoint] Parallelize Hugging Face checkpoint loading - #5087
Conversation
[ghstack-poisoned]
The reader otherwise loads each shard serially. Two workers overlap reads while limiting storage and CPU pressure. - Use two workers for unquantized readers by default. - Allow callers to override the thread count. - Preserve existing quantized reader defaults. - Reuse the shared reader in model adapters and conversion tooling. - Cover default and overridden thread counts. Test Plan: - pytest -q tests/unit_tests/cpu/test_state_dict_adapter.py -x - pytest -q test/distributed/checkpoint/test_hf_safetensor_e2e.py::TestSingleRankSaveLoad::test_load_with_multiple_threads - Full formatting, lint, spelling, link, and Pyrefly checks pass. ghstack-source-id: 8998c62 Pull-Request: #5087
| target_dtype=torch.float32, | ||
| block_size=BLOCK_SIZE, | ||
| thread_count=4, | ||
| thread_count=4 if thread_count is None else thread_count, |
There was a problem hiding this comment.
why don't we just default thread_count to be 4, in the function signature
There was a problem hiding this comment.
We currently use thread_count to be 2 as the default if it is NOT the quantized version. In my tests, 4 sometimes can put some pressures on the storage/CPUs. 2 is a conservative but generic number. Quantized version has a different access pattern, so the require thread count can be different.
| "Loading from quantized checkpoint format is not supported for this model." | ||
| ) | ||
| return HuggingFaceStorageReader(path) | ||
| if thread_count is None: |
The reader otherwise loads each shard serially. Two workers overlap reads while limiting storage and CPU pressure. - Use two workers for unquantized readers by default. - Allow callers to override the thread count. - Preserve existing quantized reader defaults. - Reuse the shared reader in model adapters and conversion tooling. - Cover default and overridden thread counts. Test Plan: - pytest -q tests/unit_tests/cpu/test_state_dict_adapter.py -x - pytest -q test/distributed/checkpoint/test_hf_safetensor_e2e.py::TestSingleRankSaveLoad::test_load_with_multiple_threads - Full formatting, lint, spelling, link, and Pyrefly checks pass. ghstack-source-id: 8998c62 Pull-Request: #5087
| path: str, | ||
| from_quantized: bool = False, | ||
| *, | ||
| thread_count: int | None = None, |
There was a problem hiding this comment.
I mean here it could be
| thread_count: int | None = None, | |
| thread_count: int = 4, |
There was a problem hiding this comment.
If we set thread_count: int = 4, it will be passed through super().get_hf_storage_reader, the unquantized one which the default value is 2.
We set them differently according to the empirical results. But the results were verified on different clusters (the quantized one was done sometime last year I think). If you should really want to consolidate the default value and get rid of None, it shouldn't hurt too much
| path: str, | ||
| from_quantized: bool = False, | ||
| *, | ||
| thread_count: int | None = None, |
There was a problem hiding this comment.
| thread_count: int | None = None, | |
| thread_count: int = 2, |
| path: str, | ||
| from_quantized: bool = False, | ||
| *, | ||
| thread_count: int | None = None, |
There was a problem hiding this comment.
this glue code will be gone soon, so doesn't matter
Stack from ghstack (oldest at bottom):
The reader otherwise loads each shard serially. Two workers overlap reads while limiting storage and CPU pressure.
Test Plan: