Skip to content

Dynamic model class loading - #101

Merged
merrymercy merged 2 commits into
mainfrom
cody/model
Jan 25, 2024
Merged

merrymercy merged 2 commits into
mainfrom
cody/model

Conversation

@comaniac

Copy link
Copy Markdown
Contributor

This PR attempts to make the model loading process more systematic and self-contained. Currently when addinga new model, we have to explicitly import the model entry class in model_runnter.load_model function. This introduces two drawbacks:

  1. model_runner.py cannot focus on the changes of "model runner".
  2. Developers have to change 2 files when adding a new model. The change inmodel_runner.py is easy to be missed and may result in conflicts.

sglang.srt does not follow the standard Python package structure (i.e., leveraging __init__.py to construct module hierarchy), so it's not straightforward to use a model registry with decorator. In this PR, I tried to dynamically scan all model files under models, and load their entry classes. The major drawback of this approach is that every model file has to have EntryClass alias to be scanned. IMHO it should be relatively easy for developers to follow.

Please share your thoughts.

@comaniac
comaniac requested a review from merrymercy January 25, 2024 21:25
@merrymercy
merrymercy merged commit 3a581e9 into main Jan 25, 2024
@merrymercy
merrymercy deleted the cody/model branch January 25, 2024 23:29
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
…d input/output strides for kernel graphs. (sgl-project#98)

* initial docs

* update path

* add doxygen files

* add more

* update docs

* add more files

* fix typo

* link update

* add gated mlp

* add more tutorials

* format

* add transpiler docs

* .

* .

* .

* .

* .

* update RMSNorm example

* adjust image width

* Update LoRA tutorial

* update files

* fix typo

* transpiler doc fix (sgl-project#89)

* transpiler doc fix

* fmt

* .

* checkpoint

* Add files via upload

* Update README.md

* add file

* add demo

* update demo

* minor changes

* add input_strides into KNInputOp

* support output_strides

* transpiler add input/output stride (sgl-project#101)

---------

Co-authored-by: Xinhao Cheng <[email protected]>
Co-authored-by: Zhihao Jia <[email protected]>
zhuyijie88 pushed a commit to zhuyijie88/sglang that referenced this pull request Sep 4, 2025
sammysun0711 pushed a commit to sammysun0711/sglang that referenced this pull request Dec 19, 2025
blzheng added a commit to blzheng/sglang that referenced this pull request Feb 6, 2026
sywangyi pushed a commit to sywangyi/sglang that referenced this pull request Feb 26, 2026
sywangyi added a commit to sywangyi/sglang that referenced this pull request Feb 27, 2026
* port layernorm 3d

* apply layernorm

* support for bias

* fix

* intf fix

* add support for CPU

* fix tp=3/6 padding issue in encoder vision

* fix tp=3/6 padding issue in qwen3-omni

* refactor code

* add mrope

* change attention_mask shape to use flash attn

* add kernel apply_rotary_pos_emb_cpu

* replace nn.Linear with ReplicatedLinear

* enable torch.compile

* construct mask using query.dtype instead of bool on CPU

* add fast path for sparse attention

* fix double free segfault by wrong setting of BLOCK_M

* improve extend kernel performance for long context length

* update test_extend.py

* update comment

* fix topk softmax performance issue

* port optimization for image preprocessor in Qwen2VLImageProcessorFast

* apply optimization for image preprocessor

* update docker file

* optimize conv3d used in patch embedding

* resolve conflict

* apply optimized conv3d

* apply optimization for flash_attn_varlen_func (sgl-project#19)

* port optimization for flash_attn_varlen_func

* apply flash_attn_varlen_func

* remove contiguous before rope (sgl-project#20)

* Revert "resolve conflict"

This reverts commit 7622f6d.

* fix after rebase

* Update pyproject_cpu.toml

* Update xeon.Dockerfile

* minor fix after rebase

* rope: add support for bf16 sincos (sgl-project#102)

* format

* Update xeon.Dockerfile

* odd tp for cpu

* Apply linear_gelu_linear and fix numa memory bind (sgl-project#22)

* [CPU]  Optimize small oc GEMM for Qwen3-next on CPU (sgl-project#12446)

Co-authored-by: Zheng, Beilei <[email protected]>

* port linear_gelu_linear kernel

* apply linear_gelu_linear for TP=1

* fix numa memory bind

* apply parallel partition patch

---------

Co-authored-by: jianan-gu <[email protected]>

* Revert "Fix: test_vlm_offline_throughput output throughput (sgl-project#13279)" (sgl-project#101)

This reverts commit 7ee3e36.

* fix input dtype mismatch issue

* apply optimized layernorm

---------

Co-authored-by: Zheng, Beilei <[email protected]>
Co-authored-by: ZailiWang <[email protected]>
Co-authored-by: mingfeima <[email protected]>
Co-authored-by: jianan-gu <[email protected]>
khalil2ji3mp6 added a commit to khalil2ji3mp6/sglang that referenced this pull request Mar 14, 2026
xq25478 pushed a commit to xq25478/sglang that referenced this pull request Apr 3, 2026
* fix(remote-spec): restore original zmq log text

* chore(zmq cpp):ZMQ 日志重构,INFO/Warn/Debug
efschu added a commit to efschu/htsglang that referenced this pull request Jul 18, 2026
…t-cause the TW Gemma-4 accept collapse

Root cause of the sgl-project#92 collapse (accept 0.03-0.11/drafted token): the
thoughtworks/Gemma-4-31B-Eagle3 head is trained on BASE google/gemma-4-31B,
not the served -it variant. Proven offline (features through the fork's own
ModelRunner, head standalone): draft/target top-1 overlap 0.61 vs bf16 BASE
self-text, but 0.24 vs bf16-IT and 0.21 vs int4-IT (int4-AutoRound itself
costs only ~0.03 — 'mild', as reported elsewhere). Wiring exonerated by
perturbation: no d2t -> 0.00, reversed aux order -> 0.02, aux ids +-1 ->
0.14/0.24; nothing moves toward healthy, so serving feeds the head
correctly. NOT a fork bug.

Fix: serve the IT-trained RedHatAI/gemma-4-31B-it-speculator.eagle3 head.
Two speculators-format (vLLM ecosystem) conventions handled:
- aux layer ids are vLLM-convention (id i = INPUT of layer i): converter
  translates [2,30,57] -> sglang outputs [1,29,56]. Raw ids cost 0.20
  overlap (0.36 vs 0.56 measured on the int4-IT serving target).
- norm_before_residual=True: input-layer residual is the NORMED hidden.
  New config flag in llama_eagle3.py, default False keeps the SpecForge
  path byte-identical (the False branch is the unmodified original code).
- test/manual/spec/convert_speculators_eagle3.py writes the SpecForge-style
  config and hardlinks the safetensors unchanged.

E2E on the sgl-project#92 rig/battery (TP=3 uneven 5090+2x3080, int4 target, boots
7-11): healthy 40-60s, zero divergence, 4/4 temp-0 coherence probes
byte-identical to the no-spec oracle, needle@8k found, deterministic across
identical-cache-state repeats, cross-boot bit-identical accepts.
Tree (3,4,8): accept-len incl bonus 1.87-2.89 (was 1.19-1.5); decode 68.7
tok/s code / 66.0 prose / 84.1 json vs 58.2 no-spec baseline (1.13-1.44x).
Creative-fiction decode 55.1 (0.95x) and deep@8k decode remain net-negative
on this rig: fixed per-verify overhead dominates (cycle rate 29-39/s vs
59.6 no-spec) — speculation recommended for instruct/code/structured
workloads only. Full data: T92_RESULTS.md section 4 (T101) in the task dir.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
…t-cause the TW Gemma-4 accept collapse

Root cause of the sgl-project#92 collapse (accept 0.03-0.11/drafted token): the
thoughtworks/Gemma-4-31B-Eagle3 head is trained on BASE google/gemma-4-31B,
not the served -it variant. Proven offline (features through the fork's own
ModelRunner, head standalone): draft/target top-1 overlap 0.61 vs bf16 BASE
self-text, but 0.24 vs bf16-IT and 0.21 vs int4-IT (int4-AutoRound itself
costs only ~0.03 — 'mild', as reported elsewhere). Wiring exonerated by
perturbation: no d2t -> 0.00, reversed aux order -> 0.02, aux ids +-1 ->
0.14/0.24; nothing moves toward healthy, so serving feeds the head
correctly. NOT a fork bug.

Fix: serve the IT-trained RedHatAI/gemma-4-31B-it-speculator.eagle3 head.
Two speculators-format (vLLM ecosystem) conventions handled:
- aux layer ids are vLLM-convention (id i = INPUT of layer i): converter
  translates [2,30,57] -> sglang outputs [1,29,56]. Raw ids cost 0.20
  overlap (0.36 vs 0.56 measured on the int4-IT serving target).
- norm_before_residual=True: input-layer residual is the NORMED hidden.
  New config flag in llama_eagle3.py, default False keeps the SpecForge
  path byte-identical (the False branch is the unmodified original code).
- test/manual/spec/convert_speculators_eagle3.py writes the SpecForge-style
  config and hardlinks the safetensors unchanged.

E2E on the sgl-project#92 rig/battery (TP=3 uneven 5090+2x3080, int4 target, boots
7-11): healthy 40-60s, zero divergence, 4/4 temp-0 coherence probes
byte-identical to the no-spec oracle, needle@8k found, deterministic across
identical-cache-state repeats, cross-boot bit-identical accepts.
Tree (3,4,8): accept-len incl bonus 1.87-2.89 (was 1.19-1.5); decode 68.7
tok/s code / 66.0 prose / 84.1 json vs 58.2 no-spec baseline (1.13-1.44x).
Creative-fiction decode 55.1 (0.95x) and deep@8k decode remain net-negative
on this rig: fixed per-verify overhead dominates (cycle rate 29-39/s vs
59.6 no-spec) — speculation recommended for instruct/code/structured
workloads only. Full data: T92_RESULTS.md section 4 (T101) in the task dir.
WhiteCmile added a commit to WhiteCmile/sglang that referenced this pull request Oct 30, 2026
Past capacity, the Target's 120 s round timeout fired on rounds that
were merely queued behind load and aborted their requests with a
truncated answer (issue sgl-project#101: on dev, 1/3391 at r28 staged into a wave
that waited >120 s while both Drafts kept draining ~12 req/s; issue
wait and only SLO attainment degrades.

The timeout is a failure detector, so _expire_local_rounds now expires
a round only after the Draft that owns it has been silent for the whole
round-timeout window. Observed progress (result batches, source
read-dones, direct candidate completions) stamps a per-Draft clock;
ledger rounds with a known owner use it, and rounds without an owner
(parked/feature-control, pre-ack) expire only when every Draft has been
silent. With no recorded progress the deadline stays absolute, and a
killed Draft is still detected: the Coordinator's pidfd session-replaced
path fails its rounds within one sweep.
WhiteCmile added a commit to WhiteCmile/sglang that referenced this pull request Oct 30, 2026
CI review on PR sgl-project#102 (issue sgl-project#101):

- _expire_local_rounds cached the raw minimum deadline as the next
  possible expiry. A round past its deadline that fresh Draft progress
  keeps alive stayed in the ledger with its deadline in the past, so
  the cache never advanced and TP0 walked the whole ledger plus
  parked/feature-control collections on every scheduler poll (often
  twice) throughout overload — undoing the expiry-scan skip exactly
  when the new behavior activates. Cache the next *effective* expiry
  instead: max(deadline, owning Draft's last progress stamp + timeout),
  via a new effective_deadline_ns transform on
  TargetRoundLedger.next_deadline_ns. Progress stamps only move later,
  so the cached bound stays a conservative lower bound on the next
  real expiry.

- Drop the getattr fallbacks added for partial object.__new__ test
  doubles (Occam): production __init__ always sets _draft_progress_ns
  and round_timeout_ns, and TargetRoundState always carries
  draft_instance_id. The affected fixtures now establish those real
  invariants themselves.

- Import the Draft-progress freshness predicate from dt_protocol
  (single source shared with the Coordinator) instead of a local copy.
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