Skip to content

[checkpoint] Parallelize Hugging Face checkpoint loading - #5087

Merged
fegin merged 2 commits into
mainfrom
gh/fegin/180/head
Oct 6, 2026
Merged

fegin merged 2 commits into
mainfrom
gh/fegin/180/head

Conversation

@fegin

@fegin fegin commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

fegin added 2 commits October 5, 2026 23:46
[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl labels Oct 6, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 6, 2026
fegin added a commit that referenced this pull request Oct 6, 2026
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,

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.

why don't we just default thread_count to be 4, in the function signature

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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:

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.

similar

fegin added a commit that referenced this pull request Oct 6, 2026
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,

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.

I mean here it could be

Suggested change
thread_count: int | None = None,
thread_count: int = 4,

@fegin fegin Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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,

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.

Suggested change
thread_count: int | None = None,
thread_count: int = 2,

path: str,
from_quantized: bool = False,
*,
thread_count: int | None = None,

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.

this glue code will be gone soon, so doesn't matter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants