Skip to content

Enable Checkpoint Conversion from Huggingface to Maxtext #1839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

YixuanWang-99
Copy link
Collaborator

@YixuanWang-99 YixuanWang-99 commented Jun 16, 2025

Description

Enable checkpoint conversion from Huggingface to Maxtext.

  • Add to_maxtext.py to perform the checkpoint conversion from HF to MaxText.
  • Add convert_gemma2_to_mt.sh to automate the conversion and verification.
  • Add mt_hf_mutual_conversion_check.py to compare the Huggingface and MaxText checkpoints.
  • Official Gemma2 models are supported.

Tests

The converted checkpoint is tested with mt_hf_mutual_conversion_check.py. It compared:

  1. For given prompts, top-k predicted tokens and scores for the next token;
  2. KL divergence of the full logit distributions

Tested on Gemma2-2b Model. A successful conversion example.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

@YixuanWang-99 YixuanWang-99 changed the title Enable conversion from Huggingface to Maxtext Enable Checkpoint Conversion from Huggingface to Maxtext Jun 16, 2025
Copy link
Collaborator

@hengtaoguo hengtaoguo left a comment

Choose a reason for hiding this comment

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

Excellent work!

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is nice, thanks for adding such a feature!

@hengtaoguo
Copy link
Collaborator

Hi @gagika ! I've heard this might be interesting to you for loading/saving HF checkpoints. Would you like to take a look when you got a chance? Thanks a lot for your time!

Copy link
Collaborator

@shralex shralex left a comment

Choose a reason for hiding this comment

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

Thanks Yixuan! Added a few comments

Copy link
Collaborator

@shralex shralex left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments! I have 1 small comment and also a question -- did you test both directions -- to and from HF ? if so can you add both to the PR description testing section, currently it includes 1 example. Thanks!

limitations under the License.
"""

"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please clarify what's the difference between this file and forward_pass_logits_checker ? this file is used in all our end-to-end tests to verify logits. If there is something missing in that file, I wonder if we could change it rather than creating a new file ?

@YixuanWang-99
Copy link
Collaborator Author

YixuanWang-99 commented Jun 24, 2025

Thanks for addressing the comments! I have 1 small comment and also a question -- did you test both directions -- to and from HF ? if so can you add both to the PR description testing section, currently it includes 1 example. Thanks!

from HF conversion with examples is pushed in previous PR: #1785 and #1821. And I have revised the run name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants