-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Adding server option to peft eval #7292
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0789d3f
Adding server to peft eval
Davood-M 378b45f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2ef4733
updated trainer.test for server
Davood-M 8a79b27
Merge branch 'davidm/peft_server_gpt' of github.com:NVIDIA/NeMo into …
Davood-M File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,13 @@ | |
# limitations under the License. | ||
|
||
|
||
import asyncio | ||
import json | ||
import os | ||
import threading | ||
from functools import partial | ||
|
||
import torch | ||
import torch.multiprocessing as mp | ||
from omegaconf.omegaconf import OmegaConf, open_dict | ||
from pytorch_lightning import Trainer | ||
|
@@ -25,6 +29,8 @@ | |
from nemo.collections.nlp.models.language_modeling.megatron_gpt_peft_models import MegatronGPTPEFTModel | ||
from nemo.collections.nlp.models.language_modeling.megatron_gpt_sft_model import MegatronGPTSFTModel | ||
from nemo.collections.nlp.models.nlp_model import NLPModel | ||
from nemo.collections.nlp.modules.common.text_generation_server import MegatronServer | ||
from nemo.collections.nlp.modules.common.text_generation_utils import generate | ||
from nemo.collections.nlp.parts.nlp_overrides import ( | ||
GradScaler, | ||
MegatronHalfPrecisionPlugin, | ||
|
@@ -36,6 +42,13 @@ | |
from nemo.core.config import hydra_runner | ||
from nemo.utils import logging | ||
|
||
try: | ||
from megatron.core import parallel_state | ||
|
||
HAVE_MEGATRON_CORE = True | ||
except: | ||
Check notice Code scanning / CodeQL Empty except Note
'except' clause does nothing but pass and there is no explanatory comment.
|
||
pass | ||
|
||
mp.set_start_method("spawn", force=True) | ||
""" | ||
This is the script to run inference with a PEFT model or an SFT Model. | ||
|
@@ -179,6 +192,44 @@ | |
|
||
trainer.test(model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we skip |
||
|
||
if cfg.server: | ||
if not HAVE_MEGATRON_CORE: | ||
raise ValueError('Megatron-core needs to be installed to use this feature!') | ||
|
||
from nemo.collections.nlp.modules.common.megatron_web_server import get_chatbot_demo, get_demo | ||
|
||
if parallel_state.is_pipeline_first_stage() and parallel_state.get_tensor_model_parallel_rank() == 0: | ||
if cfg.web_server: | ||
if cfg.chat: | ||
defaults = { | ||
'user': cfg.chatbot_config.user, | ||
'assistant': cfg.chatbot_config.assistant, | ||
'system': cfg.chatbot_config.system, | ||
} | ||
web_ui = partial( | ||
get_chatbot_demo, | ||
defaults=defaults, | ||
value=cfg.chatbot_config.value, | ||
attributes=cfg.chatbot_config.attributes, | ||
) | ||
else: | ||
web_ui = get_demo | ||
loop = asyncio.new_event_loop() | ||
thread = threading.Thread( | ||
target=web_ui, | ||
daemon=True, | ||
args=(cfg.share, cfg.username, cfg.password, cfg.port, cfg.web_port, loop), | ||
) | ||
thread.start() | ||
server = MegatronServer(model.cuda()) | ||
server.run("0.0.0.0", port=cfg.port) | ||
|
||
while True: | ||
choice = torch.cuda.LongTensor(1) | ||
torch.distributed.broadcast(choice, 0) | ||
if choice[0].item() == 0: | ||
generate(model.cuda()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Except block handles 'BaseException' Note