Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Prefix Caching raises error #273

Closed
Robinysh opened this issue Sep 11, 2024 · 4 comments
Closed

[Bug]: Prefix Caching raises error #273

Robinysh opened this issue Sep 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@Robinysh
Copy link

Robinysh commented Sep 11, 2024

Your current environment

Collecting environment information...
WARNING 09-11 21:43:04 _custom_ops.py:14] Failed to import from vllm._C with ModuleNotFoundError("No module named 'vllm._C'")
PyTorch version: 2.2.2a0+gitb5d0b9b
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.30.3
Libc version: glibc-2.35

Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-92-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      46 bits physical, 57 bits virtual
Byte Order:                         Little Endian
CPU(s):                             160
On-line CPU(s) list:                0-159
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz
CPU family:                         6
Model:                              106
Thread(s) per core:                 2
Core(s) per socket:                 40
Socket(s):                          2
Stepping:                           6
CPU max MHz:                        3400.0000
CPU min MHz:                        800.0000
BogoMIPS:                           4600.00
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          3.8 MiB (80 instances)
L1i cache:                          2.5 MiB (80 instances)
L2 cache:                           100 MiB (80 instances)
L3 cache:                           120 MiB (2 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-39,80-119
NUMA node1 CPU(s):                  40-79,120-159
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] flake8==7.1.1
[pip3] galore-torch==1.0
[pip3] habana-torch-dataloader==1.16.2.2
[pip3] habana-torch-plugin==1.16.2.2
[pip3] lion-pytorch==0.2.2
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.5
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==8.9.2.26
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-ml-py==12.560.30
[pip3] nvidia-nccl-cu12==2.19.3
[pip3] nvidia-nvjitlink-cu12==12.6.20
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pynvml==8.0.4
[pip3] pytorch-lightning==2.4.0
[pip3] pytorch-metric-learning==2.6.0
[pip3] pyzmq==26.2.0
[pip3] sentence-transformers==3.0.1
[pip3] torch==2.2.2a0+gitb5d0b9b
[pip3] torch-audiomentations==0.11.1
[pip3] torch-pitch-shift==1.2.4
[pip3] torch_tb_profiler==0.4.0
[pip3] torch_warmup_lr==1.0.0
[pip3] torchaudio==2.2.0+08901ad
[pip3] torchdata==0.7.1+5e6f7b7
[pip3] torchmetrics==1.4.1
[pip3] torchtext==0.17.0+400da5c
[pip3] torchvision==0.17.0+b2383d4
[pip3] transformers==4.44.2
[pip3] transformers-stream-generator==0.0.5
[pip3] triton==2.2.0
[pip3] vector-quantize-pytorch==1.16.2
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.5.3.post1@1e0e492e1400114f9156d61ffdd73585181ed119
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
Could not collect

🐛 Describe the bug

VLLM generate raises attribute error if I enable prefix caching. Is it not supported?

import os
os.environ["VLLM_SKIP_WARMUP"] = "true"
import habana_frameworks.torch.hpu as htcore
import time
from vllm import LLM, SamplingParams


# A prompt containing a large markdown table. The table is randomly generated by GPT-4.
LONG_PROMPT = "You are a helpful assistant in recognizes the content of tables in markdown format. Here is a table as follows.\n# Table\n" + """
| ID  | Name          | Age | Occupation    | Country       | Email                  | Phone Number   | Address                       |
|-----|---------------|-----|---------------|---------------|------------------------|----------------|------------------------------|
| 1   | John Doe      | 29  | Engineer      | USA           | [email protected]   | 555-1234       | 123 Elm St, Springfield, IL  |
| 2   | Jane Smith    | 34  | Doctor        | Canada        | [email protected] | 555-5678       | 456 Oak St, Toronto, ON      |
| 3   | Alice Johnson | 27  | Teacher       | UK            | [email protected]    | 555-8765       | 789 Pine St, London, UK      |
| 4   | Bob Brown     | 45  | Artist        | Australia     | [email protected]      | 555-4321       | 321 Maple St, Sydney, NSW    |
| 5   | Carol White   | 31  | Scientist     | New Zealand   | [email protected]    | 555-6789       | 654 Birch St, Wellington, NZ |
| 6   | Dave Green    | 28  | Lawyer        | Ireland       | [email protected]     | 555-3456       | 987 Cedar St, Dublin, IE     |
| 7   | Emma Black    | 40  | Musician      | USA           | [email protected]     | 555-1111       | 246 Ash St, New York, NY     |
| 8   | Frank Blue    | 37  | Chef          | Canada        | [email protected]    | 555-2222       | 135 Spruce St, Vancouver, BC |
| 9   | Grace Yellow  | 50  | Engineer      | UK            | [email protected]    | 555-3333       | 864 Fir St, Manchester, UK   |
| 10  | Henry Violet  | 32  | Artist        | Australia     | [email protected]    | 555-4444       | 753 Willow St, Melbourne, VIC|
| 11  | Irene Orange  | 26  | Scientist     | New Zealand   | [email protected]    | 555-5555       | 912 Poplar St, Auckland, NZ  |
| 12  | Jack Indigo   | 38  | Teacher       | Ireland       | [email protected]     | 555-6666       | 159 Elm St, Cork, IE         |
| 13  | Karen Red     | 41  | Lawyer        | USA           | [email protected]    | 555-7777       | 357 Cedar St, Boston, MA     |
| 14  | Leo Brown     | 30  | Chef          | Canada        | [email protected]      | 555-8888       | 246 Oak St, Calgary, AB      |
| 15  | Mia Green     | 33  | Musician      | UK            | [email protected]      | 555-9999       | 975 Pine St, Edinburgh, UK   |
| 16  | Noah Yellow   | 29  | Doctor        | Australia     | [email protected]     | 555-0000       | 864 Birch St, Brisbane, QLD  |
| 17  | Olivia Blue   | 35  | Engineer      | New Zealand   | [email protected]   | 555-1212       | 753 Maple St, Hamilton, NZ   |
| 18  | Peter Black   | 42  | Artist        | Ireland       | [email protected]    | 555-3434       | 912 Fir St, Limerick, IE     |
| 19  | Quinn White   | 28  | Scientist     | USA           | [email protected]    | 555-5656       | 159 Willow St, Seattle, WA   |
| 20  | Rachel Red    | 31  | Teacher       | Canada        | [email protected]   | 555-7878       | 357 Poplar St, Ottawa, ON    |
| 21  | Steve Green   | 44  | Lawyer        | UK            | [email protected]    | 555-9090       | 753 Elm St, Birmingham, UK   |
| 22  | Tina Blue     | 36  | Musician      | Australia     | [email protected]     | 555-1213       | 864 Cedar St, Perth, WA      |
| 23  | Umar Black    | 39  | Chef          | New Zealand   | [email protected]     | 555-3435       | 975 Spruce St, Christchurch, NZ|
| 24  | Victor Yellow | 43  | Engineer      | Ireland       | [email protected]   | 555-5657       | 246 Willow St, Galway, IE    |
| 25  | Wendy Orange  | 27  | Artist        | USA           | [email protected]    | 555-7879       | 135 Elm St, Denver, CO       |
| 26  | Xavier Green  | 34  | Scientist     | Canada        | [email protected]   | 555-9091       | 357 Oak St, Montreal, QC     |
| 27  | Yara Red      | 41  | Teacher       | UK            | [email protected]     | 555-1214       | 975 Pine St, Leeds, UK       |
| 28  | Zack Blue     | 30  | Lawyer        | Australia     | [email protected]     | 555-3436       | 135 Birch St, Adelaide, SA   |
| 29  | Amy White     | 33  | Musician      | New Zealand   | [email protected]      | 555-5658       | 159 Maple St, Wellington, NZ |
| 30  | Ben Black     | 38  | Chef          | Ireland       | [email protected]      | 555-7870       | 246 Fir St, Waterford, IE    |
"""


def get_generation_time(llm, sampling_params, prompts):
    # time the generation
    start_time = time.time()
    output = llm.generate(prompts, sampling_params=sampling_params)
    end_time = time.time()
    # print the output and generation time
    print(f"Output: {output[0].outputs[0].text}")
    print(f"Generation time: {end_time - start_time} seconds.")


# set enable_prefix_caching=True to enable APC
llm = LLM(
    model='Qwen/Qwen2-0.5B-Instruct',
    enable_prefix_caching=True
)

sampling_params = SamplingParams(temperature=0, max_tokens=100)

# Querying the age of John Doe
get_generation_time(
    llm,
    sampling_params,
    LONG_PROMPT + "Question: what is the age of John Doe? Your answer: The age of John Doe is ",
)

# Querying the age of Zack Blue
# This query will be faster since vllm avoids computing the KV cache of LONG_PROMPT again.
get_generation_time(
    llm,
    sampling_params,
    LONG_PROMPT + "Question: what is the age of Zack Blue? Your answer: The age of Zack Blue is ",
)

Output:

...
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1523, in _call_impl                                                                                                                         
    return forward_call(*args, **kwargs)                                                                                                                                                                                                                      
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/model_executor/models/llama.py", line 245, in forward                                                                                                                    
    hidden_states = self.self_attn(                                                                                                                                                                                                                           
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1514, in _wrapped_call_impl                                                                                                                 
    return self._call_impl(*args, **kwargs)                                                                                                                                                                                                                   
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1523, in _call_impl                                                                                                                         
    return forward_call(*args, **kwargs)                                                                                                                                                                                                                      
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/model_executor/models/llama.py", line 175, in forward                                                                                                                    
    attn_output = self.attn(q, k, v, kv_cache, attn_metadata)                                                                                                                                                                                                 
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1514, in _wrapped_call_impl                                                                                                                 
    return self._call_impl(*args, **kwargs)                                                                                                                                                                                                                   
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1523, in _call_impl                                                                                                                         
    return forward_call(*args, **kwargs)                                                                                                                                                                                                                      
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/attention/layer.py", line 97, in forward                                                                                                                                 
    return self.impl.forward(query,                                                                                                                                                                                                                           
  File "/storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/attention/backends/habana_attn.py", line 246, in forward                                                                                                                 
    attn_metadata.subquery_start_loc,                                                                                                                                                                                                                         
AttributeError: 'TrimmedAttentionMetadata' object has no attribute 'subquery_start_loc'  
@Robinysh Robinysh added the bug Something isn't working label Sep 11, 2024
@huijjj
Copy link

huijjj commented Sep 12, 2024

I made a pull request few weeks ago when flat pa wasn't ported to habana_main yet. I am currently rebasing my PR to current habana_main. You will be able to use prefix caching after this PR gets merged. Please take a look if you are interested.

@Robinysh
Copy link
Author

Robinysh commented Sep 12, 2024

You are a god sent. The code works well. However I have noticed theres an error with the cache when lazy mode is disabled.

import os
os.environ["PT_HPU_LAZY_MODE"] = "0"

# run vllm generate with prefix caching here

Output:

File /storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/hpu/cache_ops.py:72, in insert_or_update_cache(input, cache, num_kv_cache_passes, num_slots_available, block_indices, block_offsets)
     70 start_idx = i * num_slots_available
     71 end_idx = (i + 1) * num_slots_available
---> 72 cache.index_put_((block_indices[start_idx:end_idx],
     73                   block_offsets[start_idx:end_idx]),
     74                  input[start_idx:end_idx])

IndexError: index 16777215 is out of bounds for dimension 0 with size 31575

@huijjj
Copy link

huijjj commented Sep 12, 2024

You are a god sent. The code works well. However I have noticed theres an error with the cache when lazy mode is disabled.

import os
os.environ["PT_HPU_LAZY_MODE"] = "0"

# run vllm generate with prefix caching here

Output:

File /storage/robinysh/code/EvalSpeechLLM/.venv/lib/python3.10/site-packages/vllm/hpu/cache_ops.py:72, in insert_or_update_cache(input, cache, num_kv_cache_passes, num_slots_available, block_indices, block_offsets)
     70 start_idx = i * num_slots_available
     71 end_idx = (i + 1) * num_slots_available
---> 72 cache.index_put_((block_indices[start_idx:end_idx],
     73                   block_offsets[start_idx:end_idx]),
     74                  input[start_idx:end_idx])

IndexError: index 16777215 is out of bounds for dimension 0 with size 31575

Thank you for letting me know, I haven't check the cases when lazy mode is disabled yet. I'll check if error persists after the rebase and fix it if possible.

Also, please note that my PR may not work without enforce_eager=True as I haven't checked for HpuGraph compatibilities either.

@michalkuligowski
Copy link

Fixed in #162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants