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

deepspeed inf + multi-gpu chatbot #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions examples/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from lmflow.pipeline.auto_pipeline import AutoPipeline
from lmflow.models.auto_model import AutoModel
from lmflow.args import ModelArguments, DatasetArguments, AutoArguments

import torch.distributed as dist

logging.disable(logging.ERROR)
warnings.filterwarnings("ignore")
Expand Down Expand Up @@ -70,7 +70,8 @@ def main():
f"#############################################################################\n"
"\n"
)
print(guide_message, end="")
if dist.get_rank() == 0:
print(guide_message, end="")

# context = (
# "You are a helpful assistant who follows the given instructions"
Expand All @@ -80,8 +81,15 @@ def main():
end_string = "\n\n"

while True:
input_text = input("User >>> ")
if not input_text:
if dist.get_rank() == 0:
input_text = input("User >>> ")
dist.broadcast_object_list([input_text])
else:
recev_object = [None] * 1
dist.broadcast_object_list(recev_object)
input_text = recev_object[0]

if input_text == "exit":
print("exit...")
break

Expand All @@ -108,7 +116,8 @@ def main():
index = response.index(end_string)

response = response[:index + 1]
print("Bot: " + response, end="")
if dist.get_rank() == 0:
print("Bot: " + response, end="")
context += response
context = context[-model.get_max_length():] # Memory of the bot

Expand Down
12 changes: 8 additions & 4 deletions src/lmflow/models/hf_decoder_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
from lmflow.models.decoder_model import DecoderModel
from lmflow.models.interfaces.tunable import Tunable

from transformers.models.llama.modeling_llama import LlamaDecoderLayer


class HFDecoderModel(DecoderModel, Tunable):
r"""
Expand Down Expand Up @@ -179,7 +181,6 @@ def __init__(
self.tune_strategy = tune_strategy

elif tune_strategy == 'none':
dschf = HfDeepSpeedConfig(ds_config)
self.backend_model = AutoModelForCausalLM.from_pretrained(model_args.model_name_or_path)
self.tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path)
peft_model_id = model_args.lora_model_path
Expand All @@ -188,9 +189,12 @@ def __init__(
self.backend_model, peft_model_id
)

deepspeed.init_distributed()
self.ds_engine = deepspeed.initialize(model=self.backend_model, config_params=ds_config)[0]
self.ds_engine.module.eval()
self.ds_engine = deepspeed.init_inference(
self.backend_model,
mp_size=2,
dtype=torch.half,
injection_policy={LlamaDecoderLayer: ('self_attn.o_proj', 'mlp.down_proj')}
)

elif tune_strategy == 'adapter':
raise NotImplementedError('adapter tune strategy not implemented')
Expand Down