Skip to content

feat: fix fp8 for MLA and support bmm fp8 for DeepSeek V2 - #1285

Merged
zhyncs merged 2 commits into
mainfrom
change_bmm
Sep 1, 2024
Merged

zhyncs merged 2 commits into
mainfrom
change_bmm

Conversation

@zhyncs

@zhyncs zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor

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.

python3 -m sglang.launch_server --model deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct --enable-mla --trust-remote-code --disable-radix --mem-frac 0.85
python3 -m sglang.launch_server --model neuralmagic/DeepSeek-Coder-V2-Lite-Instruct-FP8 --enable-mla --trust-remote-code --quantization fp8 --disable-radix --mem-frac 0.85

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

# fp16
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.7741|±  |0.0115|
|     |       |strict-match    |     5|exact_match|↑  |0.7635|±  |0.0117|

# fp8
|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.7809|±  |0.0114|
|     |       |strict-match    |     5|exact_match|↑  |0.7672|±  |0.0116|

Modifications

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 commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

ref #1156

@zhyncs
zhyncs merged commit 54772f7 into main Sep 1, 2024
@zhyncs
zhyncs deleted the change_bmm branch September 1, 2024 07:28
@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

ref flashinfer-ai/flashinfer#469

@zhyncs zhyncs mentioned this pull request Sep 1, 2024
15 of 29 tasks
@fengyang95

fengyang95 commented Sep 1, 2024 •

Copy link
Copy Markdown

@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

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

@fengyang95 It only supports sm89+, such as 4090, H100. And I only tested on H100.

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

In order to support fp8 on A100, I think we should use the torch.bmm with cast @ispobock

@fengyang95

fengyang95 commented Sep 1, 2024 •

Copy link
Copy Markdown

@fengyang95 It only supports sm89+, such as 4090, H100. And I only tested on H100.

Is it because of the same reason as this? vllm-project/vllm#7322 @zhyncs

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

@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.

zhyncs added a commit to flashinfer-ai/flashinfer that referenced this pull request Sep 1, 2024
@fengyang95

Copy link
Copy Markdown

@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.

So, does this mean that solving the MLA issue still doesn't allow the A100 to run properly?

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

Yes we optimized it for H100.

@fengyang95

fengyang95 commented Sep 1, 2024 •

Copy link
Copy Markdown

Yes we optimized it for H100.
@zhyncs By the way, may I ask for some advice? Our main requirement now is to run DeepSeek-Coder-V2 236B using L40*8 since we only have ample resources for L40. Do you have any good technical suggestions?
Thank you very much.

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

@fengyang95

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

git clone https://github.com/sgl-project/sglang.git
cd sglang

pip install --upgrade pip
pip install -e "python[all]"

pip install flashinfer -i https://flashinfer.ai/whl/cu121/torch2.4/

# use MLA, W8A8(FP8) and FP8 E5M2 KV Cache
python3 -m sglang.launch_server --model neuralmagic/DeepSeek-Coder-V2-Instruct-FP8 --enable-mla --quantization fp8 --kv-cache-dtype fp8_e5m2 --disable-radix --tp 8 --trust-remote-code

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.

@fengyang95

fengyang95 commented Sep 1, 2024 •

Copy link
Copy Markdown

@fengyang95

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

git clone https://github.com/sgl-project/sglang.git
cd sglang

pip install --upgrade pip
pip install -e "python[all]"

pip install flashinfer -i https://flashinfer.ai/whl/cu121/torch2.4/

# use MLA, W8A8(FP8) and FP8 E5M2 KV Cache
python3 -m sglang.launch_server --model neuralmagic/DeepSeek-Coder-V2-Instruct-FP8 --enable-mla --quantization fp8 --kv-cache-dtype fp8_e5m2 --disable-radix --tp 8 --trust-remote-code

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

@zhyncs

zhyncs commented Sep 1, 2024

Copy link
Copy Markdown
Contributor Author

Could you provide some directions or suggestions for fix this?

@fengyang95 You can focus on this, but specific modifications and attempts will require you to take action yourself.

if CUDA_CAPABILITY[0] >= 9:
if Lq <= 256:
BLOCK_M, BLOCK_N = (128, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
elif CUDA_CAPABILITY[0] >= 8:
if Lq <= 128:
BLOCK_M, BLOCK_N = (128, 128)
elif Lq <= 256:
BLOCK_M, BLOCK_N = (64, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
else:
BLOCK_M, BLOCK_N = (64, 64) if Lq <= 128 else (32, 32)

@fengyang95

fengyang95 commented Sep 2, 2024 •

Copy link
Copy Markdown

Could you provide some directions or suggestions for fix this?

@fengyang95 You can focus on this, but specific modifications and attempts will require you to take action yourself.

if CUDA_CAPABILITY[0] >= 9:
if Lq <= 256:
BLOCK_M, BLOCK_N = (128, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
elif CUDA_CAPABILITY[0] >= 8:
if Lq <= 128:
BLOCK_M, BLOCK_N = (128, 128)
elif Lq <= 256:
BLOCK_M, BLOCK_N = (64, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
else:
BLOCK_M, BLOCK_N = (64, 64) if Lq <= 128 else (32, 32)

@zhyncs Thank you very much. I will try it asap.

@fengyang95

fengyang95 commented Sep 2, 2024 •

Copy link
Copy Markdown

Could you provide some directions or suggestions for fix this?

@fengyang95 You can focus on this, but specific modifications and attempts will require you to take action yourself.

if CUDA_CAPABILITY[0] >= 9:
if Lq <= 256:
BLOCK_M, BLOCK_N = (128, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
elif CUDA_CAPABILITY[0] >= 8:
if Lq <= 128:
BLOCK_M, BLOCK_N = (128, 128)
elif Lq <= 256:
BLOCK_M, BLOCK_N = (64, 64)
else:
BLOCK_M, BLOCK_N = (32, 64)
else:
BLOCK_M, BLOCK_N = (64, 64) if Lq <= 128 else (32, 32)

@zhyncs
I managed to get Triton to compile by adjusting the settings,

BLOCK_M, BLOCK_N = (32, 32)

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 ?

@xiaoqi35

xiaoqi35 commented Sep 4, 2024

Copy link
Copy Markdown

Is there a plan that sglang supports deepseek-V2 4-bit quant?
The result of my running result is the modeling of deepseek-V2 doesn't support int4 quant. My patch code for supporting awq quant infer successful without --enable-mla. There are some unknown somethings, bug, in attention-MLA I can't handle.

@zhyncs

zhyncs commented Sep 4, 2024

Copy link
Copy Markdown
Contributor Author

Can you share the HuggingFace URL of the checkpoint you used? We plan to take a look after supporting CUDA Graph and Quant MoE.

@Xu-Chen

Xu-Chen commented Sep 7, 2024 •

Copy link
Copy Markdown
Contributor

@Xu-Chen

Xu-Chen commented Sep 9, 2024 •

Copy link
Copy Markdown
Contributor

Is there a plan that sglang supports deepseek-V2 4-bit quant? The result of my running result is the modeling of deepseek-V2 doesn't support int4 quant. My patch code for supporting awq quant infer successful without --enable-mla. There are some unknown somethings, bug, in attention-MLA I can't handle.

As you mentioned in vllm-project/vllm#7494 (comment).
Can you share the code or the HuggingFace URL of the checkpoint you used?

timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
zhenhantech pushed a commit to zhenhantech/flashinfer that referenced this pull request Jan 9, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 16, 2026
…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.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 25, 2026
…, 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).
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 2, 2026
…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.
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 2, 2026
…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.
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 2, 2026
…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.
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.

5 participants