Skip to content

Add kv_channels to convert_llama_nemo_to_hf.py#10078

Closed
suhara wants to merge 3 commits intoNVIDIA-NeMo:mainfrom
suhara:suhara/llama-nemo-to-hf-add-kv-channels
Closed

Add kv_channels to convert_llama_nemo_to_hf.py#10078
suhara wants to merge 3 commits intoNVIDIA-NeMo:mainfrom
suhara:suhara/llama-nemo-to-hf-add-kv-channels

Conversation

@suhara
Copy link
Contributor

@suhara suhara commented Aug 7, 2024

What does this PR do ?

Custom Llama-based models may use custom head_dim as it is supported by NeMo/MegatronLM (it's called kv_channels in these tools).

The current convert_llama_nemo_to_hf.py assumes head_dim * num_heads == hidden_size

There's an ongoing PR to support custom head_dim in HF

I've been in touch with and getting support from @suiyoubi for this PR.

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

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)

suhara and others added 2 commits August 7, 2024 00:19

head_size = hidden_size // head_num
# Use kv_channels if available. Otherwise, use hidden_size // head_num as head_size
head_size = model.cfg.get("kv_channels", hidden_size // head_num)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think in nemo config kv_channels can be set to null explictly, which would cause issue here. I would suggest changing to something like:

if model.cfg.get("kv_channels", None) is None:
    head_size = hidden_size // head_num
else:
    head_size = model.cfg.kv_channels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@suiyoubi Thank you for the suggestion! Revised accordingly.

@github-actions
Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Aug 24, 2024
@github-actions
Copy link
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Aug 31, 2024
@suhara
Copy link
Contributor Author

suhara commented Dec 19, 2024

The feature is covered by another PR, which has been merged.
#11230

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants