deepspeedai / deepspeedai/DeepSpeed
[BUG] layer_past is ignored by DeepSpeedSelfAttention's compute_attention
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
Describe the bug
The past_key_values provided to the model are ignored by DeepSpeedSelfAttention.
To Reproduce
Call a deep speed inference model with past_key_values and note that at the following line the data (now stored as the layer_past argument) gets ignored: https://github.com/microsoft/DeepSpeed/blob/2f8d384e8bf3644e11e7bb2c658ddfcea7c611b1/deepspeed/ops/transformer/inference/ds_attention.py#L90
It looks like the "BloomSelfAttention" class does not ignore layer_past, but that is not the class that is used by default.
Expected behavior
I use past_key_values to enable acceleration of structured outputs for Transformers models: https://github.com/microsoft/guidance/blob/main/notebooks/guidance_acceleration.ipynb I would like to be able to do the same for DeepSpeed models.
For standard transformers passing past_key_values prefixes those key-values to before the input_ids when computing attention.
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
--------------------------------------------------
async_io ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
cpu_adam ............... [NO] ....... [OKAY]
fused_adam ............. [NO] ....... [OKAY]
fused_lamb ............. [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]
utils .................. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... ['/home/sclundbe/anaconda3/lib/python3.9/site-packages/torch']
torch version .................... 2.0.0+cu117
deepspeed install path ........... ['/home/sclundbe/anaconda3/lib/python3.9/site-packages/deepspeed']
deepspeed info ................... 0.9.1, unknown, unknown
torch cuda version ............... 11.7
torch hip version ................ None
nvcc version ..................... 11.3
deepspeed wheel compiled w. ...... torch 1.12, cuda 11.3
System info (please complete the following information):
- OS: Ubuntu 20.04
- GPU count and types: 4x A6000 but does not matter here
- Python version: 3.9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in deepspeed/ops/transformer/inference/ds_attention.py at the referenced line around 90, and compare how BloomSelfAttention handles layer_past. Reproduce a DeepSpeed inference call with past_key_values and verify that the supplied key-values are included when computing attention, matching standard Transformers behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100