microsoft / DeepSpeed

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
https://www.deepspeed.ai/
Apache License 2.0
35.34k stars 4.1k forks source link

[BUG] Inferencev2 Mistral problems #5024

Open tatiana-iazykova opened 9 months ago

tatiana-iazykova commented 9 months ago

Describe the bug mistral doesn't fully convert to deepspeed format despite support in v2 module

To Reproduce

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
import deepspeed

model_dir = "Open-Orca/Mistral-7B-OpenOrca"

tokeniser = AutoTokenizer.from_pretrained(model_dir, use_fast=False)

model = AutoModelForCausalLM.from_pretrained(
    model_dir, 
    torch_dtype=torch.bfloat16,
    device_map='cuda'
)

model = deepspeed.init_inference(
        model=model,
        mp_size=1,  # Number of GPU.
        dtype=torch.float16,
        replace_method='auto',
        replace_with_kernel_inject=True,
        max_tokens=4096,
    )

model

Expected behavior convertion to deepspeed attention modules

ds_report output

[2024-01-29 09:14:32,288] [INFO] [real_accelerator.py:191:get_accelerator] Setting ds_accelerator to cuda (auto detect)
--------------------------------------------------
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]
cpu_lion ............... [NO] ....... [OKAY]
 [WARNING]  Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
evoformer_attn ......... [NO] ....... [NO]
fused_lamb ............. [NO] ....... [OKAY]
fused_lion ............. [NO] ....... [OKAY]
inference_core_ops ..... [NO] ....... [OKAY]
cutlass_ops ............ [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
ragged_device_ops ...... [NO] ....... [OKAY]
ragged_ops ............. [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 ............... ['/usr/local/lib/python3.11/site-packages/torch']
torch version .................... 2.0.1+cu117
deepspeed install path ........... ['/usr/local/lib/python3.11/site-packages/deepspeed']
deepspeed info ................... 0.13.1, unknown, unknown
torch cuda version ............... 11.7
torch hip version ................ None
nvcc version ..................... 11.7
deepspeed wheel compiled w. ...... torch 2.0, cuda 11.7
shared memory (/dev/shm) size .... 251.76 GB

Screenshots If applicable, add screenshots to help explain your problem.

System info (please complete the following information):

Docker context No

Additional context Add any other context about the problem here.

tatiana-iazykova commented 9 months ago

Maybe, someone can explain to me how to use InferenceEngineV2 instead of v1?

tatiana-iazykova commented 9 months ago

@tohtana

mrwyattii commented 9 months ago

Hi @tatiana-iazykova we do not support mistral models with the old inference engine. In order to use the latest inference engine, please take a look at DeepSpeed-MII. This is the front end for inference now. Here's an example for running a mistral model:

import mii
pipe = mii.pipeline("mistralai/Mistral-7B-v0.1")
response = pipe(["DeepSpeed is", "Seattle is"], max_new_tokens=128)
print(response)