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
34.42k stars 4.02k forks source link

[BUG] StarCoder inference not working with AutoTP #4511

Open Epliz opened 10 months ago

Epliz commented 10 months ago

Describe the bug StartCoder inference with AutoTP doesn't work. I get the following error:

  File "[...]/venv38/lib64/python3.8/site-packages/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py", line 316, in forward                                                        
    attn_outputs = self.attn(
  File "[...]/venv38/lib64/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl                                                                                 
    return forward_call(*args, **kwargs)                                                                                                                                                                  
  File "[...]/venv38/lib64/python3.8/site-packages/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py", line 230, in forward                                                        
    query, key_value = self.c_attn(hidden_states).split((self.embed_dim, 2 * self.kv_dim), dim=2)                                                                                                         
  File "[...]/venv38/lib64/python3.8/site-packages/torch/_tensor.py", line 803, in split                                                                                                 
    return torch._VF.split_with_sizes(self, split_size, dim)
RuntimeError: split_with_sizes expects split_sizes to sum exactly to 1600 (input tensor's size at dimension 2), but got split_sizes=[1536, 256]

To Reproduce Script:

# ran with deepspeed --num_gpus 4 deepspeed_starcoder.py

import os
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch
import deepspeed

local_rank = int(os.getenv('LOCAL_RANK', '0'))
world_size = int(os.getenv('WORLD_SIZE', '1'))

checkpoint = "bigcode/starcoder"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint)

print("Loaded model")

# Doesn't work with AutoTP: (or replace_with_kernel_inject=True, but different errors)
ds_engine = deepspeed.init_inference(model=model, mp_size=world_size, dtype=torch.bfloat16)

print("Initialized DeepSpeed inference engine")

generator = pipeline('text-generation', model=ds_engine.module, tokenizer=tokenizer, device=local_rank)

ret = generator("DeepSpeed is", do_sample=True, max_new_tokens=200) # Fails during inference here

if not torch.distributed.is_initialized() or torch.distributed.get_rank() == 0:
  print(ret)

Expected behavior It should work

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-devel package with yum
 [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]
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 ............... [[...]venv38/lib64/python3.8/site-packages/torch']
torch version .................... 2.0.1+cu117
deepspeed install path ........... ['[...]/venv38/lib64/python3.8/site-packages/deepspeed']
deepspeed info ................... 0.11.1, unknown, unknown
torch cuda version ............... 11.7
torch hip version ................ None
nvcc version ..................... 12.1
deepspeed wheel compiled w. ...... torch 2.0, cuda 11.7
shared memory (/dev/shm) size .... 503.51 GB

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

System info (please complete the following information):

Docker context Are you using a specific docker image that you can share?

Additional context Add any other context about the problem here.

Epliz commented 10 months ago

This is weird to me that inference doesn't work, while training with Zero 3 works for StarCoder.

delock commented 7 months ago

https://github.com/microsoft/DeepSpeed/pull/4896 add StarCoder AutoTP support.