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

Integrate lm-eval-harness for evaluations in NeMo #10621

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

Conversation

athitten
Copy link
Collaborator

@athitten athitten commented Sep 25, 2024

What does this PR do ?

Integrates lm-evaluation-harness into NeMo to run evaluations on standard academic benchmarks.
Evaluations can be run by first deploying the model on PyTriton server via deploy method followed by running the evaluate method to do the actual evaluation.

Collection: This is an independent module and does not affect any collection.

Changelog

  • Refactor deploy method in nemo/collections/llm/api.py by moving utility funcs to nemo/collections/llm/evaluation/eval_utils.py. Deploy method takes care of exporting nemo model to trtllm and deploying it on PyTriton server.
  • Deploy method also starts rest service using uvicorn that runs a FastAPI application which exposes OpenAI end point /v1/completions.
  • The FastAPI application is defined in nemo/deploy/service/rest_model_api.py which contains the code to interact with the PyTriton Server to perform the actual model inference via /v1/completions endpoint.
  • Evaluate method is added to nemo/collections/llm/api.py to evaluate nemo model deployed on PyTriton server (via trtllm) using lm-evaluation-harness.
    Evaluate method takes in as input the rest service url "http://rest_service_http_address:rest_service_port/v1" and other evaluation params like eval task, num_fewshot, limit etc., and inference params like temperature, top_p, top_k, max_tokens_to_generate
  • Evaluate method instantiates NeMoFWLMEval class defined in nemo/collections/llm/evaluation/eval_utils.py that creates a wrapper to interface eval prompts from lm-eval-harness with the model deployed on PyTriton.
  • NeMoFWLMEval class defines two types of tasks: generate_until (for ex: gsm8k) and loglikelihood tasks (for ex: mmlu).
  • The PR also exposes gather_context_logits, gather_generation_logits flag to build the trtllm engine with logits. Eval code needs the generation logits to compute the logProb of the actual output token or label, hence its enabled (False by default).

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)

@athitten athitten force-pushed the athitten/evaluation branch 2 times, most recently from c970d5d to 30ee09e Compare September 30, 2024 20:55
@athitten athitten changed the title Add evaluate method and other minor fixes Integrate lm-eval-harness via evaluate method in api.py Oct 14, 2024
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.

nemo/export/tensorrt_llm.py Fixed Show fixed Hide fixed
nemo/collections/llm/api.py Fixed Show fixed Hide fixed
nemo/collections/llm/api.py Fixed Show fixed Hide fixed
nemo/export/tensorrt_llm.py Fixed Show fixed Hide fixed
@athitten athitten marked this pull request as ready for review November 8, 2024 04:04
self.add_bos = add_bos
super().__init__()

def _generate_tokens_logits(self, payload, return_text: bool = False, return_logits: bool = False):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
nemo/collections/llm/evaluation/eval_utils.py Fixed Show fixed Hide fixed
Copy link
Contributor

github-actions bot commented Nov 8, 2024

[🤖]: Hi @athitten 👋,

We wanted to let you know that a CICD pipeline 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

with open("nemo/deploy/service/config.json", "w") as f:
json.dump(args_dict, f)


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

get_trtllm_deployable() has been moved to nemo/collections/llm/evaluation/eval_utils.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

store_args_to_json() has been removed to avoid creating a new file to store the args. Instead triton args are stored as env vars in deploy() method to access in rest_model_api.py

@athitten athitten changed the title Integrate lm-eval-harness via evaluate method in api.py Integrate lm-eval-harness for evaluations in NeMo Nov 8, 2024
@athitten athitten added Run CICD and removed Run CICD labels Nov 9, 2024
Copy link
Contributor

github-actions bot commented Nov 9, 2024

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.collections.llm.api
nemo/collections/llm/api.py:64:0: C0301: Line too long (135/119) (line-too-long)
nemo/collections/llm/api.py:220:0: C0301: Line too long (135/119) (line-too-long)
nemo/collections/llm/api.py:283:0: C0301: Line too long (122/119) (line-too-long)
nemo/collections/llm/api.py:284:0: C0301: Line too long (130/119) (line-too-long)
nemo/collections/llm/api.py:289:0: C0301: Line too long (138/119) (line-too-long)
nemo/collections/llm/api.py:297:0: C0301: Line too long (135/119) (line-too-long)
nemo/collections/llm/api.py:300:0: C0301: Line too long (141/119) (line-too-long)
nemo/collections/llm/api.py:302:0: C0301: Line too long (151/119) (line-too-long)
nemo/collections/llm/api.py:304:0: C0301: Line too long (154/119) (line-too-long)
nemo/collections/llm/api.py:398:0: C0301: Line too long (158/119) (line-too-long)
nemo/collections/llm/api.py:401:0: C0301: Line too long (144/119) (line-too-long)
nemo/collections/llm/api.py:402:0: C0301: Line too long (154/119) (line-too-long)
nemo/collections/llm/api.py:404:0: C0301: Line too long (164/119) (line-too-long)
nemo/collections/llm/api.py:407:0: C0301: Line too long (147/119) (line-too-long)
nemo/collections/llm/api.py:410:0: C0301: Line too long (163/119) (line-too-long)
nemo/collections/llm/api.py:411:0: C0301: Line too long (155/119) (line-too-long)
nemo/collections/llm/api.py:412:0: C0301: Line too long (174/119) (line-too-long)
nemo/collections/llm/api.py:415:0: C0301: Line too long (166/119) (line-too-long)
nemo/collections/llm/api.py:417:0: C0301: Line too long (154/119) (line-too-long)
nemo/collections/llm/api.py:419:0: C0301: Line too long (159/119) (line-too-long)
nemo/collections/llm/api.py:421:0: C0301: Line too long (168/119) (line-too-long)
nemo/collections/llm/api.py:524:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/api.py:15:0: W0611: Unused import json (unused-import)
************* Module nemo.deploy.nlp.query_llm
nemo/deploy/nlp/query_llm.py:283:0: C0301: Line too long (120/119) (line-too-long)
nemo/deploy/nlp/query_llm.py:29:0: C0115: Missing class docstring (missing-class-docstring)
nemo/deploy/nlp/query_llm.py:16:0: W0611: Unused abstractmethod imported from abc (unused-import)
************* Module nemo.deploy.service.rest_model_api
nemo/deploy/service/rest_model_api.py:90:0: C0301: Line too long (155/119) (line-too-long)
nemo/deploy/service/rest_model_api.py:91:0: C0301: Line too long (152/119) (line-too-long)
nemo/deploy/service/rest_model_api.py:22:0: C0115: Missing class docstring (missing-class-docstring)
nemo/deploy/service/rest_model_api.py:40:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/deploy/service/rest_model_api.py:44:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/deploy/service/rest_model_api.py:48:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/deploy/service/rest_model_api.py:70:0: C0115: Missing class docstring (missing-class-docstring)
nemo/deploy/service/rest_model_api.py:83:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/deploy/service/rest_model_api.py:108:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/deploy/service/rest_model_api.py:12:0: W0611: Unused Path imported from pathlib (unused-import)
************* Module nemo.export.tensorrt_llm
nemo/export/tensorrt_llm.py:118:0: C0301: Line too long (148/119) (line-too-long)
nemo/export/tensorrt_llm.py:221:0: C0301: Line too long (123/119) (line-too-long)
nemo/export/tensorrt_llm.py:223:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:224:0: C0301: Line too long (141/119) (line-too-long)
nemo/export/tensorrt_llm.py:380:0: C0301: Line too long (186/119) (line-too-long)
nemo/export/tensorrt_llm.py:991:0: C0301: Line too long (184/119) (line-too-long)
nemo/export/tensorrt_llm.py:1025:0: C0301: Line too long (131/119) (line-too-long)
nemo/export/tensorrt_llm.py:1029:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:1087:0: C0301: Line too long (121/119) (line-too-long)
nemo/export/tensorrt_llm.py:67:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:520:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:810:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:831:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:842:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:847:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:924:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:1133:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.trt_llm.tensorrt_llm_build
nemo/export/trt_llm/tensorrt_llm_build.py:31:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/tensorrt_llm_build.py:19:0: W0611: Unused Builder imported from tensorrt_llm.builder (unused-import)
nemo/export/trt_llm/tensorrt_llm_build.py:23:0: W0611: Unused add_lora imported from tensorrt_llm.models.modeling_utils (unused-import)
************* Module nemo.export.trt_llm.tensorrt_llm_run
nemo/export/trt_llm/tensorrt_llm_run.py:501:0: C0301: Line too long (123/119) (line-too-long)
nemo/export/trt_llm/tensorrt_llm_run.py:545:0: C0301: Line too long (181/119) (line-too-long)
nemo/export/trt_llm/tensorrt_llm_run.py:829:0: C0301: Line too long (153/119) (line-too-long)
nemo/export/trt_llm/tensorrt_llm_run.py:512:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/tensorrt_llm_run.py:521:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/tensorrt_llm_run.py:579:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/tensorrt_llm_run.py:33:0: W0611: Unused Mapping imported from tensorrt_llm.mapping (unused-import)
nemo/export/trt_llm/tensorrt_llm_run.py:35:0: W0611: Unused GenerationSession imported from tensorrt_llm.runtime (unused-import)
nemo/export/trt_llm/tensorrt_llm_run.py:42:4: W0611: Unused KvCacheConfig imported from tensorrt_llm.bindings (unused-import)
nemo/export/trt_llm/tensorrt_llm_run.py:42:4: W0611: Unused WorldConfig imported from tensorrt_llm.bindings (unused-import)
************* Module nemo.lightning.pytorch.callbacks.debugging
nemo/lightning/pytorch/callbacks/debugging.py:111:0: C0301: Line too long (122/119) (line-too-long)
nemo/lightning/pytorch/callbacks/debugging.py:25:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/callbacks/debugging.py:29:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module scripts.deploy.nlp.deploy_triton
scripts/deploy/nlp/deploy_triton.py:394:0: C0301: Line too long (121/119) (line-too-long)
scripts/deploy/nlp/deploy_triton.py:30:0: C0115: Missing class docstring (missing-class-docstring)
scripts/deploy/nlp/deploy_triton.py:49:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/deploy/nlp/deploy_triton.py:259:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/deploy/nlp/deploy_triton.py:371:0: C0116: Missing function or method docstring (missing-function-docstring)
scripts/deploy/nlp/deploy_triton.py:378:0: C0116: Missing function or method docstring (missing-function-docstring)

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

Thank you for improving NeMo's documentation!

Copy link
Contributor

github-actions bot commented Nov 9, 2024

[🤖]: Hi @athitten 👋,

We wanted to let you know that a CICD pipeline 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

athitten and others added 7 commits November 12, 2024 12:11
1) Refactors the code and creates an evaluation folder where all util methods live
2) Add doctsrings, comments
3) Expose gather_context_logits, gather_generation_logits in trtllm and add output_generation_logits flag to return generation logits and remove output_logporbs as its not getting used anymore

Signed-off-by: Abhishree <[email protected]>
Copy link
Contributor

beep boop 🤖: 🚨 The following files must be fixed before merge!


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

************* Module nemo.collections.llm.evaluation.eval_utils
nemo/collections/llm/evaluation/eval_utils.py:34:0: C0301: Line too long (155/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:51:0: C0301: Line too long (125/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:79:0: C0301: Line too long (149/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:80:0: C0301: Line too long (145/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:135:0: C0301: Line too long (155/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:136:0: C0301: Line too long (145/119) (line-too-long)
nemo/collections/llm/evaluation/eval_utils.py:69:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/evaluation/eval_utils.py:130:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/collections/llm/evaluation/eval_utils.py:183:0: C0116: Missing function or method docstring (missing-function-docstring)

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

Thank you for improving NeMo's documentation!

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.

1 participant