deepspeedai / deepspeedai/DeepSpeed
[BUG] Unable to initialize DeepSpeed Inference
Open
@mrwyattii is already working on this.
Since Sep 13, 2023.
bug
inference
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
Hi All, I am trying to run inference for Falcon-40b with deepspeed inference but ending up with no response.
I am using below code to run the inference.
I want to run my inference over fast api, i am not sure if thats even possible or not.
Can someone please advice ?
script.py:
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import deepspeed
from deepspeed.accelerator import get_accelerator
import os
app = FastAPI()
# Initialize model and tokenizer
model_name = "tiiuae/falcon-40b"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).bfloat16()
model = deepspeed.init_inference(model, mp_size=4)
class TextGenerationInput(BaseModel):
prompt: str
@app.post("/generate")
def generate_text(input_data: TextGenerationInput):
input_prompt = input_data.prompt
input_tokens = tokenizer.encode_plus(input_prompt, return_tensors="pt", truncation=True, max_length=2048)
for t in input_tokens:
if torch.is_tensor(input_tokens[t]):
input_tokens[t] = input_tokens[t].to(get_accelerator().current_device_name())
input_tokens.pop('token_type_ids', None)
sequences = model.generate(**input_tokens, min_length=200, max_length=300, do_sample=True)
result = tokenizer.decode(sequences[0], skip_special_tokens=True)
return {"result": result}
if __name__ == "__main__":
import uvicorn
# Dynamically set the port based on LOCAL_RANK
port = 8000 + int(os.environ.get("LOCAL_RANK", 0))
uvicorn.run(app, host="0.0.0.0", port=port)
Error:
When i am hitting curl request, it's just stuck for forever.
Environment:
OS - Ubuntu [g5-48xlarge (8gpu - 23 gb each)]
Python - 3.10.11
Deepspeed - 0.10.2
Torch - 2.0.1+cu117
Transformers - 4.33.1
To Reproduce
Steps to reproduce the behavior:
deepspeed --num_gpus 4 script.py
Expected behavior
Should not hang and generate the response.
ds_report output
--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
runtime if needed. Op compatibility means that your system
meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
[WARNING] async_io requires the dev libaio .so object and headers but these were not found.
[WARNING] async_io: please install the libaio-dev package with apt
[WARNING] If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
fused_adam ............. [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
fused_lamb ............. [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
random_ltd ............. [NO] ....... [OKAY]
[WARNING] sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.0
[WARNING] using untested triton version (2.0.0), only 1.0.0 is known to be compatible
sparse_attn ............ [NO] ....... [NO]
spatial_inference ...... [NO] ....... [OKAY]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
transformer_inference .. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/home/ubuntu/.local/share/virtualenvs/app-uM23XpkP/lib/python3.10/site-packages/torch']
torch version .................... 2.0.1+cu117
deepspeed install path ........... ['/home/ubuntu/.local/share/virtualenvs/app-uM23XpkP/lib/python3.10/site-packages/deepspeed']
deepspeed info ................... 0.10.2, unknown, unknown
torch cuda version ............... 11.7
torch hip version ................ None
nvcc version ..................... 11.8
deepspeed wheel compiled w. ...... torch 2.0, cuda 11.7
shared memory (/dev/shm) size .... 373.97 GB
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.