Skip to content

Eliminate 2 gpu ops during sampling when logit_bias is zero - #338

Merged
hnyls2002 merged 3 commits into
sgl-project:mainfrom
Qubitium:logits-bias-allocation
Apr 3, 2024
Merged

hnyls2002 merged 3 commits into
sgl-project:mainfrom
Qubitium:logits-bias-allocation

Conversation

@Qubitium

@Qubitium Qubitium commented Mar 28, 2024 •

Copy link
Copy Markdown
Contributor

Reason for PR: Eliminate 2 gpu ops during sampling when logit_bias is not used (all zeros)

  1. skip allocation of logit_bias
  2. skip applying logits.add_(self.logit_bias)

On our internal test of Yi-6B quantized using marlin on 4090 we see tangible improvement: up to 63% throughput improvement for small sized tokens output work loads when batch > 1.

Concurrency is 10 requests so it will cause sglang to use batch size between 1-10:

IMG_20240328_204927.png

@Qubitium Qubitium changed the title Eliminate 2 gpu ops during inference (sampling) when logit_bias is zero Eliminate 2 gpu ops during sampling when logit_bias is zero Mar 28, 2024
@hnyls2002

hnyls2002 commented Apr 3, 2024 •

Copy link
Copy Markdown
Collaborator

@Qubitium Sorry to cause trouble. I have directly pushed the commit on your branch.
closes #344

@hnyls2002
hnyls2002 merged commit c9de3e1 into sgl-project:main Apr 3, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
shiyu7 pushed a commit to shiyu7/sglang that referenced this pull request Dec 12, 2025
Estrella-xx pushed a commit to Estrella-xx/sglang that referenced this pull request Apr 13, 2026
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jul 14, 2026
…ctable-aware mamba admission gate (sgl-project#338)

Two root-cause fixes so the recurrent-bound swarm runs correctly under HiMA:

sgl-project#337 (mamba_actuator): MambaArenaActuator.unmark_token_slots routed the k2m dst-grow
through the legacy MambaPool.unmark_slots shadow state, which live_size no longer reads,
so a grown mamba pool was invisible to BudgetAgent._maybe_update_admission_cap
("grew events: 0", cap pinned at boot). Route through the allocator
(self.allocator.unmark_pages_capped -> CappedFreeList._grow_into_tail) and reconcile
pool.size from pool.live_size, byte-symmetric with KVArenaActuator. Single source of
truth = the allocator's CappedFreeList.

sgl-project#338 (memory_pool + common + scheduler): a hybrid request needs a mamba active slot in
addition to a req slot, but Scheduler.get_num_allocatable_reqs gated only on
req_to_token_pool.available_size() (req slots). After sgl-project#337 raises the cap, the scheduler
admitted a batch mamba could not back and alloc_req_slots RAISED instead of leaving the
request queued (the design defer action) -> swarm crash. Add
HybridReqToTokenPool.mamba_admittable_reqs(mamba_evictable) = (free + evictable) //
slots-per-req and gate get_num_allocatable_reqs on it, mirroring the KV
available+evictable gate in PrefillAdder. Counting evictable (what alloc_req_slots
reclaims via pre-evict) is what keeps a lightly-loaded pool from throttling on free slots
alone. per-req factor extracted to HybridReqToTokenPool.mamba_slots_per_req (single source
of truth shared with alloc_req_slots).

Validated: 2 reproducing unit tests (actuator grow -> live_size; admittable-reqs
crash-guard + no-throttle). E2E swarm A/B (real CC subagent-flattened trace, default
config, conc 400): both arms complete clean 1200/1200, 0 crash (was 2148 err); base
unaffected (1009 tps, ran at 194); sys grows mamba 977->1233, admits to 246,
TTFT -23% mean / -30% p99. (Throughput is GPU-compute-bound at real-CC 16K-context, so
the higher concurrency converts to a TTFT win, not a throughput win.)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…/capabilities API, disconnect card-hold fix 30s->0.25s (sgl-project#338)

# Conflicts:
#	docs/dev/INTEGRATION_R3_VALIDATION.md
1195343015 pushed a commit to 1195343015/sglang that referenced this pull request Dec 2, 2026
…l-project#338)

* fix(ppu): keep NoPE low-precision indexers off the FP8 shortcut

Why:
- Kimi-K3.1 NoPE FP4/INT8 indexers can enter a shortcut that requires a RoPE cache.

How:
- Restrict the merged NoPE shortcut to FP8 and retain the existing FP4/INT8 paths.

Dependency:
- None

Test:
- Unit:
  - None
- E2E:
  - Kimi-K3.1:
    - Model data type: MXFP4 MoE weights with FP8 activations (W4A8).
    - Affected platforms: T-HEAD PPU with SAIL SM89+ support; two-node TP8/CP8/EP8/PP2.
    - Test case:
      - Retain the original model precision and two-node serving configuration.
      - Environment: export SGLANG_JIT_DEEPGEMM_PRECOMPILE=0; export SGLANG_K3_FUSED_FRONT=0; export SGLANG_SAIL_DEEPGEMM_MXFP4_W4A8=1; export SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=2048; export SGLANG_PP_LAYER_PARTITION=47,46; export SGLANG_PP_LAST_STAGE_STREAM_ORDERING=1.
      - Command: sglang serve --model-path /ppusw/datasets/checkpoints/LLM/moonshotai/k3.1/Kimi-K3.1-Pro/ --trust-remote-code --tp-size 8 --attn-cp-size 8 --enable-prefill-cp --cp-strategy interleave --ep-size 8 --moe-a2a-backend megamoe --pp-size 2 --pp-async-batch-depth 1 --nnodes 2 --node-rank 0 --dist-init-addr 215.193.197.25:20000 --host 0.0.0.0 --port 30000 --max-total-tokens 101024 --max-running-requests 96 --mem-fraction-static 0.98 --disable-radix-cache --attention-backend dsa --dsa-prefill-backend flashmla_sparse --dsa-decode-backend flashmla_kv --linear-attn-backend flashkda --watchdog-timeout 3600 --served-model-name Kimi-K3.1
      - Verify service startup, Graph capture, and one inference complete without missing NoPE RoPE-cache attribute errors.

* fix(ppu): omit unsupported Kimi MegaMoE token hints on SAIL

Why:
- PPU MegaMoE entry points reject the global_num_tokens keyword passed by Kimi.

How:
- Pass the token hint only to the non-SAIL implementation.

Dependency:
- None

Test:
- Unit:
  - None
- E2E:
  - Kimi-K3.1:
    - Model data type: MXFP4 MoE weights with FP8 activations (W4A8).
    - Affected platforms: T-HEAD PPU with SAIL SM89+ support; two-node TP8/CP8/EP8/PP2.
    - Test case:
      - Retain the original model precision and two-node serving configuration.
      - Environment: export SGLANG_JIT_DEEPGEMM_PRECOMPILE=0; export SGLANG_K3_FUSED_FRONT=0; export SGLANG_SAIL_DEEPGEMM_MXFP4_W4A8=1; export SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=2048; export SGLANG_PP_LAYER_PARTITION=47,46; export SGLANG_PP_LAST_STAGE_STREAM_ORDERING=1.
      - Command: sglang serve --model-path /ppusw/datasets/checkpoints/LLM/moonshotai/k3.1/Kimi-K3.1-Pro/ --trust-remote-code --tp-size 8 --attn-cp-size 8 --enable-prefill-cp --cp-strategy interleave --ep-size 8 --moe-a2a-backend megamoe --pp-size 2 --pp-async-batch-depth 1 --nnodes 2 --node-rank 0 --dist-init-addr 215.193.197.25:20000 --host 0.0.0.0 --port 30000 --max-total-tokens 101024 --max-running-requests 96 --mem-fraction-static 0.98 --disable-radix-cache --attention-backend dsa --dsa-prefill-backend flashmla_sparse --dsa-decode-backend flashmla_kv --linear-attn-backend flashkda --watchdog-timeout 3600 --served-model-name Kimi-K3.1
      - Verify service startup, Graph capture, and one inference complete without unsupported global_num_tokens keyword errors.

* fix(ppu): align DSA FP4 cache selection across SAIL paths

Why:
- SAIL indexers and cache allocation can select different precision layouts.
- The FP4 CLI gate rejects supported SAIL devices.

How:
- Accept SAIL SM89+ and retain the legacy environment default.
- Align cache allocation and sizing with the SAIL precision resolver.
- Keep SAIL on the PPU Indexer implementation.

Dependency:
- None

Test:
- Unit:
  - None
- E2E:
  - Kimi-K3.1:
    - Model data type: MXFP4 MoE weights with FP8 activations (W4A8).
    - Affected platforms: T-HEAD PPU with SAIL SM89+ support; two-node TP8/CP8/EP8/PP2.
    - Test case:
      - Retain the original model precision and two-node serving configuration.
      - Environment: export SGLANG_JIT_DEEPGEMM_PRECOMPILE=0; export SGLANG_K3_FUSED_FRONT=0; export SGLANG_SAIL_DEEPGEMM_MXFP4_W4A8=1; export SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=2048; export SGLANG_PP_LAYER_PARTITION=47,46; export SGLANG_PP_LAST_STAGE_STREAM_ORDERING=1.
      - Command: sglang serve --model-path /ppusw/datasets/checkpoints/LLM/moonshotai/k3.1/Kimi-K3.1-Pro/ --trust-remote-code --tp-size 8 --attn-cp-size 8 --enable-prefill-cp --cp-strategy interleave --ep-size 8 --moe-a2a-backend megamoe --pp-size 2 --pp-async-batch-depth 1 --nnodes 2 --node-rank 0 --dist-init-addr 215.193.197.25:20000 --host 0.0.0.0 --port 30000 --max-total-tokens 101024 --max-running-requests 96 --mem-fraction-static 0.98 --disable-radix-cache --attention-backend dsa --dsa-prefill-backend flashmla_sparse --dsa-decode-backend flashmla_kv --linear-attn-backend flashkda --watchdog-timeout 3600 --served-model-name Kimi-K3.1
      - Verify service startup, Graph capture, and one inference complete without FP4 writer versus FP8 index-K cache stride mismatches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants