Skip to content

Support Triton fp8 e5m2 kv cache - #1286

Merged
zhyncs merged 4 commits into
sgl-project:mainfrom
ispobock:triton_fp8_kv
Sep 1, 2024
Merged

zhyncs merged 4 commits into
sgl-project:mainfrom
ispobock:triton_fp8_kv

Conversation

@ispobock

@ispobock ispobock commented Sep 1, 2024 •

Copy link
Copy Markdown
Collaborator

Motivation

Previously fp8 kv cache for Flashinfer was supported in #1204.
This PR support this feature for Triton runtime.

Evaluation

DeepSeek-Coder-V2-Lite-Instruct

backend kv cache dtype gsm8k flexible-extract gsm8k strict-match
Flashinfer bf16 0.7703 0.7627
Flashinfer fp8_e5m2 0.7635 0.7491
Triton fp16 0.7839 0.7695
Triton fp8_e5m2 0.7627 0.7498

Meta-Llama-3.1-8B-Instruct

backend kv cache dtype gsm8k flexible-extract gsm8k strict-match
Flashinfer bf16 0.7771 0.7127
Flashinfer fp8_e5m2 0.7650 0.7043
Triton fp16 0.7817 0.7202
Triton fp8_e5m2 0.7710 0.7498
python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct --port 30000 --trust-remote-code --host 0.0.0.0 --tp=1 --enable-mla --kv-cache-dtype fp8_e5m2

lm_eval --model local-completions --tasks gsm8k --model_args model=deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct,base_url=http://0.0.0.0:30000/v1/completions,num_concurrent=128,max_retries=3,tokenized_requests=False

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

@zhyncs zhyncs added the enhancement New feature or request label Sep 1, 2024
@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor

Nice work!

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor

ref #1156

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor

hold on, we should also verify on H100

@zhyncs
zhyncs merged commit 6cb32ef into sgl-project:main Sep 1, 2024
@yzh119

yzh119 commented Sep 2, 2024

Copy link
Copy Markdown
Collaborator

Note: the current fp8 prefill kernels in flashinfer is a mixed-precision kernel (upcast fp8 K/V to fp16 inside kernels and use fp16 tensor cores), which is slow because of the online dequantization overhead, and it's different from the triton kernel logic here (where you downcast fp16 query to fp8 and use fp8 tensor cores).

The native fp8 prefill attention kernel in flashinfer will land together with fa3, where we use fp8 tensor cores, but the accuracy landscape might change (and might align with your triton implementation).

@zhyncs

zhyncs commented Sep 2, 2024

Copy link
Copy Markdown
Contributor

Note: the current fp8 prefill kernels in flashinfer is a mixed-precision kernel (upcast fp8 K/V to fp16 inside kernels and use fp16 tensor cores), which is slow because of the online dequantization overhead, and it's different from the triton kernel logic here (where you downcast fp16 query to fp8 and use fp8 tensor cores).

The native fp8 prefill attention kernel in flashinfer will land together with fa3, where we use fp8 tensor cores, but the accuracy landscape might change (and might align with your triton implementation).

Looking forward to it very much!

timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 9, 2026
… read from

A HARD LOWER BOUND on the priced world pool of whatever the objective ships.
It CONSTRAINS the one objective knob rather than becoming a second one: the
objective still ranks, over the cuts that clear the floor, and "fastest above
F" is the same ranking on a smaller set. Default None = no floor = today's
behaviour, and the byte-identity of that path is asserted twice -- once field
by field against a call that does not pass the argument at all, and once
against the pre-#1286b selection rule restated independently in the test.

WHY NOW. sgl-project#1286 repriced every candidate against the boot's own sizing formula
and the makespan winner came out at 304,946 tokens against the incumbent's
715,089. The speed arm ships 43 % of the capacity, and until now the only way
to put a bound under that was to pin a layer cut by hand -- the act the solver
exists to replace.

NO SILENT FALLBACK. When nothing clears the floor the answer is a W40 refusal
carrying the frontier: the fastest cuts that DO clear it, or -- when none do --
the best pool anywhere in the field with the shortfall named. A floor that
degrades to the fastest cut below it is worse than no floor, because every
line of the boot still reports the floor as honoured.

ONE WRITER, THREE CALLERS. _refuse_below_pool_floor is EXTENDED (floor_flag +
field), not duplicated: the two floors differ only in which flag the operator
must move. refuse_below_floors applies both, for the solver's pinned paths,
its solved path, and the launcher's check on the candidate that actually
ships -- that last one because --pp-solve-objective incumbent names a
CANDIDATE, not a ranking, and so never passes through the narrowed set.

PROVENANCE. PP-CUT SHIPPED gains pool_floor=<F|none> and renames pool_tokens=
to chosen_pool= (no parser reads that key; the table rows and PP-POOL-JOIN
keep pool_tokens=). New PP-CUT FRONTIER line prints the Pareto non-dominated
(makespan, pool) pairs over the whole servable field with its own denominator,
each point marked CLEARS/BELOW against the floor, so the cost of a floor is a
subtraction between two rows of one line and a value for the flag can be
chosen from any boot log. Truncation bounds RESOLUTION, never range: both ends
are always printed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…emessene Transiente (fnFL2 sgl-project#114)

fnFL2x121/x122 (24.09.): die 5090-Stufe bootete mit Residenz 0.45 bzw. 0.40
bei Chunk 16384, passierte jeden Riegel (W120/W122, das KV-Sizing der Runtime)
und starb im ERSTEN Chunk-Forward mit CUDA-OOM (320 bzw. 384 MiB fehlend).
Beide Buecher preisten den 1024-MiB-Aktivierungsposten der Referenzboots
(Chunk 4096) auf einem 16384er Chunk; das eigene [vram-peak]-Instrument des
Boots misst dort 3,58 GiB, linear im Chunk auf jeder Stufe:

    PP0 (5090)  8192 -> 1,79 GiB   16384 -> 3,58 GiB   (x113/x116, x118)
    PP1 (3080)  8192 -> 1,59 GiB   16384 -> 3,19 GiB
    PP2 (3080)  8192 -> 1,21 GiB   16384 -> 2,43 GiB

x118 (0.26) ueberlebte nur, weil 7,5 GiB ungebuchte Luft hinter dem KV-Pool
blieben; x122 (0.40) hatte 2,4 GiB und starb.

Zwei Naehte, eine Messung:

* Pool-Modell (Dry-Run, Cut-Solver mit Pool-Boden Kappe+Chunk):
  activation_reserve_mib = max(1024, gemessene Transiente der bindenden
  Stufe fuer den Chunk, mit dem P bootet). --pp-cut-activation-reserve-mib
  pinnt weiterhin; unter Chunk <= 4096 bleibt die Rechnung byte-identisch
  zu sgl-project#1286. Eigene Provenienzzeile "PP-CUT activation post (sgl-project#114)".
* Rang-Env der Gruppe P: SGLANG_KV_BUDGET_PREFILL_TRANSIENT_MIB (der
  vorhandene Restposten des Sizers, Task sgl-project#48 C, bislang von niemandem
  gesetzt) traegt den gemessenen Vektor je Stufe; der Sizer zieht ihn vor
  dem KV-Pool ab. Operator-Wert gewinnt, andere Gruppen erben ihn nicht.
  In der Bestform x118 halten alle drei Stufen nach der Buchung weiter
  Kappe+Chunk (PP0 6,2 GiB Rest gegen 2,3 GiB KV, PP1 5,1/1,1, PP2 3,8/0,9).

Tests: test_weg2_p_prefill_transient_114.py (Messpunkte, Linearitaet,
Referenz-Floor, Pin, Env-Vektor und Rueckleser der Runtime, Gruppen-
Trennung). Gate der Hebel gruen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants