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

[Bugfix] fix qwen tokenizer config when converting to nemo format #11098

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

Conversation

chrjxj
Copy link

@chrjxj chrjxj commented Oct 30, 2024

What does this PR do ?

This PR fixes qwen tokenizer config when converting qwen2 from HF to nemo format;

Background: when running Qwen SFT, _build_tokenizer() will return Qwen2Tokenizer or Qwen2TokenizerFast based on cfg.tokenizer .

without this update, _build_tokenizer will use use_fast default value ( False) and create an Qwen2Tokenizer instance (wrapped by NeMo/nemo/collections/common/tokenizers/huggingface/auto_tokenizer.py). Qwen2Tokenizer instance don't have vocab attributes, which results in errors during SFT data loading.

Above changes is tested within nvcr.io/nvidia/nemo:24.07; passed.

Collection: LLM, Qwen2

Changelog

  • line 86 to 92, in NeMo/scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py

Usage

  • won't affect usage

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@ntajbakhsh
Copy link
Collaborator

@cuichenx can you review this PR please?

Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module convert_qwen2_hf_to_nemo
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:40:0: C0301: Line too long (101/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:53:0: C0301: Line too long (114/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:58:0: C0301: Line too long (109/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:61:0: C0301: Line too long (218/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:142:0: C0301: Line too long (113/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:144:0: C0301: Line too long (114/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:149:0: C0301: Line too long (108/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:175:0: C0301: Line too long (103/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:182:0: C0301: Line too long (103/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:190:0: C0301: Line too long (115/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:197:0: C0301: Line too long (101/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:198:0: C0301: Line too long (102/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:199:0: C0301: Line too long (102/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:203:0: C0301: Line too long (108/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:206:0: C0301: Line too long (103/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:210:0: C0301: Line too long (116/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:232:0: C0301: Line too long (111/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:240:0: C0301: Line too long (103/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:263:0: C0301: Line too long (104/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:268:0: C0301: Line too long (101/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:272:0: C0301: Line too long (111/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:298:0: C0301: Line too long (115/100) (line-too-long)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:27:0: E0401: Unable to import 'torch' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:28:0: E0401: Unable to import 'omegaconf' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:29:0: E0401: Unable to import 'pytorch_lightning.trainer.trainer' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:30:0: E0401: Unable to import 'transformers' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:32:0: E0401: Unable to import 'nemo.collections.nlp.models.language_modeling.megatron_gpt_model' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:33:0: E0401: Unable to import 'nemo.collections.nlp.parts.nlp_overrides' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:40:0: E0401: Unable to import 'nemo.collections.nlp.parts.utils_funcs' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:41:0: E0401: Unable to import 'nemo.utils' (import-error)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:44:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:64:4: W0621: Redefining name 'args' from outer scope (line 314) (redefined-outer-name)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:68:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:68:16: W0621: Redefining name 'args' from outer scope (line 314) (redefined-outer-name)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:104:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:104:0: R0914: Too many local variables (55/15) (too-many-locals)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:104:12: W0621: Redefining name 'args' from outer scope (line 314) (redefined-outer-name)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:163:23: C3001: Lambda expression assigned to a variable. Define a function using the "def" keyword instead. (unnecessary-lambda-assignment)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:168:38: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:170:34: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:172:34: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:176:7: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:177:49: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:179:44: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:181:44: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:277:41: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:279:29: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:281:29: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:284:45: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:286:33: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:288:33: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:302:4: W0212: Access to a protected member _save_restore_connector of a client class (protected-access)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:104:0: R0912: Too many branches (42/12) (too-many-branches)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:104:0: R0915: Too many statements (154/50) (too-many-statements)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:107:4: W0612: Unused variable 'tokenizer' (unused-variable)
scripts/checkpoint_converters/convert_qwen2_hf_to_nemo.py:111:14: W0612: Unused variable 'param' (unused-variable)

-----------------------------------
Your code has been rated at 5.34/10

Thank you for improving NeMo's documentation!

@cuichenx cuichenx enabled auto-merge (squash) November 18, 2024 19:12
Copy link
Collaborator

@cuichenx cuichenx left a comment

Choose a reason for hiding this comment

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

LGTM! thanks for the fix

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

Successfully merging this pull request may close these issues.

3 participants