Skip to content

[Feature] Allow specifying all ports to use in advance - #116

Merged
merrymercy merged 4 commits into
sgl-project:mainfrom
Ja1Zhou:fix-port
Jan 30, 2024
Merged

merrymercy merged 4 commits into
sgl-project:mainfrom
Ja1Zhou:fix-port

Conversation

@Ja1Zhou

@Ja1Zhou Ja1Zhou commented Jan 30, 2024

Copy link
Copy Markdown
Contributor

No description provided.

@Ja1Zhou
Ja1Zhou marked this pull request as ready for review January 30, 2024 01:01

@merrymercy merrymercy left a comment •

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.

LGTM! I only have a few minor notes about the style.

Comment thread python/sglang/srt/utils.py Resolved
Comment thread python/sglang/srt/utils.py Resolved
Comment thread python/sglang/srt/utils.py Resolved
Ja1Zhou and others added 3 commits January 30, 2024 08:19
@Ja1Zhou

Ja1Zhou commented Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

Looks good to me!

@merrymercy
merrymercy merged commit 4a634cf into sgl-project:main Jan 30, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
pi314ever pushed a commit to pi314ever/sglang that referenced this pull request Aug 25, 2025
- Fix block_groups oob values - keep pad values instead of
batch_size to avoid exceeding number of classes. This was
causing accuracy issue in block sonft max adjustment.

Signed-off-by: Rahul Vijayaraghavan <[email protected]>
sammysun0711 referenced this pull request in apinge/sglang Dec 30, 2025
* Swtich aiter ci branch to rocm/aiter dev/perf branch

* change package name from aiter to amd-aiter

* Increase timeout for Qwen3-VL

* Minor fix

* try aot prebuild aiter kernel before launch server

* Fix path

* Add layernorm2d aot prebuild

* Update qwen3-omni test

* Fix path

* Adjust timeout to 90 minute
blzheng pushed a commit to blzheng/sglang that referenced this pull request May 11, 2026
Add MHC and apply_rotary_emb_interleaved_cpu kernels on CPU
efschu pushed a commit to efschu/htsglang that referenced this pull request Jul 18, 2026
test_uneven_rejects_kv_replication asserted QKVParallelLinear raises
"replication is not supported" when num_kv_heads < tp_size. That
rejection was removed when REPLICATED-KV geometry landed (sgl-project#62): kv < tp
is now a supported mode (every rank holds all kv heads, q splits by the
plan). The test has therefore been failing on HEAD independently of any
other change. Replace it with test_uneven_kv_replication_supported,
which asserts the now-correct behavior: construction succeeds and yields
num_kv_heads == total kv heads with num_kv_head_replicas == tp_size on
every rank.

Pre-existing failure since sgl-project#62; not related to the sgl-project#116 change.
efschu pushed a commit to efschu/htsglang that referenced this pull request Jul 18, 2026
…head split

The --rank-tp-ratio auto planner derives a memory-proportional per-rank
weight vector. Under REPLICATED-KV geometry (num_kv_heads < tp_size) that
vector could yield a q-head split whose per-rank packets STRADDLE a global
kv-head-group boundary, e.g. A3B (q=16, kv=2) at TP=5 3+1+1 co-location:
auto weights [469,469,469,1132,1132] -> q-heads [2,2,2,6,4], rank 3
crossing the boundary at head 8. The sgl-project#105 current-chunk ragged kernel
cannot represent that (it fails fast in _replicated_kv_ragged_reindex), so
the auto planner could PRODUCE a config the guard must reject. The only
workaround (explicit kv-aligned --rank-tp-ratio) is mutually exclusive with
--rank-auto-reserve-mib, so MoE TP=5 co-location was effectively blocked.

Fix: make the Q-dimension partition kv-boundary-aware. A new `groups`
parameter (= num_kv_heads under REPLICATED-KV, else None) threads through
partition_units -> partition_sizes -> tp_partition_{sizes,size,offset} ->
tp_loaded_shard_start. When engaged it constrains the split so no rank's q
packets cross a kv-group boundary (repairing the example to [4,2,2,4,4]),
assigning contiguous rank segments to whole kv-groups (balanced weight sums
per group to preserve proportionality). It is a NO-OP whenever the raw
split is already aligned OR when kv**2 does not divide q (non-divisible
fallback), so even TP, kv>=tp, and explicit kv-aligned ratios stay
byte-identical. New single source attn_q_partition_groups() feeds the qkv
q block, the o_proj input, and the flashinfer/triton backends; QKV
cross-checks the caller-supplied value so a future mis-wiring fails loudly.

This is a general robustness win: EVERY kv<tp auto split is now aligned, so
the sgl-project#105 guard should never fire on an auto config, not just MoE TP=5.

Notably includes the GGUF QKV weight-loader path (linear.py), which sizes
the packed q rows separately from output_partition_sizes — it must thread
`groups` too, or the materialized qkv width (raw) disagrees with the
aligned forward split (split_with_sizes sum mismatch at graph capture).

Tests (CPU, no GPU):
- test_uneven_tp_kv_aligned.py: byte-identity for groups=None over 4000
  random cases; kv>=tp and non-divisible fall back to raw; no-straddle
  invariant over 6000 kv<tp cases; the A3B repair.
- TestReplicatedKvAlignedQKV: constructs the REAL qkv/o_proj under a
  straddling plan; asserts the aligned split, exact weight roundtrip, o_proj
  input width == qkv q width, the GGUF-loader q-shard sizing matches the
  aligned init, and the guardrail raises on mismatched q_shard_groups.

Validated (full-perf boots, NCCL 2.30.7, MPS, GGUF Q4_K_XL):
- A3B TP=5 3+1+1 co-location (the blocked config): boots, aligned split
  [4,2,2,4,4] on all layers, guard does not fire, all graphs captured,
  temp-0 coherent (17*23=391, Jupiter), needle-in-haystack HIT.
- Regression A3B TP=3: split [8,4,4] raw==aligned (no repair, byte-
  identical), outputs match the TP=5 co-location (oracle agreement).
- Regression dense 27B TP=5 co-location (kv=4<5): split [4,4,4,8,4],
  units 6 % groups 4 != 0 -> non-divisible fallback, raw==aligned
  (byte-identical), boots + coherent.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
test_uneven_rejects_kv_replication asserted QKVParallelLinear raises
"replication is not supported" when num_kv_heads < tp_size. That
rejection was removed when REPLICATED-KV geometry landed (sgl-project#62): kv < tp
is now a supported mode (every rank holds all kv heads, q splits by the
plan). The test has therefore been failing on HEAD independently of any
other change. Replace it with test_uneven_kv_replication_supported,
which asserts the now-correct behavior: construction succeeds and yields
num_kv_heads == total kv heads with num_kv_head_replicas == tp_size on
every rank.

Pre-existing failure since sgl-project#62; not related to the sgl-project#116 change.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
…head split

The --rank-tp-ratio auto planner derives a memory-proportional per-rank
weight vector. Under REPLICATED-KV geometry (num_kv_heads < tp_size) that
vector could yield a q-head split whose per-rank packets STRADDLE a global
kv-head-group boundary, e.g. A3B (q=16, kv=2) at TP=5 3+1+1 co-location:
auto weights [469,469,469,1132,1132] -> q-heads [2,2,2,6,4], rank 3
crossing the boundary at head 8. The sgl-project#105 current-chunk ragged kernel
cannot represent that (it fails fast in _replicated_kv_ragged_reindex), so
the auto planner could PRODUCE a config the guard must reject. The only
workaround (explicit kv-aligned --rank-tp-ratio) is mutually exclusive with
--rank-auto-reserve-mib, so MoE TP=5 co-location was effectively blocked.

Fix: make the Q-dimension partition kv-boundary-aware. A new `groups`
parameter (= num_kv_heads under REPLICATED-KV, else None) threads through
partition_units -> partition_sizes -> tp_partition_{sizes,size,offset} ->
tp_loaded_shard_start. When engaged it constrains the split so no rank's q
packets cross a kv-group boundary (repairing the example to [4,2,2,4,4]),
assigning contiguous rank segments to whole kv-groups (balanced weight sums
per group to preserve proportionality). It is a NO-OP whenever the raw
split is already aligned OR when kv**2 does not divide q (non-divisible
fallback), so even TP, kv>=tp, and explicit kv-aligned ratios stay
byte-identical. New single source attn_q_partition_groups() feeds the qkv
q block, the o_proj input, and the flashinfer/triton backends; QKV
cross-checks the caller-supplied value so a future mis-wiring fails loudly.

This is a general robustness win: EVERY kv<tp auto split is now aligned, so
the sgl-project#105 guard should never fire on an auto config, not just MoE TP=5.

Notably includes the GGUF QKV weight-loader path (linear.py), which sizes
the packed q rows separately from output_partition_sizes — it must thread
`groups` too, or the materialized qkv width (raw) disagrees with the
aligned forward split (split_with_sizes sum mismatch at graph capture).

Tests (CPU, no GPU):
- test_uneven_tp_kv_aligned.py: byte-identity for groups=None over 4000
  random cases; kv>=tp and non-divisible fall back to raw; no-straddle
  invariant over 6000 kv<tp cases; the A3B repair.
- TestReplicatedKvAlignedQKV: constructs the REAL qkv/o_proj under a
  straddling plan; asserts the aligned split, exact weight roundtrip, o_proj
  input width == qkv q width, the GGUF-loader q-shard sizing matches the
  aligned init, and the guardrail raises on mismatched q_shard_groups.

Validated (full-perf boots, NCCL 2.30.7, MPS, GGUF Q4_K_XL):
- A3B TP=5 3+1+1 co-location (the blocked config): boots, aligned split
  [4,2,2,4,4] on all layers, guard does not fire, all graphs captured,
  temp-0 coherent (17*23=391, Jupiter), needle-in-haystack HIT.
- Regression A3B TP=3: split [8,4,4] raw==aligned (no repair, byte-
  identical), outputs match the TP=5 co-location (oracle agreement).
- Regression dense 27B TP=5 co-location (kv=4<5): split [4,4,4,8,4],
  units 6 % groups 4 != 0 -> non-divisible fallback, raw==aligned
  (byte-identical), boots + coherent.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 23, 2026
…ogy SVGs; add runtime-feature diagrams

TOPOLOGIES.md 2.7: TP=5 co-location was booted+validated on the 3-card rig
(--rank-gpu-id 0,0,0,1,2, 3 ranks time-slicing the 5090 via MPS, 1 rank/3080,
bit-identical across two boots); kv-boundary-aware auto planner (sgl-project#116). Replaces
the incorrect "TP=5 not booted here / TP=4 first boot" wording.

gen.py: rework diagram 07 to the booted TP=5 layout (3 co-located ranks, MPS
time-slice). Neutralize upstream-comparison wording across all paired diagrams
(stock->upstream; drop WASTED/OOM/impossible/refuses/throttles/fails) to match
the neutral prose. Update weightless diagram 06 (graph-decode landed sgl-project#133/sgl-project#136,
262k measured, not eager-only/"4x"). Align offload correctness/perf wording with
the corrected prose (self-deterministic, not bit-identical; factors not
benchmarked).

Add four runtime-feature diagrams + Part 3 sections:
- 17 adaptive drafter routing (NEXTN/DFLASH dual residence, policy vs bandit,
  ctx-gate) (§5)
- 18 session KV spill (newest-first host offload, keeps decoding; S1 measured
  vs modeled curves) (§20)
- 19 fast-lane priority scheduling (reserved-heavy floor, aging, spill interplay)
  (§16)
- 20 measured VRAM budget (component registry, KV as measured remainder,
  corridor rule) (§10)

All 20 SVGs regenerated and validated as well-formed XML.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 23, 2026
…; scope fork contribution to co-location + uneven adapt

The wording implied "we can do TP=5" as if TP=5 were the fork's invention.
Reframe with the same attribution care as the GGUF note:

- TP=5 is a STANDARD sglang capability (any TP degree; a normal TP=5 uses five
  physical cards, one rank each). Not the fork's feature.
- Fork contribution = MULTI-RANK CO-LOCATION: running more TP-ranks than
  physical GPUs by sharing a GPU via MPS (+ NCCL >= 2.30 for the co-located
  communicator). This let a standard TP=5 config be TESTED/emulated on just 3
  physical cards (3 ranks time-slice the 5090, 1 per 3080) — the original way
  to test it, not a 5-card perf equivalent (decode tok/s deliberately not
  5-card-representative, already stated).
- Second fork delta: the uneven-TP + kv-boundary-aware auto-split (sgl-project#116) that
  lets a co-located uneven TP=5 boot when num_kv_heads < tp (fixes the sgl-project#105
  Q-split straddle).

Honest framing: TP=5 = the standard capability, co-location = the fork's way to
emulate/test it on 3 cards. No "we can do TP=5" tone. Upstream comparison side
(standard TP=5 = 5 identical cards, one rank each) is the honest contrast and
kept unchanged. Only fork-side wording + alt text adjusted; SVG regenerated via
gen.py, validated well-formed and overflow-free, all img references resolve.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 25, 2026
…ct pinned

Commissioned: flip attn_kv_replicated's strict `<` to `<=` so kv == tp can
express a non-uniform --rank-tp-ratio on attention, together with the o_proj
unit coupling. Implemented, red/green on CPU, validated on GPU -- and the GPU
measurement refuted the flip.

Measured on Qwen3.5-2B (q=8/kv=2, TP=2, --rank-tp-ratio 11,21, flashinfer,
CUDA graphs, uneven-DCP pool):

  with `<=`: boot green, REPLICATED-KV active, q split [2, 6], KV cache
  duplicated per rank -- then the FIRST request dies:
    ValueError: REPLICATED-KV current-chunk attention (sgl-project#105): this rank's
    q heads (offset 2, 6 heads over 2 local kv slots) straddle a global
    kv-head boundary (global GQA group size 4)

  with `<` (kept): normal mode, even [4, 4] attention (geometrically forced),
  the plan applied to every other dimension, output coherent and
  TOKEN-IDENTICAL to the TP=1 reference, no crash, no KV duplication.

The refutation is geometric, not tuning: the sgl-project#116 alignment repair requires
ranks > groups, and at kv == tp groups == ranks ALWAYS, so
_partition_units_kv_aligned falls back to the raw (straddling) split
(`groups >= n` bail-out) and the only aligned split is the even one. For the
second-host qwen05b geometry (q=14/kv=2) alignment is impossible outright
(units % groups != 0). Truly uneven attention at kv == tp needs a ragged
kernel with per-rank non-uniform GQA mapping (the sgl-project#169 head-gather family),
not a threshold flip.

The predicate keeps `<` with the measured rationale in its docstring so the
flip is not re-tried; test_kv_eq_tp_stays_in_normal_mode_by_measurement pins
the behavior, the geometric reason (aligned partitioner returns the raw split
at groups == ranks), the head-true [256, 640] o_proj arithmetic for kv < tp
where the repair DOES engage, and the untouched default path.

Also: replaced importlib.reload in the earlier guard test with exact
attribute restore (reload swaps the module object under other tests), and
named a PRE-EXISTING order-dependent pollution: test_server_args.py poisons
test_uneven_tp_memory.py::test_fractions_survive_pickling when run in one
process -- present at the pushed HEAD, bisected to file level, not fixed here.

Suites: 5 failed / 677 passed -- the pre-existing baseline set.
Jiminator pushed a commit that referenced this pull request Oct 16, 2026
[Perf] FlashInfer MegaMoE: opt-in decode-only workspace (extends #116)
kevin-mii added a commit that referenced this pull request Nov 11, 2026
sgl-project/sgl-amd-mono#114 and #116 (the wide launch drops its debug checks and A/B switches,
and feeds AITER's BM16 presort from the launch; on an AITER without presorted_moe it falls back to
the old sort), and #121, which imports require_mlp_sync from dp_attention: this branch's SGLang no
longer has it in utils.common, so the old pin fails --enable-amd-monokernel at startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yuychang pushed a commit to yuychang/sglang that referenced this pull request Nov 17, 2026
sgl-project/sgl-amd-mono#114 and sgl-project#116: the wide launch drops its debug checks and A/B switches,
and feeds AITER's BM16 presort from the launch (aux16). sgl-project#116 needs AITER with presorted_moe
(d4defd456 or newer); on an older AITER it falls back to the old sort.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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