NeMo 2.0 vLLM export
State: closed | Pull request: yes
Labels: name: CI

name: Run CICD

# What does this PR do ?

vLLM export for NeMo 2.0 models

**Collection**: llm

# Changelog 
- Add specific line by line info of high level changes in this PR.

# Usage
The vLLM export needs to be run in the virtual environment, installed inside the NeMo container:
``` bash
source /opt/venv/bin/activate
```

Sample vLLM script for export:
```python
from nemo.export.vllm_exporter import vLLMExporter
import os, os.path
import argparse

def get_args():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description="vLLM export argument parser",
    )
    parser.add_argument("--nc", type=str)
    parser.add_argument("--tps", type=int)
    parser.add_argument("--mt", type=str)

    args = parser.parse_args()
    args.export_path = f"/tmp/vllm_{args.mt}_tps{args.tps}"
    return args


args = get_args()
if not os.path.exists(args.export_path):
   os.mkdir(args.export_path)

exporter = vLLMExporter()
exporter.export(
   nemo_checkpoint=args.nc,
   model_dir=args.export_path,
   model_type=args.mt,
   tensor_parallel_size=args.tps,
)

output = exporter.forward(["What is the best city in the world?"], max_output_len=50, top_k=1, top_p=0.0, temperature=1.0)
print("output: ", output)
```

# 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](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)


> Were you able to test this with a nemo 2 ckpt?

Yep, that's the very point here. Model types tested are Llama, Mixtral, Gemma, StarCoder2 to keep vLLM supported models parity with 24.07 release https://docs.nvidia.com/nemo-framework/user-guide/24.07/deployment/llm/optimized/index.html

<!-- pylint-output-strict-mode-false -->

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 nemo.export.sentencepiece_tokenizer
nemo/export/sentencepiece_tokenizer.py:249:0: C0301: Line too long (137/119) (line-too-long)
nemo/export/sentencepiece_tokenizer.py:68:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:97:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:126:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:132:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:151:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:157:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:166:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:174:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:199:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:207:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:215:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:223:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:230:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:237:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:244:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:256:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:266:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:269:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:276:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/sentencepiece_tokenizer.py:279:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.trt_llm.nemo_ckpt_loader.nemo_file
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:50:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:164:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:196:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:207:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:211:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:238:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:249:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:270:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:365:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:483:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:570:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:574:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:585:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:597:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:637:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:674:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:687:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:25:0: W0611: Unused import tensorstore (unused-import)
************* Module nemo.export.vllm.engine
nemo/export/vllm/engine.py:38:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/vllm/engine.py:41:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/vllm/engine.py:45:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.vllm.model_converters
nemo/export/vllm/model_converters.py:61:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/vllm/model_converters.py:124:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/vllm/model_converters.py:193:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/vllm/model_converters.py:274:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.export.vllm.model_loader
nemo/export/vllm/model_loader.py:84:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/vllm/model_loader.py:24:0: W0611: Unused import tensorstore (unused-import)

-----------------------------------
Your code has been rated at 9.53/10
```

---

Mitigation guide:

* Add sensible and useful docstrings to functions and methods
* For trivial methods like getter/setters, consider adding `# pylint: disable=C0116` inside the function itself
* To disable multiple functions/methods at once, put a `# pylint: disable=C0116` before the first and a `# pylint: enable=C0116` after the last.

By applying these rules, we reduce the occurance of this message in future.

Thank you for improving NeMo's documentation!

[🤖]: Hi @Laplasjan107 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/12751055699) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g