vllm [Bug]:在分析运行中,计算log_probs的VRAM使用量未被考虑,

dzhpxtsq  于 3个月前  发布在  其他
关注(0)|答案(9)|浏览(52)

当前环境

The output of `python collect_env.py`

Collecting environment information...
PyTorch version: 2.3.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

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

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.9.1-arch1-1-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4070 Ti SUPER
Nvidia driver version: 550.78
cuDNN version: Could not collect
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, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               24
On-line CPU(s) list:                  0-23
Vendor ID:                            GenuineIntel
Model name:                           13th Gen Intel(R) Core(TM) i7-13700K
CPU family:                           6
Model:                                183
Thread(s) per core:                   2
Core(s) per socket:                   16
Socket(s):                            1
Stepping:                             1
CPU max MHz:                          5400.0000
CPU min MHz:                          800.0000
BogoMIPS:                             6837.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                       VT-x
L1d cache:                            640 KiB (16 instances)
L1i cache:                            768 KiB (16 instances)
L2 cache:                             24 MiB (10 instances)
L3 cache:                             30 MiB (1 instance)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-23
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Mitigation; Clear Register File
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[pip3] mypy==1.9.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.4
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] torch==2.3.0
[pip3] triton==2.3.0
[pip3] vllm-nccl-cu12==2.18.1.0.4.0
[conda] Could not collectROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.4.2
vLLM Build Flags:
CUDA Archs: 7.0 7.5 8.0 8.6 8.9 9.0+PTX; ROCm: Disabled; Neuron: Disabled
GPU Topology:
�[4mGPU0	CPU Affinity	NUMA Affinity	GPU NUMA ID�[0m
GPU0	 X 	0-23	0		N/A

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

🐛 描述bug

在为LoRA添加新功能到vLLM时,我遇到了一个意外的 CUDA out of memory 错误。经过尝试不同的设置,我发现这个bug只出现在 prompt_logprobsSamplingParams 中被设置为非零值,并且使用了长提示长度的情况下,就像在 #1532 中提到的那样。然后我试图定位bug并找到了以下内容(一些不重要的回溯被省略):

[rank0]: Traceback (most recent call last):
[rank0]:   File "/workspace/vllm/worker/model_runner.py", line 721, in execute_model
[rank0]:     output = self.model.sample(
[rank0]:   File "/workspace/vllm/model_executor/models/llama.py", line 381, in sample
[rank0]:     next_tokens = self.sampler(logits, sampling_metadata)
[rank0]:   File "/workspace/vllm/model_executor/layers/sampler.py", line 72, in forward
[rank0]:     logits = _apply_penalties(logits, sampling_tensors.prompt_tokens,
[rank0]:   File "/workspace/vllm/model_executor/layers/sampler.py", line 208, in _apply_penalties
[rank0]:     output_bin_counts, output_mask = _get_bin_counts_and_mask(
[rank0]:   File "/workspace/vllm/model_executor/layers/sampler.py", line 143, in _get_bin_counts_and_mask
[rank0]:     bin_counts = torch.zeros((num_seqs, vocab_size + 1),
[rank0]: torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 3.41 GiB. GPU

这个bug是由 _get_bin_counts_and_mask 中的采样阶段计算引起的。当 prompt_logprobs 被启用时,会计算提示中所有tokens的对数概率(对于Llama 3,最多有8192个tokens),导致内存使用量高达
$$num tokens \times vocab\ size times 4 \text{Bytes} = 8192 \times 128256 times 4 \text{Bytes} = 7.8 \text{GiB}$$
然而,这个内存使用量并没有在 profile_run() 中预测到,因为采样参数被设置为:

# Enable top-k sampling to reflect the accurate memory usage.
sampling_params = SamplingParams(top_p=0.99, top_k=self.vocab_size - 1)

这仅考虑了最多256个tokens(最大批量序列计数)的对数概率计算。

ecbunoof

ecbunoof1#

解决这个问题的一个简单方法是在scheduler.py中的以下函数中添加限制$log\ prob\ tokens< max\ seqs$:

def can_schedule(self, *, num_new_tokens: int, num_new_seqs: int):
        assert num_new_tokens != 0
        assert num_new_seqs != 0
        return (self.num_batched_tokens + num_new_tokens <= self.token_budget
                and self.num_curr_seqs + num_new_seqs <= self.max_num_seqs)

如果这个解决方案是可以接受的,我稍后可以提交一个拉取请求。

dojqjjoe

dojqjjoe2#

我同意这是一个需要解决的问题。但我不完全明白log_prob_tokens < max_seqs是如何成为正确的解决方案的,这是不是有点过于粗粒度了?

pxiryf3j

pxiryf3j3#

我同意你的观点。我提出的另一个更细粒度的解决方案是,在 EngineArgs 中添加一个新的参数 max_num_logprobs(默认值为 max_num_seqs )。但是,我担心这个参数可能很少被使用。你怎么看?

zlhcx6iw

zlhcx6iw4#

我同意你的看法。另一个更细粒度的解决方案是,向 EngineArgs 添加一个新参数 max_num_logprobs(默认值为 max_num_seqs )。但是,我担心这个参数可能很少被使用。
你怎么看?
我认为我们应该有一些用户控制的 max_num_logprobs 参数,并设置合理的默认值。我来问问其他小组成员的意见。
然后我们需要:

  • 更新性能分析逻辑以考虑这个因素
  • 更新调度器逻辑以考虑这个因素
o2rvlv0m

o2rvlv0m5#

@robertgshaw2-neuralmagic 感谢您考虑这个问题。
接下来我们需要:

  • 更新分析逻辑以考虑这个因素
  • 更新调度器逻辑以考虑这个因素

这个修改应该不会太困难。鉴于当前代码的简洁结构,似乎可以通过在调度器的 profile_runcan_schedule 中添加生成提示的逻辑来实现。

nbewdwxp

nbewdwxp6#

遇到了这个问题:(

jk9hmnmh

jk9hmnmh7#

@Conless,你愿意解决这个问题吗?我同意这是一个很好的改进——我在进行MMLU上的LLM评估时遇到了这个问题,这需要大量的对数概率。

dgenwo3n

dgenwo3n8#

@mgoin 没问题,我很乐意解决这个问题。

lhcgjxsq

lhcgjxsq9#

遇到了同样的问题:(有没有快速解决的方法?

相关问题