Skip to content

Fix server launch for jupyter notebook - #186

Merged
merrymercy merged 1 commit into
mainfrom
fix-notebook
Feb 12, 2024
Merged

merrymercy merged 1 commit into
mainfrom
fix-notebook

Conversation

@merrymercy

@merrymercy merrymercy commented Feb 12, 2024 •

Copy link
Copy Markdown
Collaborator

Close #185

@merrymercy merrymercy changed the title Fix server launch for notebooks Fix server launch for jupyter notebook Feb 12, 2024
@merrymercy
merrymercy merged commit 06008bc into main Feb 12, 2024
@merrymercy
merrymercy deleted the fix-notebook branch February 12, 2024 12:43
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
NorthmanPKU pushed a commit to NorthmanPKU/sglang that referenced this pull request May 16, 2025
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 7, 2026
… + real-dump tests + HTTP pid coercion fix

Audit of sgl-project#181 found the code correct (both dump paths byte-
identical) but the tests fake + 3 real contract issues.

1. **Fake tests** (highest priority): verify B0/B1/B2 tested a
   hand-copied REPLICA of the overlay loop, not the production
   dump methods.  A divergence in the real code would ship green.
   Fix: factored the overlay into one shared method
   `_aginfer_overlay_program_states(per_program)` that BOTH
   `_dump_aginfer_state_dict` and `_dump_aginfer_state_bytes` call
   — divergence is now impossible by construction.  Verify calls
   the real helper directly + a source-inspection stage pins that
   both paths invoke it.

2. **Unbounded growth**: `_aginfer_program_states` was never
   pruned — every program ever PUT accumulated forever and
   polluted every dump's per_program_usage.  Fix: lazy GC in the
   shared helper — an ENDED program with NO live units is dropped
   from storage during the dump and not echoed.  ENDED programs
   that still have residual units ARE echoed (daemon needs the
   terminal state while cleanup completes).

3. **HTTP pid coercion bypass**: the route did `str(body["pid"])`,
   silently turning JSON null/number into "None"/"123" — these
   reach the setter as non-empty strings, bypassing the empty-pid
   guard.  Fix: extracted `_validate_program_paused_body` (pure
   function, no FastAPI deps) that type-checks pid/state are
   non-empty strings + pre_pause is string-or-null BEFORE coercion.

verify/t21/: 10 → 13 stages, all green.
  B0 REAL overlay helper echoes state (production code, not replica)
  B1 both dump paths call shared helper (source pin)
  B3 ENDED + no units → GC'd, not echoed
  B4 ENDED + residual units → kept + echoed
  D0 HTTP body validation: 10 reject cases + 2 accept (coercion fix)

Doc: README + PLAN note the `applied` integer should be treated
as a BOOLEAN by the daemon (>0 = changed, 0 = no-op); under DP>1
the exact integer conflates idempotency with rank count.

Regression sanity: T22 / T24 / T164 green; module imports clean
+ both dump paths confirmed to call the shared helper.
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 7, 2026
…e units

Closes the sgl-project#187-audit N3 leak: ProgramTracker.end() wrote
_states[pid]=ENDED and nothing ever removed it, so _states grew one
entry per session forever.  sgl-project#187 made tracker.state(sid) hot-path
(read per holder per unit in build_paper_state), so this matters for
steady-state memory.

Fix: ProgramTracker.gc_ended(live_pids) reclaims ENDED programs absent
from the latest /aginfer/state snapshot (no residual KV, no bookkeeping
left), dropping them from _states / _events / _ended_while_gated /
_gated_count.  kv_scheduler.handle computes live_pids = union of every
unit's holders in the fresh dump and calls it each event — mirroring
sglang's ENDED-no-units dump-GC (sgl-project#186).  So _states is bounded by
(live programs) + (ENDED programs with residual units), not by total
sessions ever seen.

Guards: only ENDED is GC'd (REASONING/ACTING/PAUSED are live, kept
even with zero units); an ENDED pid with a request still PARKED in the
gate (_gated_count > 0) is kept; pid reuse is safe (the next
observe_arrival resurrects to REASONING regardless of GC).  A LIVE
program that never signals SESSION_END is still kept — an idle/LRU cap
for that is future work (noted in the docstring).

verify: program_tracker [9] (gc_ended unit contract — reclaim/keep/
gated/reuse) + t187 G0 (real handle() → build_paper_state → gc_ended).
Regression: T6 / value_rule (20) / t187 (13) / t40 / t30 green.
rucnyz added a commit to rucnyz/sglang that referenced this pull request Jun 7, 2026
Closes the sgl-project#187-audit G3 gap: there was no end-to-end test of the
live SESSION_END seam — webhook POST /aginfer/event {session_end} →
the daemon's composed handler (sgl-project#185 F5 end + sgl-project#187 kv_scheduler.handle
migrate D_t + PUT {ENDED}) → sglang's per_program_usage[pid].state.
The per-action migrate WIRE was e2e-covered (T20/T33) and the
SESSION_END DECISION was daemon-pure (t187), but the full live chain
was untested.

New flavor G (shared stack): tag exclusive units with a pid (direct
chats, unique prompts) → fire the SESSION_END webhook at the daemon →
assert per_program_usage[pid].state becomes ENDED within ~10s (the F5
PUT round-trip) OR the units fully drop + the entry GC's (sgl-project#186).
Demote is OBSERVED + logged, not hard-gated — cold-start h_max≈0 can
make V_u(keep) ≥ 0 so the policy may decline.

Run result (2026-06-03): units_before=6 ppu_before=REASONING →
ENDED=True | migrate demoted 6→5 HBM units — under the real HiCache
cost model the policy actually fired, so BOTH the F5 PUT and the sgl-project#187
migrate half landed end-to-end.  All 7 flavors green.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 26, 2026
…load-bearing append

Task sgl-project#186 re-examined the H4 RED. The RED and every reading of the
instrumentation stand; the attribution does not.

The 275^2 mask was not a text-only prefill. prepare_attn_masks is not called on
every prefill -- gemma4_mm.py:657-665 already guards on contains_image_inputs()
-- and the 275-token prefill was sglang's own VLM boot warmup, which posts a
32x32 base64 PNG. Measured on CPU with the real gemma-4-31B processor and chat
template: 275 tokens, 256 of them image soft tokens; the same text without the
image is 17. The mask was genuinely bidirectional.

And the per-request append at :406 is the invariant, not a stray: the mask is
one flat buffer addressed by mask_indptr and USE_CUSTOM_MASK is a whole-launch
constexpr, so dropping a request's slot makes the kernel read the next
request's bytes with this request's row stride, and read out of bounds when the
skipped request is last. Route (b) is therefore correct only at batch
granularity.

Real blocker for sgl-project#96: the DCP Triton extend lane cannot serve an image request
at all, and the boot warmup sends one. Annotated in place with a pointer to
TASK_186_GEMMA4_MASK.md on fix/gemma4-textonly-mask, which also carries the
owner.py cross-check clearing sgl-project#96's q-head basis against sgl-project#180.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 26, 2026
…the Stage-B lane

Rebasing feat/swa-dcp-triton onto integration/r3-probe (which now carries the
merged sgl-project#180) exposed one stale expectation, in the tests only.

sgl-project#96's guard test listed `speculative=True` among the refusals that the Stage-B
lane flag must not open. That was true when sgl-project#96 was written: any speculative
decoding was refused on the uneven lane. sgl-project#180 serves the CHAIN verify
(topk == 1), so the pair swa_hybrid_dcp + speculative now passes the guard.
The assertion was stale, not the code -- the refusal that must survive is the
TREE one, so the loop now asserts that instead, naming the actionable flag.

What is NOT established is that window x chain-verify is correct. sgl-project#180 drops
custom_mask/mask_indptr under dcp_size > 1 on the target-verify branch,
justified for the DCP paged path. Under sgl-project#96 a sliding-window layer no longer
takes the DCP path at all -- it falls through to the plain 2-stage kernel and
DOES receive a mask, with window_kv_offsets re-basing the column arithmetic.
Whether the drop is still right there is unverified in either direction. Added
test_window_lane_times_chain_verify_is_permitted_but_unvalidated, which pins
only what the guard currently decides and says in its docstring that it is not
evidence of correctness, plus the GPU experiment that would settle it.

Conflict resolution was otherwise mechanical, as the sgl-project#186 owner.py cross-check
predicted: four files, all additive. layers/dcp/__init__.py (import list +
__all__) and layers/dcp/owner.py (__all__) were union merges of two disjoint
symbol sets; triton_backend.py was one import-list hunk; the guard test's large
hunk was two independent test methods, both kept. No semantic conflict on
_plan_aware_dcp_group_q_head_counts -- sgl-project#180 touched no head-count code, and
sgl-project#96's full-attention basis is a precondition for the geometry the merge opens.

Tests: test/registered/unit/distributed/ + dcp/test_dcp_layout_unit.py ->
414 passed, 5 failed. The same 5 fail identically on the untouched base tree
(test_uneven_tp_nccl_env MPS pipe dir, test_vmm_utils KeyError: 'LOCAL_RANK') --
environment, not code. Error sets diff clean; sgl-project#96 adds 26 tests and 113
subtests over the baseline's 388.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 26, 2026
…es green, sgl-project#143 no-ship, nothing merged

GPU validation window on the main rig; no merge performed, integration/r3-probe
otherwise unchanged.

GREEN and ready to merge:
- sgl-project#194 solo-barrier: deadlock diagnosed by py-spy (head in the draft prefill
  runner's constructor barrier, worker already serving), falsified as
  lane-specific, then confirmed fixed WITH the prefill graph on.
- sgl-project#127 weightless-fp8-kv: closes the dense-model lane corruption (garbage output
  with spec off); the KV cell size doubles and output becomes coherent. Promote.
- sgl-project#96 x sgl-project#186 H4/H5/H6/H7: Stage B boots via the text warmup, SWA pool identical
  across ranks, rows/ratio 513.0 exactly, C vs B token-identical, and the needle
  beyond the sliding window is retrieved byte-identically to a TP=1 oracle.

NOT merged:
- sgl-project#143 chain-spec: R0/R1/R2/R6 green and the symmetric verify capture is
  hardware-confirmed, but R4 Gate 4 is unmeasured -- no vehicle on this rig runs
  the lane and admits solo spec at once. Every blocker is pre-existing.

Method fix: needle_probe.py posts raw completion prompts to an instruction-tuned
model and fails identically on a single GPU, so it cannot falsify a DCP bug;
chat_needle.py replaces it. Gemma-4 rejects flashinfer, so the recipe's H5 arm A
is not runnable -- a TP=1 triton oracle replaces it.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
…probe

Semantic pre-check: zero file overlap with the tip and with feat/swa-dcp-triton,
its designated merge partner (this branch is http_server / tokenizer_manager /
gemma4_mm / multimodal lane_support; sgl-project#96 is the DCP pool and triton backend).
Merged as a PAIR with feat/swa-dcp-triton -- sgl-project#186 alone leaves H4 failing.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
Merged as the second half of the sgl-project#186 pair (either one alone leaves H4 red).

Semantic pre-check on the doubly-touched file
model_runner_kv_cache_mixin.py (sgl-project#188 merge 2 vs sgl-project#96 here): hunk regions are
disjoint -- sgl-project#188 sits at lines 214-540 (measured-budget correction and its
provenance note), sgl-project#96 at 1737+ (SWA-hybrid DCP lane predicate and pool
construction). The coupling is sequential, not conflicting: sgl-project#188 adjusts
max_total_num_tokens, sgl-project#96 consumes that same value to size the sharded full
sub-pool. Both read it through the same attribute, so the composition is
order-correct, and sgl-project#188's path is opt-in (SGLANG_MEASURED_KV_BUDGET, default
off) so the default lane is untouched by it.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 27, 2026
…3-probe

Docs-only, merged last as planned. Three CONTENT conflicts in
FEATURES_VS_UPSTREAM.md, all because the docs branch was written before sgl-project#96,
sgl-project#127 and sgl-project#117/sgl-project#198 landed. Resolved by taking the branch's editorial rules and
re-applying them to the facts as they now stand, rather than by picking a side:

1. Row 12 (Weightless-KV lane). Took the branch's evidence tier ("Cross-checked"
   instead of "Implemented") and its determinism-harness sentence, and KEPT the
   per-ROLE KV precision paragraph that sgl-project#127 added this window -- content the
   docs branch never saw.

2. Row 21 (HTCCL, ucx transport). The branch's rule from 8f1fdcf is that
   detail sections compare against upstream sglang only, with foreign engines
   confined to the overview matrix. Applied that rule to the NEW ucx section
   that sgl-project#117/sgl-project#198 brought in: the whole Nordstern-L1 body is kept, and only its
   trailing seven-line vLLM/llama.cpp/ik_llama.cpp/UCC paragraph is replaced by
   the branch's sglang-only one-liner.

3. Guarded/descoped section, SWA-DCP Stage B. The docs branch states "neither
   branch is merged, so Stage B stays out of the main matrix". That became FALSE
   earlier in this same stack -- sgl-project#96 and sgl-project#186 are merged. Rewritten to say so,
   keeping the branch's tier vocabulary and its Window-3 H-series evidence
   (H4 boot, H5 needle byte-identical to a TP=1 solo-5090 oracle, H6/H7 green)
   and keeping HEAD's _plan_aware_dcp_group_q_head_counts paragraph.
   The +6-10% figure stays labelled an ex-ante design estimate: no throughput
   number has been taken for Stage B.

OPEN DOC ITEM, deliberately not fixed here: that Stage B bullet still physically
sits under the "Built and evaluated, then gated off" heading. The bullet now
opens by contradicting its own section, which is honest but ugly; moving it into
a numbered detail row plus an overview-matrix row is a doc restructure, not a
merge resolution, and is left for a docs pass.
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.

Starting the runtime from a Jupyter Notebook broken in v0.1.12

1 participant