Skip to content

add new feature for llava-next-video - #417

Closed
ZhangYuanhan-AI wants to merge 19 commits into
sgl-project:mainfrom
ZhangYuanhan-AI:llava_video
Closed

ZhangYuanhan-AI wants to merge 19 commits into
sgl-project:mainfrom
ZhangYuanhan-AI:llava_video

Conversation

@ZhangYuanhan-AI

Copy link
Copy Markdown
Contributor

Comment thread python/sglang/utils.py
from io import BytesIO
from json import dumps

import cv2

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opencv-python should be added in pyproject.toml.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many user-defined paths and some parameters in argparse are not being used.

Comment thread README.md Outdated
@@ -1,411 +1,74 @@
To refine and clean up the README you've provided for the SGLang project, I'll focus on improving clarity, organization, and conciseness. This includes providing clear installation instructions, simplifying steps where possible, and ensuring the document is easy to navigate. Here's a revised version:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the change to README.md

Comment thread python/pyproject.toml Outdated
[project.optional-dependencies]
srt = ["aiohttp", "fastapi", "psutil", "rpyc", "torch", "uvloop", "uvicorn",
"zmq", "vllm>=0.3.3", "interegular", "pydantic", "pillow", "outlines>=0.0.27"]
"zmq", "vllm==0.3.3", "interegular", "pydantic", "pillow", "outlines>=0.0.27"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recently, we moved to vllm==0.4.2, can you update accordingly?
There are only minor changes. You can change similar to the changes in this PR #380

Comment thread examples/demo/model_call.py Outdated
@@ -0,0 +1,198 @@
# from flask import Flask, request, jsonify

@merrymercy merrymercy May 12, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename examples/demo to examples/usage/llava_video

compile_and_cleanup_final_results(cur_chunk, num_batches, save_dir)


import argparse

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the beginning of the file.

parser.add_argument('--chunk-idx', type=int, default=0, help='The index of the chunk to process.')
parser.add_argument('--num-chunks', type=int, default=8, help='The number of chunks to process.')
parser.add_argument('--save-dir', type=str, default="./work_dirs/llava_video", help='The directory to save the processed video files.')
parser.add_argument('--video-dir', type=str, default="/mnt/bn/vl-research/workspace/yhzhang/data/sora/", help='The directory to save the processed video files.')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there are many personal paths. Can someone else easily run this script?
Maybe you can move all things under a single folder examples/llava_video and add a README.md with an example command that runs on your Q98Z4OTh8RwmDonc.mp4

Comment thread python/sglang/utils.py Outdated
return video_base64


# def encode_video_base64(video_path):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused code.

)
from vllm.logger import _default_handler as vllm_default_handler

from typing import Any, Dict, List, Optional, Tuple, Union

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge this with L7

@ZhangYuanhan-AI
ZhangYuanhan-AI deleted the llava_video branch May 12, 2024 05:57
EdwardXuy pushed a commit to shun8686/sglang that referenced this pull request Apr 23, 2026
Adapt to the latest GSM8K public method
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…device actually has

Boot 11 failed on both architectures of this rig for two different reasons,
and neither was a missing capability -- both were a dispatch that named one
architecture where it meant "has this kernel".

TP0 (5090, sm120) entered the sparse-prefill branch and hit
"Sparse Attention Forward Kernel is only supported on SM90a and SM100f".
Upstream already fixed exactly this in the merged PR sgl-project#30272 by adding
"and not _is_sm120" to the predicate; our base predates it (git log -S on
that file is empty, so this is an old base, not a fork regression). Adopted
rather than rebuilt, but phrased as flash_mla_sparse_fwd_supported(device) --
the kernel states its own domain in its error text, so the gate says
major in (9, 10) and covers Ampere with the same line. The dense branch it
falls to is handed the SAME swa_page_indices / swa_topk_lengths the indexer
produced: the kernel changes, the attention support does not. Two independent
confirmations that this is lossless rather than an approximation: upstream
sgl-project#32464 calls the SM120 dense route intended production behaviour, and our own
test kit compares both branches against one _pure_torch_dsv4_combined_reference.

TP1/TP2 (3080, sm86) died in dsv4/dequant_k_cache.py on "type fp8e4nv not
supported in this architecture". The V4 KV layout is fp8-e4m3 BY ARCHITECTURE
(448 fp8 nope + 64 bf16 rope + 7 ue8m0 scale bytes in a uint8 pool);
--kv-cache-dtype cannot move it, the pool asserts store_dtype == uint8.
Triton's NVIDIA backend admits fp8e4nv only from capability 8.9.

The briefing named one file. The bug has four call sites, and fixing only the
named one would have MOVED the failure rather than removed it -- the two KV
*writers* run before any attention:
  * dequant_k_cache.py (read)     -> manual decode
  * flash_mla_sm120_triton.py     -> manual decode; this is the one that
    actually becomes load-bearing on sm86 once the sparse branch is left
  * index_buf_accessor.py (write) -> turned out to be a pure byte copy with no
    arithmetic between load and store, so both ends are viewed as uint8
    unconditionally: byte-identical everywhere, no gate needed
  * quant_k_cache.py (write)      -> a real encode. Rather than hand-roll
    round-to-nearest-even in Triton, the fallback stages the already-clamped
    float32 and lets torch do the cast, which sgl-project#262 proved bit-exact on sm86.
    f32 not bf16 staging: bf16 has 8 mantissa bits and would double-round.

Third finding, from sgl-project#33194's report and confirmed here: the compile failure
is triggered by the kernel ARGUMENT, not the load -- an fp8-typed tensor fails
at the def line even if the pointer is never dereferenced. An in-kernel branch
alone cannot fix it, so the host passes the uint8 view and a tl.constexpr
selects the decode. nope_cache_view returns view and flag together, following
sgl-project#192's pairing invariant: a caller cannot take one without the other.

Also removed the module-level SGLANG_SM120_FLASHMLA_BACKEND read in
flash_mla_sm120.py -- the exact sgl-project#343 anti-pattern, and its default resolves to
a flashinfer kernel gated to cc 120/121, so on a mixed group every rank got
whichever card imported first. Resolution is per device now; an explicitly set
value still applies everywhere (a statement about the launch, not a probe),
and is downgraded loudly, not silently, where the kernel cannot exist.

TESTS (desk, CUDA_VISIBLE_DEVICES=99, no GPU touched)
  test_dsv4_fp8_triton_compat_417.py  12 tests / 262 subtests green. Runs the
    production @triton.jit decode under TRITON_INTERPRET=1 against a pure
    Python IEEE-754 reference that never touches a torch fp8 dtype (sgl-project#262's
    rule: a torch reference would share torch's own Ampere bug and pass
    vacuously), with an e5m2 cross-probe so a comparison of nothing fails.
    All 256 codes, signed zero at 0x80, both NaN codes, plus the whole paged
    kernel vs the torch ref.
    CAN-FAIL: bits & 7 -> bits & 6 gives 128 failed / 10 passed.
  test_dsv4_arch_dispatch_417.py      16 tests / 28 subtests green, incl. the
    two cards of this rig disagreeing inside one process.
    CAN-FAIL: _FLASH_MLA_CUDA_MAJORS -> (8, 9, 10) gives 7 failed / 15 passed.
  Regression: unit/layers/attention + unit/utils, 44 failed / 362 passed on
    this branch vs 44 failed / 334 passed at a56f33aafd (throwaway detached
    worktree). Failing set diff EMPTY; all 44 pre-existing "No CUDA GPUs are
    available". The +28 are these tests.
  ruff 1 finding on the touched files, the identical 1 at the base (F841,
    pre-existing). codespell, black, isort clean. mypy clean on both new
    modules.

NOT proved at the desk, by construction: that these kernels COMPILE on a real
sm86 card. The Triton interpreter never invokes the NVIDIA backend, which is
where fp8e4nv is rejected. Gates for the card window are written down in
docs/dev/PLAN_417_dsv4_arch_paths.md along with the full per-architecture
coverage matrix, the upstream survey, and the open risks -- chief among them
that the indexer (dsv4/indexer.py:667, DeepGEMM metadata) is NOT addressed
here and may well be where boot 12 stops, and that sgl-project#33194's chain ends at FP4
routed experts, a wall we expect to miss because we serve GGUF.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…roduction takes

The compact runner pins SGLANG_OPT_FLASHMLA_SPARSE_PREFILL and then asserts
sparse_prefill_cache was populated. With the sparse-prefill gate in place that
assertion is now false on every device without flash_mla_sparse_fwd -- SM120
and Ampere both -- and it fires BEFORE the output is compared against the
pure-torch reference, so a real regression would be hidden behind a known
false failure. Upstream PR sgl-project#32464 makes the same fix for SM120 alone; this
uses the same predicate as production, so it covers Ampere too.

The env override deliberately stays on: production ignores the request on
these architectures, and if the production gate were removed this test would
go red again rather than quietly following it. The C4 seeding dispatches on
the resolved path for the same reason it dispatched on the flag before -- the
two must not disagree about which branch is being exercised.

Desk: black, isort, codespell, ruff clean on the file (ruff was already clean
at the base). unit/layers/attention 44 failed / 362 passed, unchanged failing
set. The kit itself needs a GPU and is a card-window item.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
Risk sgl-project#1 of the Cut 1/2 report predicted boot 12 stops at the DSpark indexer,
and a card window is not spent on a wall we have already named. Closed here.

The paged-MQA-logits step of the DSpark layers (40-42, compress_ratio 4/128)
defaults to deep_gemm.fp8_paged_mqa_logits: Hopper and datacenter Blackwell
only. Not an Ampere-only problem -- DeepGEMM declined SM12x (deepgemm PR
sgl-project#318), so after Cut 2 gets TP0 through attention the 5090 would have hit this
exactly like the 3080s. All three ranks of this rig need it.

Upstream first: PR sgl-project#31480 solves the same thing for the sibling dsa/ package,
and its structure is what is adopted -- explicit backend selections stay
authoritative, the capability-driven choice goes underneath them, and the
DeepGEMM schedule metadata is skipped for any backend that does not consume
it. The parts that PR had to BUILD (a torch implementation, a metadata
bypass) already exist here from sgl-project#24692, so our delta is the dispatch half
only. This cut writes no kernel; saying otherwise would overstate it.

New dsv4/indexer_arch.py: deepgemm_indexer_supported (per_device_gate,
major in (9, 10)), resolve_paged_mqa_logits_backend, the companion
deepgemm_indexer_metadata_needed, and the named warning. The kernel choice
and the schedule choice must never disagree -- a rank with a schedule and no
DeepGEMM, or a kernel and no schedule, is a crash either way -- so that
invariant is pinned over the whole env x capability matrix rather than left
to two functions happening to agree.

The fn selection is lifted out of _forward_paged_indexer into module-level
select_paged_mqa_logits_fn(). It is the whole of this cut and the kind of
decision that goes quietly wrong on a heterogeneous group; inline in a
600-line method it was untestable. Also: _can_use_nonpaged_indexer now
refuses a card without DeepGEMM (that branch calls fp8_mqa_logits directly
and has no torch twin; the paged path is its fallback).

APPROXIMATION, NAMED, NOT SILENT: this substitution is not bit-identical.
DeepGEMM computes the logits as an FP8 tensor-core GEMM; the torch path
dequantises to float32 and accumulates with bmm. Same quantity, different
arithmetic. The logits feed a top-k, so a near-tie between two KV positions
can be broken differently and output can differ from a Hopper run of the same
checkpoint. Warned once per device, naming the capability and the mechanism.
It stays quiet when the user asked for the torch path explicitly -- then it
is not a surprise.

Two findings from writing the test, both worth the branch on their own:

  * The FP4 indexer has no fallback at all (68-byte vs 132-byte index cache
    layout), so it now REFUSES by name instead of being routed at the FP8
    torch path, which would have read the cache wrongly and returned
    plausible numbers. Our GGUF checkpoint is unaffected.
  * The two torch implementations are not interchangeable, and the difference
    is not architectural. The paged call site passes seq_lens with a trailing
    dim of 1; only the _sm120 variant squeezes it, the other asserts
    shape == (batch_size,). So the old is_sm120_supported() split at
    indexer.py:667 would have sent every non-SM120 card at an implementation
    that ASSERTS -- including anyone setting SGLANG_FP8_PAGED_MQA_LOGITS_TORCH
    on a Hopper box today. The dispatch now always takes the trimmed variant,
    which is additionally the one that walks ceil(max_seq_len/64) pages
    instead of the full capture-time page-table width.

TESTS (desk, CUDA_VISIBLE_DEVICES=99, no GPU touched)
  test_dsv4_indexer_arch_417.py  21 tests / 68 subtests green, incl.
    PagedIndexerMetadata constructed on a mocked Ampere card without ever
    importing DeepGEMM, and the Hopper branch still being taken (observable
    because DeepGEMM raises in this CPU environment).
    CAN-FAIL, three ways: _DEEPGEMM_MAJORS -> (8,9,10) gives 22 failed /
    17 passed; returning fp8_paged_mqa_logits_torch from the dispatch gives
    8 failed / 21 passed; making the FP4 branch fall back silently instead of
    refusing gives 1 failed / 20 passed.
  Regression: unit/layers + unit/utils, 47 failed / 731 passed on this branch
    vs 47 failed / 682 passed at a56f33aafd. Failing set diff EMPTY.
    This comparison earned its keep: it caught the first version of the
    non-paged DeepGEMM check reaching into a metadata field that
    test_dsv4_nonpaged_indexer's stub does not provide. Asking the CURRENT
    device instead is both what that test expects and the more correct
    question after set_device.
  ruff findings identical to base on the touched files (E712 x3 pre-existing
    in indexer.py), new files clean. codespell, black, isort, mypy clean.

Plan file updated: Cut 3 section, matrix rows 9/9b/9c/10, the GPU-window
request restated for Cuts 1-3 in path (all three cards, ~90 min,
SGLANG_OPT_USE_TOPK_V2=0 on any sm86 boot, plus a new gate 6 that sizes the
top-k divergence between ranks rather than asserting the warning is
harmless), and a 5-line ticket note for the ue8m0 subnormal divergence so it
is not lost -- registered separately, deliberately untouched here.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
Window 2 closed a feasibility box: at the MEASURED routed top-k of 6 the
20 GiB cards need SGLANG_MOE_SCRATCH_SLOTS=6, and scratch=6 plus weights plus
KV plus warmup transients does not fit in 19.58 GiB. Lowering the fraction to
make room pushes the pinned pool into host FILE and trips the 98 GiB guard
(f=0.40 peaked 103.6 of 104 GiB). Six boots bracket it; none failed on
anything sgl-project#417 touches.

The lever that does not exist: SGLANG_MOE_RESIDENT_EXPERT_FRACTION is
EnvFloat(1.0), ONE SCALAR FOR EVERY RANK. Measured at f=0.45, the 5090 sat at
28569 of 32607 MiB -- ~4.0 GiB idle -- while both 3080s were 32 then 152 MiB
short. Spare VRAM on the rig, on the wrong card, inexpressible.

CORRECTION TO THE FRAMING, because it changes the arithmetic: this does NOT
shift experts to the 5090. The fraction is the GPU-resident/host-pinned split
WITHIN a rank's own shard; moving experts between ranks is --rank-moe-ratio, a
different axis. The vector helps through two independent mechanisms -- lower
on the 3080s frees the VRAM that binds, raise on the 5090 spends its idle VRAM
and SHRINKS the host pinned pool, paying mechanism 1's host cost back. A
scalar can do neither without doing the other harm everywhere.

Surface:
  * EnvFloatVector: "0.45" parses to a float exactly as EnvFloat did, so the
    default and every existing launch are byte-identical; "0.485,0.42,0.42"
    parses to a tuple. get() REFUSES a tuple by name -- the value has a dozen
    readers and an untaught one must fail loudly, never size a buffer from the
    wrong element.
  * layers/moe/resident_fraction.py: resident_fraction_for_rank() for every
    SIZING/ACCOUNTING site, offload_active() for ACTIVATION, describe() for
    the boot log.
  * --rank-moe-resident-fraction, validated EAGERLY at CLI-parse time like its
    siblings, at the top of _handle_uneven_tp before that method's early
    return (the fraction is meaningful with or without an uneven-TP plan).
  * Env and flag must AGREE or hard-error -- deliberately unlike the
    --rank-*-ratio family where env silently wins: these set the same thing.

Three things a consumer-map audit turned up that the first cut had wrong:
  * The rank identity is moe_tp_rank, not tp_rank -- the fraction splits an
    EXPERT shard. Same number under pure TP, separate groups in general; where
    they differ the vector is ambiguous (length per TP rank, indexed by MoE
    rank) and is REFUSED by name rather than guessed. Scalar stays legal.
  * offload_active() must stay group-wide. _expert_offload_lane_active gates
    an all_reduce(MIN) and a barrier; a rank answering "my own f is 1.0" would
    skip a collective its peers enter and hang the group. any(f < 1.0) is
    computed from the same launch string on every rank, so it cannot disagree.
  * planner/placement.py::_compute_offload did float(env) and turned the
    ValueError a comma-list raises into frac=None -- which drops the whole
    offload section from the capacity report. An unbooked pool in the one
    place whose job is to book it (sgl-project#400 class). Now per-rank, and a length
    matching neither 1 nor tp raises instead of reporting nothing.

TESTS (desk, CUDA_VISIBLE_DEVICES=99)
  test_resident_fraction_per_rank.py 21 tests / 8 subtests green: scalar path
    pinned byte-identical (plain float type, broadcast, and plan equality
    against passing the float directly), vector produces DIFFERENT resident
    counts per rank through the real planner, group-wide offload_active,
    length/range/moe-group/env-vs-flag refusals, eager CLI validation.
  CAN-FAIL, four ways: rank ignored -> 2 failed; scalar getter stops refusing
    a vector -> 1 failed; broadcast dropped -> 2 failed; CLI length check
    removed -> 1 failed.
  Regression unit/layers + unit/utils + unit/server_args + unit/model_loader:
    53 failed / 1465 passed on this branch vs 53 failed / 1444 passed at
    6e3b850afb. Failing set diff EMPTY.
  ruff 360 on the touched files vs 361 at base (the 5 now-unused `envs`
    imports my edits orphaned are gone, plus one pre-existing F401 in a file
    I was already in). codespell, black, isort clean; mypy clean on the new
    module.

NOT DONE, and why: the rammon guard needed no fix. The brief called it "a
hardcoded 98"; it is not. rammon.sh already derives guard = cgroup limit -
margin, and its own first log line says so: "limit=104.0 GiB margin=6 GiB
guard=98.0 GiB". 98 was 104-6. A 4 GiB margin would guard at 100 and would
NOT have saved boot 417e, which peaked at 103.6 -- it would trade a clean
guard stop for a kernel OOM kill two GiB later, which can take unrelated
processes with it. One real latent hazard found while checking and left as a
ticket: resolve_limit_bytes() falls back to MemTotal when memory.max reads
"max", which lxcfs makes honest here but the script's own comment flags as
wrong on a bare host.

Fixposten for the next window is in the plan file with the arithmetic shown:
vector 0.485,0.42,0.42 leaves ~0.90 GiB corridor on the 3080s (floor 0.40),
costs the 5090 1.47 of its ~4.0 GiB spare, and holds the host pinned pool at
the f=0.45 footprint that boot 417b already proved fits.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…ache peak managed

Two probes and one answered question, all from sgl-project#417 window 3. Both probes are
default-off and inert unless asked for; they sit on the forward path and the
load path.

1. FORWARD PEAK, MEASURED INSTEAD OF INFERRED
Window 3 died on a prefill transient: a 3080 rank had 639 MiB free at ready
and still failed a 136 MiB allocation on a ~1-2k prompt. Nobody ever measured
that transient -- it was inferred from the one allocation that happened to
fail, which is a lower bound on the SHORTFALL and says nothing about the peak.
Every fixposten since has budgeted it by taste, mine included.

model_executor/forward_peak.py brackets each forward with
reset_peak_memory_stats / max_memory_allocated, bucketed by phase and token
count. Driven from _forward_raw, the same place the sgl-project#343 layer tap lives and
for the same reason (the model is entered as model.forward(...), so a module
hook never fires). peak_scope() closes the bracket on the exception path too:
an OOM is exactly when the peak matters.

It writes a FILE per rank, not a log line, and the channel was chosen on
evidence. /server_info already aggregates a per-rank memory_usage dict and is
the natural home for a live number -- but this number exists to characterise a
peak that PRECEDES an OOM death, and /server_info needs a live server. The
per-rank JSON files survive it: that is how window 3's expert_stats arrived
from a boot whose rank had already died. Worker logger.warning does not reach
the log at all on this rig, which rules out the third channel.

2. THE LOAD-TIME PAGE-CACHE RACE, MANAGED INSTEAD OF LUCKY
Chosen of the three options: trim coupled to CONSUMER PROGRESS
(ProgressCoupledTrim, called from ConsumedPageDropper._flush_shard after each
advice batch). The failure is a RATE mismatch, not a wrong threshold:
cachetrim.sh samples on a 5 s wall clock and window 3 moved memory.current
88.2 -> 102.5 GiB inside one 15 s window, so whether a boot lived came down to
where a noisy peak fell between two samples -- w3a survived the recipe w3b
died on. Coupling the trim to the stream makes a faster load trim more often
with no interval to tune.
  * "loader waits on a watermark" is this plus a stall: more invasive, and it
    can deadlock when the watermark is unreachable because the pinned pool,
    which reclaim cannot touch, is already above it.
  * "tighter load-phase threshold" only moves a number a 5 s sampler can still
    overshoot. It does not address the rate.
cachetrim.sh stays (it also trims what the loader does not cause) and the
rammon guard is untouched, as instructed. Safety is cachetrim's own argument
and is CHECKED not assumed: swapless means reclaim cannot evict anon, so the
pinned pool, CUDA host allocations and the Python heap are out of reach and
only page cache can go. With swap it refuses; without memory.reclaim it
disables itself. A probe must never be why a load fails.

3. PER-RANK CHUNKED-PREFILL-SIZE IS NOT POSSIBLE -- NAMED LIMIT, NOT A GAP
Asked whether the 3080s could get a smaller chunk than the 5090. Hard no.
chunked_prefill_size IS the batch-shape knob: it sets how many tokens each
rank contributes to prefill's own collectives, every rank parses the same
scalar, and the only division (dp_size) is applied identically everywhere.
Making it per-rank reproduces precisely the class this fork already built
machinery against -- kv_session_offload.py:2559: "A divergent decision makes
rank 0 take the prefill branch while ranks 1/2 take the decode branch ... those
branches carry DIFFERENT collectives, so the ranks desync (NCCL/gloo hang)",
with scheduler.py:3643 documenting the admission budget as deliberately
RANK-UNIFORM. --rank-moe-resident-fraction is safe as a vector precisely
because it only moves bytes within a rank's own weight/host split and never
changes a batch shape; chunk size is the opposite knob. Recorded as an
exclusion with its reason. Consequence: the 3080 prefill transient can only be
cut by lowering the GLOBAL chunk size, at a cost paid by all three ranks.

Also answered, for the window-4 plan: --disable-cuda-graph is NOT a
conservative choice and is nothing to do with DSV4 or GGUF. MoE expert offload
forces it, fail-fast at layer construction, because the residency plan is
data-dependent (topk_ids.tolist(), a device->host sync inside every forward)
and cannot be captured. SGLANG_MOE_OFFLOAD_CUDA_GRAPH=1 opens a capturable
DECODE-only path, but it freezes the resident set -- a different
configuration, not a toggle, so its number would not be comparable to an eager
one from the same boot. Recommended as its own later arm with its own floor
rather than forced into window 4.

TESTS (desk, CUDA_VISIBLE_DEVICES=99)
  test_forward_peak_and_stream_trim.py 12 tests green: both probes inert by
    default, peak recorded per phase/bucket, bracket closes on the exception
    path, file written per rank, trim quiet below the watermark and reclaiming
    exactly current-target above it, swap refusal, self-disable when
    memory.reclaim is missing. Can-fail included (a tracker that never reset
    would report a running max).
  48 passed across the two new suites together.
  Regression unit/layers + unit/model_executor + unit/model_loader:
    19 failed / 1113 passed at 5d1e8a18c6, failing set diff EMPTY on this
    branch.
  ruff clean on the new files, codespell/black/isort clean, mypy clean on
  forward_peak.

Window-4 plan is in docs/dev/PLAN_MOE_RESIDENT_FRACTION_PER_RANK.md: one boot,
w3a's vector unchanged, both probes armed, and a STAGED prefill (256/512/1024/
2048) so the transient is bracketed between two measured numbers even if the
top step still OOMs -- which is the difference between this window and the
last one.
WhiteCmile added a commit to WhiteCmile/sglang that referenced this pull request Dec 1, 2026
… methods (issue sgl-project#417)

sgl-project#416 plan PR-1: remove benchmark/bench_dt_{feature,cuda_ipc,candidate}_p2p.py
and benchmark/dt_sm_comm/ (zero references from ci/, analysis/, .github/,
dt-runtime), the self-referenced speculative/dt_completion_source.py, and
fork-added methods nothing calls: CandidateArena.has_active,
CudaIpcPrimitives.stream_synchronize/stream_wait_value32 (+ the
_stream_wait_value32 loader and CU_STREAM_WAIT_VALUE_* constants),
_RingMapping.entry_bytes, RingGpuPublisher.stage_request,
DraftRingWorker.consumed_seq (+ _consumed_words and the
dt_ring_worker_consumed_seq_address binding), FeaturePull/KV transports'
invalidate_peer (+ _invalidate_peer_if_healthy), dt_rdma._wait_one.
Delete-only; no behaviour change on the default path.
WhiteCmile added a commit to WhiteCmile/sglang that referenced this pull request Dec 1, 2026
…h (issue sgl-project#436, sgl-project#416 PR-6)

DT_FEATURE_PULL_INLINE=1 (the default) made DraftFeaturePullTransport.submit()
enqueue the copy on the calling scheduler thread and poll it by event query;
=0 dispatched the same pull to the ThreadPoolExecutor instead. Nothing in
sglang, dt-runtime, ci/ or the current analysis/ scripts ever sets it to 0,
so the executor branch of submit() is dead code.

Deletes the env read, the always-true guard around the inline stream setup,
submit()'s executor fallback, and DraftFeaturePullTransport._run_pull, which
only that fallback called. The `import os` read was the file's last use of
os, so the import goes with it.

Kept deliberately:
- submit_remote_batch()/_remote_worker_loop()/_submit_remote(): the cross-host
  pull worker, called unconditionally from dt_draft_engine.py:6634 — the live
  cross-host path, not a switch alternative.
- submit_batch() and its executor dispatch: this switch never gated it (it
  has always had a single path), so removing it would be an unrelated
  refactor outside sgl-project#416 PR-6. Note for the foreman: after issue sgl-project#417 deleted
  benchmark/bench_dt_feature_p2p.py, submit_batch() has no production caller
  left — only test/registered/cpu/test_dt_feature_peer_queues.py — so it is a
  candidate for a separate zero-caller-method slimming PR, not for this one.
- _run_batch(), _run_admitted(), _executor: still reached from submit_batch(),
  the quiescence probes and close().
- the admission accounting: _submit_inline() does its own
  _admitted_pulls +/- around the enqueue, so the fence/quiescence contract
  that close() waits on is unchanged on the default path.

No behaviour change on the default path: the switch was on, so submit()
already returned _submit_inline() and none of the deleted code ran.
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.

4 participants