deepspeedai / deepspeedai/DeepSpeed

[BUG] StarCoder inference not working with AutoTP

Open
#4,511 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug inference
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

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):

  • OS: red hat
  • GPU count and types: 4 x A10 GPUs
  • (if applicable) Hugging Face Transformers/Accelerate/etc. versions: transformers 4.34.0
  • Python version: 3.8
  • Any other relevant info about your setup

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

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided deepspeed_starcoder.py reproduction and the deepspeed.init_inference call using AutoTP, then trace how the StarCoder checkpoint is partitioned across the four processes. Reproduce the split_with_sizes error with the stated Transformers, PyTorch, DeepSpeed, and GPU setup; done means StarCoder inference completes successfully with AutoTP.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.