Add unified tool to inspect checkpoint structures#3139
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
🤖 Hi @RissyRan, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
This Pull Request introduces a unified checkpoint inspector tool for HuggingFace, MaxText architecture, and Orbax. The tool is a great addition for debugging model bring-ups. However, there is a significant bug in the MaxText mode where layer indices are ignored during path flattening, leading to incomplete output. Additionally, there are opportunities to improve memory efficiency when inspecting large checkpoints.
🔍 General Feedback
- Bug Fix Required: The MaxText architecture inspection currently collapses all layers into a single set of keys because it ignores
SequenceKeyindices. This needs to be addressed to provide a complete view of the model structure. - Memory Efficiency: For
safetensors, usingget_sliceinstead ofget_tensoravoids unnecessary data loading. For PyTorch checkpoints, better handling of large files and common state-dict wrappers would make the tool more robust. - Consistency: Standardizing separators across different modes (e.g., using
.everywhere) would improve the user experience.
25dd2cf to
cd8b454
Compare
parambole
left a comment
There was a problem hiding this comment.
- JAX path flattening currently ignores SequenceKey (layer indices in lists) and GetAttrKey because it filters strictly with hasattr(k, "key"). This collapses all layers (e.g., layer_0 and layer_1 become just layer), causing incorrect parameter counts and output. We should use the existing helper param_key_parts_from_path(path_tuple) to format keys correctly. When scan_layers=False
- "attention=dot_product" after remaining_args overrides any user-specified CLI flags (e.g., attention=flash). We should prepend defaults before remaining_args.
- Remove a leftover debug prints.
7f35e51 to
dc8b3a6
Compare
parambole
left a comment
There was a problem hiding this comment.
LGTM. Thank you adding this awesome tool.
hengtaoguo
left a comment
There was a problem hiding this comment.
This is awesome tool, thanks Shuning!
As a nice-to-have feature, I wonder if we could add a --save_to_txt=<path> flag. In addition to printing logs to the terminal, it would be great to dump them into a separate text file. This would allow both humans and agents to review the files and analyze the differences more easily later on. WDYT?
Does the tool currently support this? If not, we can definitely treat this as a follow-up item.
f7c37b2 to
c09fcb3
Compare
Thanks @hengtaoguo for the suggestion! I have enabled saving to output, with flag Tests: I have rerun the tests and included the saved file in the PR description.
|
90999cf to
d002758
Compare
d002758 to
9caffac
Compare
Description
Unified script to inspect checkpoint structures for HF/MaxText/Orbax, to help with bringup and debugging.
Fix: b/484416862
Feature: Inspection Tool
A unified command-line tool to inspect checkpoint structures and tensor shapes. It is designed to be lightweight and minimize memory/compute costs across three supported modes:
1. HuggingFace Checkpoints (Locally downloaded file)
mmap). Incurs a time cost for deserialization, but the host memory footprint is strictly constrained.2. MaxText Model Architecture (On-the-fly)
jax.eval_shape3. Orbax Checkpoints (Pre-saved disk/GCS file)
Usage Examples
[Mode 1: HuggingFace] python src/maxtext/checkpoint_conversion/inspect_checkpoint.py hf \ --path <local_hf_path> --format <safetensors | pth> [Mode 2: MaxText Architecture] python src/maxtext/checkpoint_conversion/inspect_checkpoint.py maxtext \ model_name=<maxtext_model_name> scan_layers=<True | False> (Optional: other maxtext config) [Mode 3: Orbax] python src/maxtext/checkpoint_conversion/inspect_checkpoint.py orbax \ --path <local_orbax_path | gcs_orbax_path>Additional Features:
--check_dtype: bool, default to False. Appends the data type of each tensor to the output.--output_file: str, default to empty. Path to save the output structure.Add Documentation: When to use Tool
docs/guides/checkpointing_solutions/convert_checkpoint.mdDevelopment and Troubleshooting, introduced a new### Inspection Toolssection documenting theinspect_checkpoint.pyutility. It provides clear command-line examples for checking the three supported checkpoint formats.Adding New Models, introduced using Inspection Tools to create mappings.Common Errors, introduced using Inspection Tools to debug. The most common error (Type ShapeDtypeStruct is not a valid JAX type) is caused by structural mismatches.docs/guides/model_bringup.md3.1 Create Mapping, introduced using Inspection Tools to create mappings.Tests
1 HF checkpoint, locally downloaded
safetensors: no cost
pth: low cost with per-tensor load
2 MaxText model, on-fly, no cost
3 Orbax checkpoint, pre-saved, no cost
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.