vllm-project / vllm

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

[Usage]: How to inference a model with medusa speculative sampling. #6768

Open deepindeed2022 opened 4 months ago

deepindeed2022 commented 4 months ago

Your current environment

Collecting environment information... PyTorch version: 2.3.1+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.30.0 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-5.15.0-125.006-nvidia-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA H100 80GB HBM3 GPU 1: NVIDIA H100 80GB HBM3 GPU 2: NVIDIA H100 80GB HBM3 GPU 3: NVIDIA H100 80GB HBM3 GPU 4: NVIDIA H100 80GB HBM3 GPU 5: NVIDIA H100 80GB HBM3 GPU 6: NVIDIA H100 80GB HBM3 GPU 7: NVIDIA H100 80GB HBM3

Nvidia driver version: 550.90.07 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: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 192 On-line CPU(s) list: 0-191 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8468 CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 Stepping: 8 CPU max MHz: 3800.0000 CPU min MHz: 800.0000 BogoMIPS: 4200.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 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 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 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 avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr avx512_fp16 flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 4.5 MiB (96 instances) L1i cache: 3 MiB (96 instances) L2 cache: 192 MiB (96 instances) L3 cache: 210 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-47,96-143 NUMA node1 CPU(s): 48-95,144-191 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 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] flashinfer==0.0.9+cu121torch2.3 [pip3] numpy==1.26.4 [pip3] nvidia-nccl-cu12==2.20.5 [pip3] torch==2.3.1 [pip3] torchvision==0.18.1 [pip3] transformers==4.42.4 [pip3] triton==2.3.1 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.5.2 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 GPU1 GPU2 GPU3 GPU4 GPU5 GPU6 GPU7 NIC0 NIC1 NIC2 NIC3 NIC4 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X NV18 NV18 NV18 NV18 NV18 NV18 NV18 PIX NODE SYS SYS NODE 0-47,96-143 0 N/A GPU1 NV18 X NV18 NV18 NV18 NV18 NV18 NV18 PXB NODE SYS SYS NODE 0-47,96-143 0 N/A GPU2 NV18 NV18 X NV18 NV18 NV18 NV18 NV18 NODE PXB SYS SYS NODE 0-47,96-143 0 N/A GPU3 NV18 NV18 NV18 X NV18 NV18 NV18 NV18 NODE PIX SYS SYS NODE 0-47,96-143 0 N/A GPU4 NV18 NV18 NV18 NV18 X NV18 NV18 NV18 SYS SYS PXB NODE SYS 48-95,144-191 1 N/A GPU5 NV18 NV18 NV18 NV18 NV18 X NV18 NV18 SYS SYS PIX NODE SYS 48-95,144-191 1 N/A GPU6 NV18 NV18 NV18 NV18 NV18 NV18 X NV18 SYS SYS NODE PXB SYS 48-95,144-191 1 N/A GPU7 NV18 NV18 NV18 NV18 NV18 NV18 NV18 X SYS SYS NODE PIX SYS 48-95,144-191 1 N/A NIC0 PIX PXB NODE NODE SYS SYS SYS SYS X NODE SYS SYS NODE NIC1 NODE NODE PXB PIX SYS SYS SYS SYS NODE X SYS SYS NODE NIC2 SYS SYS SYS SYS PXB PIX NODE NODE SYS SYS X NODE SYS NIC3 SYS SYS SYS SYS NODE NODE PXB PIX SYS SYS NODE X SYS NIC4 NODE NODE NODE NODE SYS SYS SYS SYS NODE NODE SYS SYS 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_0 NIC1: mlx5_1 NIC2: mlx5_4 NIC3: mlx5_5 NIC4: mlx5_bond_0

How would you like to use vllm

I want to run inference of a medusa model.

start server cmd

  1. git clone https://huggingface.co/FasterDecoding/medusa-1.0-zephyr-7b-beta
  2. extract medusa_head weight from the model and set the weight to medusa-1.0-zephyr-7b-beta/head
  3. python3 -m vllm.entrypoints.openai.api_server --port 8010 \
    --model medusa-1.0-zephyr-7b-beta --dtype auto -tp 1 \
    --max-model-len 4096 --max-num-seqs 512 --gpu-memory-utilization 0.8 \
    --speculative-model medusa-1.0-zephyr-7b-beta/head \
    --speculative-draft-tensor-parallel-size 1 \
    --num-speculative-tokens 3 --speculative-disable-by-batch-size 4 \
    --use-v2-block-manager \
    --spec-decoding-acceptance-method typical_acceptance_sampler

    issue: poor performance (only about 1/2 of baseline) when use medusa speculative sampling.

INFO 07-24 04:00:41 metrics.py:295] Avg prompt throughput: 277.1 tokens/s, Avg generation throughput: 115.8 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.4%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:41 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 60288, Number of emitted tokens tokens: 3768.

vllm log

INFO 07-24 03:57:14 api_server.py:212] vLLM API server version 0.5.2
INFO 07-24 03:57:14 api_server.py:213] args: Namespace(host=None, port=8005, uvicorn_log_level='info', allow_credentials=False, allowed_origins=['*'], allowed_methods=['*'], allowed_headers=['*'], api_key=None, lora_modules=None, prompt_adapters=None, chat_template=None, response_role='assistant', ssl_keyfile=None, ssl_certfile=None, ssl_ca_certs=None, ssl_cert_reqs=0, root_path=None, middleware=[], model='/home/xxxx/models/medusa-1.0-zephyr-7b-beta', tokenizer=None, skip_tokenizer_init=False, revision=None, code_revision=None, tokenizer_revision=None, tokenizer_mode='auto', trust_remote_code=False, download_dir=None, load_format='auto', dtype='auto', kv_cache_dtype='auto', quantization_param_path=None, max_model_len=4096, guided_decoding_backend='outlines', distributed_executor_backend=None, worker_use_ray=False, pipeline_parallel_size=1, tensor_parallel_size=1, max_parallel_loading_workers=None, ray_workers_use_nsight=False, block_size=16, enable_prefix_caching=False, disable_sliding_window=False, use_v2_block_manager=True, num_lookahead_slots=0, seed=0, swap_space=4, gpu_memory_utilization=0.8, num_gpu_blocks_override=None, max_num_batched_tokens=None, max_num_seqs=128, max_logprobs=20, disable_log_stats=False, quantization=None, rope_scaling=None, rope_theta=None, enforce_eager=False, max_context_len_to_capture=None, max_seq_len_to_capture=8192, disable_custom_all_reduce=False, tokenizer_pool_size=0, tokenizer_pool_type='ray', tokenizer_pool_extra_config=None, enable_lora=False, max_loras=1, max_lora_rank=16, lora_extra_vocab_size=256, lora_dtype='auto', long_lora_scaling_factors=None, max_cpu_loras=None, fully_sharded_loras=False, enable_prompt_adapter=False, max_prompt_adapters=1, max_prompt_adapter_token=0, device='auto', scheduler_delay_factor=0.0, enable_chunked_prefill=False, speculative_model='/home/xxxx/models/medusa-1.0-zephyr-7b-beta/medusa', num_speculative_tokens=16, speculative_draft_tensor_parallel_size=1, speculative_max_model_len=None, speculative_disable_by_batch_size=4, ngram_prompt_lookup_max=None, ngram_prompt_lookup_min=None, spec_decoding_acceptance_method='typical_acceptance_sampler', typical_acceptance_sampler_posterior_threshold=0.01, typical_acceptance_sampler_posterior_alpha=0.1, model_loader_extra_config=None, preemption_mode=None, served_model_name=None, qlora_adapter_name_or_path=None, otlp_traces_endpoint=None, engine_use_ray=False, disable_log_requests=True, max_log_len=None)
INFO 07-24 03:57:14 config.py:1374] Downcasting torch.float32 to torch.float16.
INFO 07-24 03:57:14 llm_engine.py:174] Initializing an LLM engine (v0.5.2) with config: model='/home/xxxx/models/medusa-1.0-zephyr-7b-beta', speculative_config=SpeculativeConfig(draft_model='/home/xxxx/models/medusa-1.0-zephyr-7b-beta/medusa', num_spec_tokens=16), tokenizer='/home/xxxx/models/medusa-1.0-zephyr-7b-beta', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, rope_scaling=None, rope_theta=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.float16, max_seq_len=4096, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), observability_config=ObservabilityConfig(otlp_traces_endpoint=None), seed=0, served_model_name=/home/xxxx/models/medusa-1.0-zephyr-7b-beta, use_v2_block_manager=True, enable_prefix_caching=False)
INFO 07-24 03:57:17 selector.py:169] Cannot use FlashAttention-2 backend due to sliding window.
INFO 07-24 03:57:17 selector.py:53] Using XFormers backend.
INFO 07-24 03:57:18 spec_decode_worker.py:141] Configuring SpecDecodeWorker with proposer=<class 'vllm.spec_decode.medusa_worker.MedusaWorker'>
INFO 07-24 03:57:18 spec_decode_worker.py:155] Configuring SpecDecodeWorker with sampler=<class 'vllm.model_executor.layers.typical_acceptance_sampler.TypicalAcceptanceSampler'>
INFO 07-24 03:57:19 selector.py:169] Cannot use FlashAttention-2 backend due to sliding window.
INFO 07-24 03:57:19 selector.py:53] Using XFormers backend.
INFO 07-24 03:57:31 model_runner.py:266] Loading model weights took 13.4966 GB
INFO 07-24 03:57:33 model_runner.py:266] Loading model weights took 4.4062 GB
INFO 07-24 03:57:34 gpu_executor.py:86] # GPU blocks: 22839, # CPU blocks: 2048
INFO 07-24 03:57:37 model_runner.py:1007] Capturing the model for CUDA graphs. This may lead to unexpected consequences if the model is not static. To run the model in eager mode, set 'enforce_eager=True' or use '--enforce-eager' in the CLI.
INFO 07-24 03:57:37 model_runner.py:1011] CUDA graphs can take additional 1~3 GiB memory per GPU. If you are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. You can also reduce the `max_num_seqs` as needed to decrease memory usage.
INFO 07-24 03:57:44 model_runner.py:1208] Graph capturing finished in 7 secs.
INFO 07-24 03:57:45 serving_chat.py:94] Using default chat template:^M
INFO 07-24 03:57:45 serving_chat.py:94] {% for message in messages %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% if message['role'] == 'user' %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {{ '<|user|>^M
INFO 07-24 03:57:45 serving_chat.py:94] ' + message['content'] + eos_token }}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% elif message['role'] == 'system' %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {{ '<|system|>^M
INFO 07-24 03:57:45 serving_chat.py:94] ' + message['content'] + eos_token }}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% elif message['role'] == 'assistant' %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {{ '<|assistant|>^M
INFO 07-24 03:57:45 serving_chat.py:94] '  + message['content'] + eos_token }}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% endif %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% if loop.last and add_generation_prompt %}^M
INFO 07-24 03:57:45 serving_chat.py:94] {{ '<|assistant|>' }}^M
INFO 07-24 03:57:45 serving_chat.py:94] {% endif %}^M
WARNING 07-24 03:57:45 serving_embedding.py:141] embedding_mode is False. Embedding API will not work.
INFO 07-24 03:57:45 api_server.py:257] Available routes are:
INFO 07-24 03:57:45 api_server.py:262] Route: /openapi.json, Methods: HEAD, GET
INFO 07-24 03:57:45 api_server.py:262] Route: /docs, Methods: HEAD, GET
INFO 07-24 03:57:45 api_server.py:262] Route: /docs/oauth2-redirect, Methods: HEAD, GET
INFO 07-24 03:57:45 api_server.py:262] Route: /redoc, Methods: HEAD, GET
INFO 07-24 03:57:45 api_server.py:262] Route: /health, Methods: GET
INFO 07-24 03:57:45 api_server.py:262] Route: /tokenize, Methods: POST
INFO 07-24 03:57:45 api_server.py:262] Route: /detokenize, Methods: POST
INFO 07-24 03:57:45 api_server.py:262] Route: /v1/models, Methods: GET
INFO 07-24 03:57:45 api_server.py:262] Route: /version, Methods: GET
INFO 07-24 03:57:45 api_server.py:262] Route: /v1/chat/completions, Methods: POST
INFO 07-24 03:57:45 api_server.py:262] Route: /v1/completions, Methods: POST
INFO 07-24 03:57:45 api_server.py:262] Route: /v1/embeddings, Methods: POST
INFO:     Started server process [37495]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8005 (Press CTRL+C to quit)
INFO 07-24 04:00:16 metrics.py:295] Avg prompt throughput: 4.0 tokens/s, Avg generation throughput: 135.3 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.1%, CPU KV cache usage: 0.0%.
INFO:     ::1:57296 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:57298 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50174 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50190 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50198 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50214 - "POST /v1/completions HTTP/1.1" 200 OK
INFO 07-24 04:00:21 metrics.py:295] Avg prompt throughput: 6.0 tokens/s, Avg generation throughput: 137.5 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.0%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:21 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 21664, Number of emitted tokens tokens: 1354.
INFO:     ::1:50216 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50230 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50236 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50242 - "POST /v1/completions HTTP/1.1" 200 OK
INFO 07-24 04:00:26 metrics.py:295] Avg prompt throughput: 4.0 tokens/s, Avg generation throughput: 131.9 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.1%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:26 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 32160, Number of emitted tokens tokens: 2010.
INFO:     ::1:50258 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50266 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50328 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50332 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50338 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50342 - "POST /v1/completions HTTP/1.1" 200 OK
INFO 07-24 04:00:31 metrics.py:295] Avg prompt throughput: 558.7 tokens/s, Avg generation throughput: 127.4 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.8%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:31 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 42272, Number of emitted tokens tokens: 2642.
INFO:     ::1:50352 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50356 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:50368 - "POST /v1/completions HTTP/1.1" 200 OK
INFO 07-24 04:00:36 metrics.py:295] Avg prompt throughput: 278.5 tokens/s, Avg generation throughput: 110.4 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.3%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:36 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 51056, Number of emitted tokens tokens: 3191.
INFO:     ::1:50382 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:40776 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:40792 - "POST /v1/completions HTTP/1.1" 200 OK
INFO 07-24 04:00:41 metrics.py:295] Avg prompt throughput: 277.1 tokens/s, Avg generation throughput: 115.8 tokens/s, Running: 2 reqs, Swapped: 0 reqs, Pending: 0 reqs, GPU KV cache usage: 0.4%, CPU KV cache usage: 0.0%.
INFO 07-24 04:00:41 metrics.py:316] Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.059, Number of speculative tokens: 16, Number of accepted tokens: 0, Number of draft tokens tokens: 60288, Number of emitted tokens tokens: 3768.
INFO:     ::1:40804 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:40816 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:40826 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:40836 - "POST /v1/completions HTTP/1.1" 200 OK
INFO:     ::1:57242 - "GET /v1/models HTTP/1.1" 200 OK
abhigoyal1997 commented 4 months ago

Is this same as #6777?

xhjcxxl commented 2 months ago

i use medusa in vllm, also has this result:Speculative metrics: Draft acceptance rate: 0.000, System efficiency: 0.250, Number of speculative tokens: 3, Number of accepted tokens: 0, Number of draft tokens: 96, Number of emitted tokens: 32. Do you fix it?