vllm-project / vllm

A high-throughput and memory-efficient inference and serving engine for LLMs
https://docs.vllm.ai
Apache License 2.0
29.97k stars 4.53k forks source link

[Usage]: Can spec_decode and repetition_penalty be used together? #6718

Closed Time-Limit closed 3 months ago

Time-Limit commented 3 months ago

Your current environment

Nvidia driver version: 535.104.05 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.0.0 /usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.0.0 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: 43 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: AuthenticAMD Model name: AMD EPYC 7452 32-Core Processor CPU family: 23 Model: 49 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 0 Frequency boost: enabled CPU max MHz: 2350.0000 CPU min MHz: 1500.0000 BogoMIPS: 4699.94 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es Virtualization: AMD-V L1d cache: 2 MiB (64 instances) L1i cache: 2 MiB (64 instances) L2 cache: 32 MiB (64 instances) L3 cache: 256 MiB (16 instances) NUMA node(s): 8 NUMA node0 CPU(s): 0-7,64-71 NUMA node1 CPU(s): 8-15,72-79 NUMA node2 CPU(s): 16-23,80-87 NUMA node3 CPU(s): 24-31,88-95 NUMA node4 CPU(s): 32-39,96-103 NUMA node5 CPU(s): 40-47,104-111 NUMA node6 CPU(s): 48-55,112-119 NUMA node7 CPU(s): 56-63,120-127 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Retbleed: Mitigation; untrained return thunk; SMT enabled with STIBP protection 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; Retpolines, IBPB conditional, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] numpy==1.24.4 [pip3] nvidia-nccl-cu12==2.19.3 [pip3] onnx==1.15.0rc2 [pip3] optree==0.10.0 [pip3] pytorch-quantization==2.1.2 [pip3] pytorch-triton==2.2.0+e28a256d7 [pip3] torch==2.2.0 [pip3] torch-tensorrt==2.3.0a0 [pip3] torchdata==0.7.1a0 [pip3] torchtext==0.17.0a0 [pip3] torchvision==0.17.0 [pip3] transformers==4.35.2 [pip3] triton==2.2.0 [pip3] tritonclient==2.39.0 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: N/A vLLM Build Flags: CUDA Archs: 5.2 6.0 6.1 7.0 7.2 7.5 8.0 8.6 8.7 9.0+PTX; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7 NIC0 NIC1 NIC2 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X SYS SYS SYS SYS SYS SYS SYS SYS SYS SYS 24-31,88-95 3 N/A GPU1 SYS X SYS SYS SYS SYS SYS SYS SYS SYS SYS 16-23,80-87 2 N/A GPU2 SYS SYS X SYS SYS SYS SYS SYS SYS SYS SYS 8-15,72-79 1 N/A GPU3 SYS SYS SYS X SYS SYS SYS SYS SYS SYS SYS 0-7,64-71 0 N/A GPU4 SYS SYS SYS SYS X SYS SYS SYS SYS SYS SYS 56-63,120-127 7 N/A GPU5 SYS SYS SYS SYS SYS X SYS SYS SYS SYS SYS 48-55,112-119 6 N/A GPU6 SYS SYS SYS SYS SYS SYS X SYS PHB PHB PHB 40-47,104-111 5 N/A GPU7 SYS SYS SYS SYS SYS SYS SYS X SYS SYS SYS 32-39,96-103 4 N/A NIC0 SYS SYS SYS SYS SYS SYS PHB SYS X PIX PHB NIC1 SYS SYS SYS SYS SYS SYS PHB SYS PIX X PHB NIC2 SYS SYS SYS SYS SYS SYS PHB SYS PHB PHB X

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

NIC Legend:

NIC0: mlx5_2 NIC1: mlx5_3 NIC2: mlx5_bond_0

How would you like to use vllm

Can spec_decode and repetition_penalty be used together?

cadedaniel commented 3 months ago

Yep!

Time-Limit commented 3 months ago

When use spec decode, each iteration may generate multiple tokens,such as T0, T1, T2. Because the three tokens generated in a same iteration(forward → penalty → sample), so I think when vLLM calculates logits of T2 with repetition penalty strategy, T0 and T1 is not sure, vLLm is unable to determine whether T0 and T1 are the same as T2, so how to penalty the logits of T2?

@cadedaniel Could you explain this issue or point out where my understanding seems incorrect? Thanks very much!

cadedaniel commented 3 months ago

The short answer is that scoring the first speculative token is equivalent to computing P(x_1|prefix), where x_1 is the first speculative token. For x_2, it is P(x_2|prefix+x_1), and so on for the third speculative token P(x_3|prefix+x_1+x_2). Because during scoring all of x_n are known, we are able to correctly apply repetition penalty for each position. Finally, if any x_n is rejected during rejection sampling, all subsequent speculative tokens are also rejected, which preserves the distribution of the target model (including perturbations to the target model distribution incurred from sampling parameters like repetition penalty).

Time-Limit commented 3 months ago

The short answer is that scoring the first speculative token is equivalent to computing P(x_1|prefix), where x_1 is the first speculative token. For x_2, it is P(x_2|prefix+x_1), and so on for the third speculative token P(x_3|prefix+x_1+x_2). Because during scoring all of x_n are known, we are able to correctly apply repetition penalty for each position. Finally, if any x_n is rejected during rejection sampling, all subsequent speculative tokens are also rejected, which preserves the distribution of the target model (including perturbations to the target model distribution incurred from sampling parameters like repetition penalty).

Got it! Thanks very much!