DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

[BUG] inference generate raises ValueError

Open lshamis opened this issue 2 months ago • 2 comments

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)

lshamis avatar Apr 09 '24 23:04 lshamis

Try replace_with_kernel_inject=False

kizzpdd avatar Apr 11 '24 09:04 kizzpdd

@kizzpdd replace_with_kernel_inject=False does fix the crash, so the issue is most likely in the kernels.

I would like to keep replace_with_kernel_inject=True for my use case. Without it, the benchmark for deepspeed.init_inference is nearly identical to vanilla HuggingFace.

lshamis avatar Apr 11 '24 18:04 lshamis