deepspeedai / deepspeedai/DeepSpeed

[BUG] inference generate raises ValueError

Open
#5,388 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
Calls to model.generate with deepspeed.init_inference model raises ValueError: too many values to unpack (expected 2).

To Reproduce

import deepspeed
import traceback
import transformers

def main():
    pipeline = transformers.pipeline(
        "text-generation",
        model="/path/to/llama-2-7b-hf",
        device_map="cuda",
        batch_size=32,
    )
    pipeline.tokenizer.pad_token_id = pipeline.tokenizer.eos_token_id

    pipeline.model = deepspeed.init_inference(
        pipeline.model,
        max_out_tokens=4096,
        replace_with_kernel_inject=True,
    )

    try:
        pipeline(["012345", "0 1 2 3 4 5", "0, 1, 2, 3, 4, 5"])
    except Exception as err:
        print(err)
        print(traceback.format_exc())

if __name__ == "__main__":
    main()

Expected behavior
pipeline.__call__ should work with any batch size. Only works with batch_size 2.

ds_report output

$ ds_report
[2024-04-09 23:14:37,836] [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]
transformer_inference .. [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.2
 [WARNING]  using untested triton version (2.2.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]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/data/home/lshamis/conda/envs/onellm_bench_deepspeed/lib/python3.11/site-packages/torch']
torch version .................... 2.2.2+cu121
deepspeed install path ........... ['/data/home/lshamis/conda/envs/onellm_bench_deepspeed/lib/python3.11/site-packages/deepspeed']
deepspeed info ................... 0.14.0, unknown, unknown
torch cuda version ............... 12.1
torch hip version ................ None
nvcc version ..................... 11.7
deepspeed wheel compiled w. ...... torch 2.1, cuda 12.1
shared memory (/dev/shm) size .... 560.90 GB

Screenshots
No Screenshots

System info (please complete the following information):

  • OS: Ubuntu 20.04.6 LTS
  • Python version: Python 3.11.8
  • DeepSpeed: 0.14.0
  • Hugging Face Transformers: 4.39.3
  • Accelerate: 0.21.0

Docker context
No docker

Additional context
Here is the full stack trace:

Traceback (most recent call last):
  File "/tmp/tmp.py", line 21, in main
    pipeline(["012345", "0 1 2 3 4 5", "0, 1, 2, 3, 4, 5"])
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/text_generation.py", line 240, in __call__
    return super().__call__(text_inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/base.py", line 1187, in __call__
    outputs = list(final_iterator)
              ^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/pt_utils.py", line 124, in __next__
    item = next(self.iterator)
           ^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/pt_utils.py", line 125, in __next__
    processed = self.infer(item, **self.params)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/base.py", line 1112, in forward
    model_outputs = self._forward(model_inputs, **forward_params)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/pipelines/text_generation.py", line 327, in _forward
    generated_sequence = self.model.generate(input_ids=input_ids, attention_mask=attention_mask, **generate_kwargs)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/deepspeed/inference/engine.py", line 636, in _generate
    return self.module.generate(*inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/generation/utils.py", line 1527, in generate
    result = self._greedy_search(
             ^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/generation/utils.py", line 2411, in _greedy_search
    outputs = self(
              ^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/models/llama/modeling_llama.py", line 1196, in forward
    outputs = self.model(
              ^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/models/llama/modeling_llama.py", line 977, in forward
    past_key_values = DynamicCache.from_legacy_cache(past_key_values)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/conda/envs/test_deepspeed/lib/python3.11/site-packages/transformers/cache_utils.py", line 182, in from_legacy_cache
    key_states, value_states = past_key_values[layer_idx]
    ^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

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 deepspeed/inference/engine.py at _generate, then follow the traceback through Transformers generation and cache_utils.py. Reproduce the reported pipeline call with a batch of three inputs and the stated versions; done means batched generation no longer raises the cache unpacking ValueError.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.