Skip to content
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

Add convert_special_token_settings.py #15

Merged
merged 2 commits into from
Apr 14, 2024
Merged

Conversation

hiroshi-matsuda-rit
Copy link
Member

@so298 Please review and test in the real model directories. After merging to main branch, please reflect the changes to llm-jp and llm-jp-nvlink clusters.

@hiroshi-matsuda-rit hiroshi-matsuda-rit requested a review from a team as a code owner April 13, 2024 00:28
@so298
Copy link
Collaborator

so298 commented Apr 14, 2024

@hiroshi-matsuda-rit

I tried to run the script for some models, but I could not successfully convert to hf models because of len(tokenizer) == model_config["vocab_size"] assertion's failure.

For example:

exp9 model and ver3.0b1 tokenizer
Phase 5: Update model config with Hugging Face Tokenizer special token settings
python convert_special_token_settings.py /model/7B_HF_RE/test_conversion_script/
Traceback (most recent call last):
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 38, in <module>
    main()
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 32, in main
    new_model_config = update_special_token_settings(tokenizer, model_config)
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 8, in update_special_token_settings
    assert len(tokenizer) == model_config["vocab_size"], f'Different vocab size definitions: {len(tokenizer)=} and {model_config["vocab_size"]=}'
AssertionError: Different vocab size definitions: len(tokenizer)=99574 and model_config["vocab_size"]=99584
exp4+ model and ver2.2 50k tokenizer
==========================================
Phase 5: Update model config with Hugging Face Tokenizer special token settings
python convert_special_token_settings.py /model/7B_HF_RE/test_conversion_script_ver2.2_50k/
Traceback (most recent call last):
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 38, in <module>
    main()
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 32, in main
    new_model_config = update_special_token_settings(tokenizer, model_config)
  File "/model/sosuke/modelwg/convert_special_token_settings.py", line 8, in update_special_token_settings
    assert len(tokenizer) == model_config["vocab_size"], f'Different vocab size definitions: {len(tokenizer)=} and {model_config["vocab_size"]=}'
AssertionError: Different vocab size definitions: len(tokenizer)=48586 and model_config["vocab_size"]=48640

While reading this issue in huggingface transformers repo, I think tokenizer's vocab size and model's vocab size can be different to make model's vocab size GPU-friendly.
(I have not looked into Megatron-LM's logic to determine vocab_size in model_config.json)

In fact, the values of vocab_size in model_config.json, such as 48640 (= 2^9 * 5 * 19) and 99584 (= 2^8 * 389), can be factored into products of large powers of two and a few prime numbers.

I think this assertion should be removed.

@so298
Copy link
Collaborator

so298 commented Apr 14, 2024

@hiroshi-matsuda-rit
Copy link
Member Author

Thanks for reviewing. I just changed the assertion to warning message. @so298

Copy link
Collaborator

@so298 so298 left a comment

Choose a reason for hiding this comment

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

I have confirmed that the script works correctly. I will merge it.

@so298 so298 merged commit 394a609 into main Apr 14, 2024
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.

2 participants