Mistral 7b conversion script
State: closed | Pull request: yes
Labels: name: NLP

# What does this PR do ?
Adds conversion script for mistral-7b to NeMo.

**Collection**: [Note which collection this PR will affect]
nlp/language_modeling

# Changelog 
- Add specific line by line info of high level changes in this PR.

# Usage
* You can potentially add a usage example below

```python
# Add a code snippet demonstrating how to use this 
```

# Jenkins CI
To run Jenkins, a NeMo User with write access must comment `jenkins` on the PR.

# Before your PR is "Ready for review"
**Pre checks**:
- [ ] Make sure you read and followed [Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md)
- [ ] 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**:
- [x] 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](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md) contains specific people who can review PRs to various areas.

# Additional Information
* Related to # (issue)


Could you please keep the conversion script consistent with other ones? I specifically mean:
* https://github.com/NVIDIA/NeMo/blob/main/scripts/nlp_language_modeling/convert_mpt_7b_hf_to_nemo.py
* https://github.com/NVIDIA/NeMo/blob/main/scripts/nlp_language_modeling/convert_starcoder_hf_to_nemo.py
* https://github.com/NVIDIA/NeMo/blob/main/scripts/nlp_language_modeling/convert_hf_falcon_to_nemo.py

In particular, at best we keep these aligned across scripts:
* defining a new `convert_state_dict` function
* config handling (`override_model_dict` etc.)
* script parameters.

[Llama2 conversion script](https://github.com/NVIDIA/NeMo/blob/main/scripts/nlp_language_modeling/convert_hf_llama_to_nemo.py) has a bit different flavour, but I believe we should follow the "majority" style for new scripts (and align Llama2 at some point).

As for architecture, Mistral seems to heavily borrow from Llama2.

Would it be possible to just extend Llama2 conversion script to cover HF Mistral checkpoint?

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.

Hi @janekl thanks for your comments! I'm leaning towards merging this as is and once we settle on how we want to refactor the import scripts do the actual refactor. I think you are right it shares a lot with the Llama script, and once the PRs you mention have been approved & merged we can follow the appropriate guidelines here as well.

jenkins

jenkins

I think that adding a Jenkins conversion test for a small Mistral model would be really desirable. 

Examples are here https://github.com/NVIDIA/NeMo/blob/f10d6941d7c18a0154d41c943deaae4d65a4b752/Jenkinsfile#L391-L419

cc @ericharper 

> Hi @janekl thanks for your comments! I'm leaning towards merging this as is and once we settle on how we want to refactor the import scripts do the actual refactor. I think you are right it shares a lot with the Llama script, and once the PRs you mention have been approved & merged we can follow the appropriate guidelines here as well.

Sorry for replying late. That's fine, we can polish it later, there is some consistency PR open here https://github.com/NVIDIA/NeMo/pull/8192.

In any case, please see my comments in two other threads. We really need to test conversion in analogy to other scripts. Otherwise we won't have any confidence in refactoring work later. I think @ericharper should support this extra effort.