在常规的推理框架中,当我们的服务接收到一条请求时,它会为这条请求中的prompts分配gpu显存空间,其中就包括对KV cache的分配。由于推理所生成的序列长度大小是无法事先预知的,所以大部分框架会按照(batch_size, max_seq_len)这样的固定尺寸,在gpu显存上预先为一条请求开辟一块连续的矩形存储空间。然而,这样的分配...
vllm能够通过PageAttention内存优化方法,将BatchSize大大拓展 ,对于业务而言相当于能处理并发的客户请求数变多了,是一件极具性价比的事情, 因此推理业务广泛使用该框架。 PageAttention 原理 PagedAttention灵感来自于操作系统中虚拟内存和分页的经典思想,它可以允许在非连续空间立存储连续的KV张量。具体来说,PagedAttention...
直观地,此参数可以看作是增加 GPU 内存大小的一种虚拟方式。例如,如果您有一个24GB 的 GPU,并将其设置为10,那么实际上您可以将其视为一个34GB 的 GPU。然后,您可以使用 BF16 权重加载一个 13B 模型,这至少需要 26GB 的 GPU 内存。请注意,这需要快速的 CPU-GPU 互连,因为模型的一部分在每次模型前向传递...
INFO01-1808:13:39model_runner.py:505] CUDA graphs can take additional1~3GiB memory per GPU.Ifyou are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. INFO01-1808:13:44model_runner.py:547] Graph capturing finishedin5secs. prompts = ["Hello, my...
blk_size:也就是 block_size,是 KVCache page 的最高维,KVCache 是若干个 page 的集合,每个 page 存(blk_size, num_head,head_size)个 K、V 的元素。 head_mapping [num_heads] 用于 MQA, GQA,确定用的 KV_head block_tables [num_seqs, max_num_blocks_per_seq] block_tables 映射表,表示每个 se...
(64-bit runtime) Python platform: Linux-4.15.0-136-generic-x86_64-with-glibc2.27 Is CUDA available: True CUDA runtime version: 12.1.105 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: Tesla T4 GPU 1: Tesla T4 GPU 2: Tesla T4 GPU 3: Tesla T4 Nvidia driver ...
tensor_parallel_size=2, trust_remote_code=True, load_format="pt") def process_prompts(prompts): sampling_params = SamplingParams(temperature=0.0, top_p=1.0, max_tokens=500) return llm.generate(prompts, sampling_params) prompt_batch_1 = ["Hello, my name is", "The president of the United...
最简单的提升推理效率的方式是避免通过加大矩阵乘法的尺寸来避免 Memory Bound 和增强 GPU 计算效率,但大的矩阵乘法意味着大的batch_size,导致KV Cache对内存需求很大。 所以我们想到通过 Optimizer 的 Offload 将 Adam 优化器权重放到 CPU 内存中来节省内存,并且通过 Pinned Memory 避免梯度聚合时候的GPU-CPU通信效率...
--tensor-parallel-size:并行推理数,建议和GPU个数相同。 --gpu-memory-utilization:GPU显存使用率。 --kv-cache-dtype:KV量化类型。 --max-num-seqs:一次推理最多能处理的sequences数量。 --max-num-batched-tokens:一次推理最多能处理的tokens数量。
--max-num-seqswill restrict the generation for both first token and rest token. It will restrict the maximum batch size to the value set by--max-num-seqs. When out-of-memory error occurs, the most obvious solution is to reduce thegpu-memory-utilization. Other ways to resolve this error...