Repository navigation
feat: fix fp8 for MLA and support bmm fp8 for DeepSeek V2 - #1285
Conversation
|
ref #1156 |
|
@zhyncs May I ask if this does not support the A100? I encountered the following error when using the A100: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/tiger/deepseek_http/vllm_source/sglang/python/sglang/srt/models/deepseek_v2.py", line 576, in forward
hidden_states = self.self_attn(
^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/tiger/deepseek_http/vllm_source/sglang/python/sglang/srt/models/deepseek_v2.py", line 453, in forward
q_nope_out = bmm_fp8(
^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/flashinfer/gemm.py", line 266, in bmm_fp8
_kernels.bmm_fp8(A, B, out, A_scale, B_scale)
RuntimeError: CUDA error: CUBLAS_STATUS_NOT_SUPPORTED when calling `cublasLtMatmulAlgoGetHeuristic( lt_handle, matmul_desp.descriptor(), a_desp.descriptor(), b_desp.descriptor(), d_desp.descriptor(), d_desp.descriptor(), preference.descriptor(), 1, &heuristic_result, &returned_result)`
[rank0]:W0901 22:42:24.599000 139974644569856 torch/_inductor/compile_worker/subproc_pool.py:126] SubprocPool unclean exit
Killed |
|
@fengyang95 It only supports sm89+, such as 4090, H100. And I only tested on H100. |
|
In order to support fp8 on A100, I think we should use the |
Is it because of the same reason as this? vllm-project/vllm#7322 @zhyncs |
|
@fengyang95 Currently, the dependency of fp8 on sm89+ appears in two places: torch.bmm in MLA implementation and FusedMOE. The former can be resolved by converting fp8 to bf16 and multiplying by w_scale. While the latter requires support for the sm80 kernel in FusedMOE, but we have no plans to do so in the short term. |
fp8 scale per tensor ref sgl-project/sglang#1285
So, does this mean that solving the MLA issue still doesn't allow the A100 to run properly? |
|
Yes we optimized it for H100. |
|
|
L40 is sm89, it supports bmm fp8. But we haven't adjusted the Triton kernel block size for the shared memory of L40, so it might not work. The verification and adaptation of sm89 will be done when there is time, but it is not a high priority. Maybe you can try this If you encounter any problems, you can directly resolve them and submit a PR. We highly welcome contributions! Subsequently, we will implement CUDA Graph and Quant MOE on this basis, and the performance will continue to improve. Please stay tuned. |
@zhyncs That's great. I ran it and encountered the following error. It looks like there's indeed an issue with Triton. I am not familiar with Triton. Could you provide some directions or suggestions for fix this? File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
self.run()
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/sglang/python/sglang/srt/managers/tp_worker.py", line 896, in run_tp_server
model_server.exposed_step(recv_reqs)
File "/sglang/python/sglang/srt/managers/tp_worker.py", line 244, in exposed_step
self.forward_step()
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/managers/tp_worker.py", line 260, in forward_step
self.forward_prefill_batch(new_batch)
File "/sglang/python/sglang/srt/managers/tp_worker.py", line 507, in forward_prefill_batch
sample_output, logits_output = self.model_runner.forward(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/model_executor/model_runner.py", line 584, in forward
return self.forward_extend(batch)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/model_executor/model_runner.py", line 548, in forward_extend
return self.model.forward(
^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/models/deepseek_v2.py", line 660, in forward
hidden_states = self.model(input_ids, positions, input_metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/models/deepseek_v2.py", line 629, in forward
hidden_states, residual = layer(
^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/models/deepseek_v2.py", line 576, in forward
hidden_states = self.self_attn(
^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/models/deepseek_v2.py", line 471, in forward
attn_output = self.attn(q_input, k_input, v_input, input_metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/layers/radix_attention.py", line 201, in forward
return self.extend_forward(q, k, v, input_metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sglang/python/sglang/srt/layers/radix_attention.py", line 73, in extend_forward_triton
extend_attention_fwd(
File "/sglang/python/sglang/srt/layers/extend_attention.py", line 298, in extend_attention_fwd
_fwd_kernel[grid](
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/triton/runtime/jit.py", line 345, in <lambda>
return lambda *args, **kwargs: self.run(grid=grid, warmup=False, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/triton/runtime/jit.py", line 691, in run
kernel.run(grid_0, grid_1, grid_2, stream, kernel.function, kernel.packed_metadata, launch_metadata,
^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/triton/compiler/compiler.py", line 381, in __getattribute__
self._init_handles()
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/triton/compiler/compiler.py", line 374, in _init_handles
raise OutOfResources(self.metadata.shared, max_shared, "shared memory")
triton.runtime.errors.OutOfResources: out of resource: shared memory, Required: 106496, Hardware limit: 101376. Reducing block sizes or `num_stages` may help.
Killed |
@fengyang95 You can focus on this, but specific modifications and attempts will require you to take action yourself. sglang/python/sglang/srt/layers/extend_attention.py Lines 275 to 288 in 6487ef6 |
@zhyncs Thank you very much. I will try it asap. |
but there are issues with fused MoE, so it doesn't seem to run on L40 either. File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/vllm/model_executor/layers/quantization/fp8.py", line 499, in apply
return fused_experts(x,
^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/vllm/model_executor/layers/fused_moe/fused_moe.py", line 544, in fused_experts
moe_align_block_size(curr_topk_ids, config['BLOCK_SIZE_M'], E))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/vllm/model_executor/layers/fused_moe/fused_moe.py", line 228, in moe_align_block_size
ops.moe_align_block_size(topk_ids, num_experts, block_size, sorted_ids,
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/vllm/_custom_ops.py", line 28, in wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/vllm/_custom_ops.py", line 485, in moe_align_block_size
torch.ops._C.moe_align_block_size(topk_ids, num_experts, block_size,
File "/home/tiger/.pyenv/versions/3.11.2/lib/python3.11/site-packages/torch/_ops.py", line 1061, in __call__
return self_._op(*args, **(kwargs or {}))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: invalid argument
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.So for the L40, running with FP8 precision is fine with MLA support because it uses native Triton; however, there are issues with Fused MoE because it uses vLLM's Fused MoE ? |
|
Is there a plan that sglang supports deepseek-V2 4-bit quant? |
|
Can you share the HuggingFace URL of the checkpoint you used? We plan to take a look after supporting CUDA Graph and Quant MoE. |
As you mentioned in vllm-project/vllm#7494 (comment). |
…t#1285) Co-authored-by: ispobock <[email protected]>
fp8 scale per tensor ref sgl-project/sglang#1285
…ject#1285 retry too. xsn188 died at the first wake with W4 although P answered /resume_memory_occupation 200: the kv_cache leg went out on the shared pooled session without an epoch, a stale keep-alive connection raised ServerDisconnectedError before any response line, and plain rpc() has no retry. Both KV legs now go through leg_rpc with credit_epoch(boot_epoch, epoch) -- one retry on a fresh force_close connection, deduplicated on the far side by the epoch-scoped leg ledger. Tests: 1285, 1233, 1394/1369 green.
…, Erstschlaf-Messung im Thread, Sidecar-Appends im FIFO-Schreiber, Launcher-Prewarm ohne GC-Vollpass, Keep-alive unter dem der Gruppen -- x172-x175 hielten die Loop 18-47 ms je Flip, 132-155 ms je Erstschlaf, 83-96 ms beim Ratchet; x174 schrieb Leg 1 in eine von P geschlossene Verbindung (fnFL2 H78) Gemessen an den Front-Logs x172-x175 (Abstand zweier Zeilen derselben Coroutine ohne await dazwischen = Zeit, die die Loop nicht verlassen konnte): - WEG2-FLIP-ORDER -> ISSUED des gesammelten Sleep-Legs: 18-47 ms bei JEDEM Flip (Median 22, 42 Flips). _sleep_leg_gate parste den append-only Sidecar weg2_measured_record.json (3,26 MB, 2040 Samples) auf der Loop; Desk: read_measured_record 17-19 ms. - Erstschlaf je Gruppe (Flip 1 und 2): kv-Wake RETURNED -> FLIP-TIMELINE 132-155 ms = ps + nvidia-smi + /proc-Sample 51-63 ms und append_measured_record 79-94 ms (Desk 76-81 ms), vor state=serving. - done epoch=2: FLIP-RATCHET post -> FLIP done 83-96 ms (Append). - H75-Prewarm: der ECHTE Launcher-Import im Thread hielt einen 2-ms-Ticker 6x > 40 ms (max 201 ms) -- volle GC-Paesse (219-225 ms im Front-Heap mit 731k Objekten, GIL gehalten); mit pausiertem Collector 0 Stalls. x175s erster Request kam 3,5 s nach WEG2-FRONT up, also im Fenster. - x174: 'WEG2 leg1 rid=weg2-0-4 failed: Server disconnected' 3 ms nach FLIP done: P-Verbindung 7,66 s idle (Loop 7,5 s eingefroren) gegen P's uvicorn timeout_keep_alive 5 s; aiohttp haelt 15 s und hatte den FIN nie gelesen. (1) SidecarView: das Gate liest den Sidecar ueber einen Cache mit Schluessel (dev, ino, size, mtime_ns), vor dem Lesen genommen -- dieselbe Antwort wie read_measured_record, nie aelter als die Datei. Der Flip bereitet ihn vor dem Gate im Worker-Thread vor (_sidecar_ready), Startup waermt ihn vor. Warm: 0,2 ms (stat). Unbedingt (gleiche Antwort). Das Gate bleibt inert wie bisher (repr-Schluessel, Nutzer 24.09. "aus lassen"). (2) Mit SGLANG_WEG2_DC_OFF_PATH=1 (NF-Arm an): die Erstschlaf-Messung laeuft in einem Worker-Thread, den der Flip AWAITET -- W19 und das Dormant-Image behalten ihren Platz. Die Sidecar-Appends (Dormant-Image, Flip-Ratchet) gehen an einen FIFO-Schreiber (_sidecar_submit), nicht mehr auf den Flip; der naechste Gate-Leser und cleanup warten auf ihn. Der Ratchet-post-Wert wird wie bisher bei done epoch=2 auf der Loop genommen; seine Zeile kommt jetzt aus dem Schreiber (nach FLIP done). Schalter aus = beides wie bisher. (3) Launcher-Prewarm importiert mit pausiertem Collector und friert den Heap danach ein (gc.freeze); WEG2-FRONT GC-PAUSE benennt jeden Vollpass >= 50 ms. (4) Die kleinen Lazy-Importe des Flip-Pfads (wake_credit, wake_credit_pd, wake_kv, ple_admit_hint) beim Start im Thread. (5) rpc_connector: Keep-alive des Pools = Server-Keep-alive minus min(1 s, halb) = 4 s bei SGLANG_TIMEOUT_KEEP_ALIVE=5; eine laenger idle Verbindung wird geschlossen statt beschrieben. KEIN Retry fuer Leg 1/Leg 2: die rid wird serverseitig nicht dedupliziert (TokenizerManager ueberschreibt rid_to_state), also beweist "keine Antwortbytes" nicht, dass die Gruppe den Request nie annahm. Die Flip-Legs behalten ihren sgl-project#1285-Retry (Epoch-Ledger). Test test_weg2_front_loop_blockers_h78.py: 26 Tests, 21 rot auf e925485 (u. a. Loop 1,207 s gehalten, 3 Parses statt 1, Prewarm hielt die Loop 192 ms), gruen mit H78; Kontrolle reproduziert x174 (Default-Connector schreibt nach eingefrorener Loop in die geschlossene Verbindung).
…ounds reach the log before the sleep, not after the next wake N6i (f501e46) 27B D: 'Decode rank batch' rounds 285-331 of 18:14:46-47 landed in the log only at 18:15:28, after the next wake. DecodeRoundLog. flush() is query-only (Event.query): a round whose events are not readable yet stays pending, and the idle-tick flush that normally emits the last round of a burst did not get to them before the group slept; a sleeping group runs no rounds and no idle ticks, so they waited for the next wake. - DecodeRoundLog.drain_blocking(): retire the open round, one device sync, emit every pending round in round order; nothing pending = no sync. - release_memory_occupation calls it right after the sgl-project#1285 replay check, before the leg mutates anything (the group is quiesced: the sync costs nothing). A drain error never breaks the sleep. - Marker: 'DECODE-ROUND-LOG drained n= left= at=sleep' (only when it emitted something). SGLANG_WEG2_DECODE_LOG_DRAIN_AT_SLEEP=0 = the lazy flush as before. Gate (41 decode-round-log / release-leg files): base 14 failed (3 in the new test + 11 pre-existing), change 11 failed (the same), 661 passed.
…ounds reach the log before the sleep (pick-clean) Redo of b71f05d (reverted): the drain call sits at the head of release_memory_occupation, before the sgl-project#1285 replay lookup (log only, so a replayed leg draining is harmless), away from integ's L15-14d block after the replay check. Code otherwise unchanged. N6i (f501e46) 27B D: 'Decode rank batch' rounds 285-331 of 18:14:46-47 landed in the log only at 18:15:28, after the next wake. DecodeRoundLog. flush() is query-only: a round whose events are not readable yet stays pending; a sleeping group runs no rounds and no idle ticks. - DecodeRoundLog.drain_blocking(): retire the open round, one device sync, emit every pending round in round order; nothing pending = no sync. - release_memory_occupation calls it first (the group is quiesced: the sync costs nothing). A drain error never breaks the sleep. - Marker: 'DECODE-ROUND-LOG drained n= left= at=sleep'. SGLANG_WEG2_DECODE_LOG_DRAIN_AT_SLEEP=0 = the lazy flush as before. Gate (41 decode-round-log / release-leg files): base 14 failed (3 in the new test + 11 pre-existing), change 11 failed (the same), 661 passed; new test 3/3 after the move.
…ounds reach the log before the sleep (pick-clean) Redo of b71f05d (reverted): the drain call sits at the head of release_memory_occupation, before the sgl-project#1285 replay lookup (log only, so a replayed leg draining is harmless), away from integ's L15-14d block after the replay check. Code otherwise unchanged. N6i (f501e46) 27B D: 'Decode rank batch' rounds 285-331 of 18:14:46-47 landed in the log only at 18:15:28, after the next wake. DecodeRoundLog. flush() is query-only: a round whose events are not readable yet stays pending; a sleeping group runs no rounds and no idle ticks. - DecodeRoundLog.drain_blocking(): retire the open round, one device sync, emit every pending round in round order; nothing pending = no sync. - release_memory_occupation calls it first (the group is quiesced: the sync costs nothing). A drain error never breaks the sleep. - Marker: 'DECODE-ROUND-LOG drained n= left= at=sleep'. SGLANG_WEG2_DECODE_LOG_DRAIN_AT_SLEEP=0 = the lazy flush as before. Gate (41 decode-round-log / release-leg files): base 14 failed (3 in the new test + 11 pre-existing), change 11 failed (the same), 661 passed; new test 3/3 after the move.
Motivation
Paired programming with @ispobock , completed this feature, gsm8k fp16 and fp8 are both normal, will continue to use nvtx and nsys for performance analysis and optimization.
Modifications
Checklist