Skip to content

fix bug of undefined is_single in meth create_abort_task - #1370

Merged
merrymercy merged 1 commit into
sgl-project:mainfrom
wcsjtu:main
Sep 10, 2024
Merged

merrymercy merged 1 commit into
sgl-project:mainfrom
wcsjtu:main

Conversation

@wcsjtu

@wcsjtu wcsjtu commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

Motivation

According to the current logic in GenerateReqInput.post_init, when neither text nor input_ids are provided, the is_single field will not be dynamically set. This results in an AttributeError being triggered in TokenizerManager.create_abort_task.

Additionally, dynamically setting fields in a dataclass is not a good practice. The fields in a dataclass should all be predefined.

Modifications

I just add predefined field is_single: bool = True to class GenerateReqInput and EmbeddingReqInput

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

@zhyncs

zhyncs commented Sep 10, 2024

Copy link
Copy Markdown
Contributor

Can you provide a simple demo for reproducing the issue?

@wcsjtu

wcsjtu commented Sep 10, 2024

Copy link
Copy Markdown
Contributor Author

Can you provide a simple demo for reproducing the issue?

you can reproduce it via this code with any model and any launching parameter.

import requests
# use your url
url = "http://localhost:10000/generate"
res = requests.post(url, json={"text": None, "stream": True}, stream=True)
print(res)

sglang will raise

  File "/usr/local/lib/python3.8/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/local/lib/python3.8/dist-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.8/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.8/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.8/dist-packages/starlette/routing.py", line 77, in app
    await response(scope, receive, send)
  File "/usr/local/lib/python3.8/dist-packages/starlette/responses.py", line 267, in __call__
    await self.background()
  File "/usr/local/lib/python3.8/dist-packages/starlette/background.py", line 45, in __call__
    await task()
  File "/usr/local/lib/python3.8/dist-packages/starlette/background.py", line 28, in __call__
    await self.func(*self.args, **self.kwargs)
  File "/root/work/sglang/python/sglang/srt/managers/tokenizer_manager.py", line 542, in abort_request
    if obj.is_single:
AttributeError: 'GenerateReqInput' object has no attribute 'is_single'

@merrymercy
merrymercy merged commit fec2d12 into sgl-project:main Sep 10, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
@wengsnow

Copy link
Copy Markdown

I am using version 0.5.4.post2 for inference and the error persists.

However, it seems to be non-blocking—the service keeps running and the generation results are correct. I checked the source code for 0.5.4.post2 and noticed that the modification discussed here doesn't seem to be included in this release.

Do you have any suggestions? Thanks!
image

efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 13, 2026
…11b's cushion breach

Wand 11b (sgl-project#1377) is the open host blocker for the goal-question boot: the
bounce prices 5 measured lanes x 3.00 GiB + 0.75 GiB staging = 15.75 GiB on
xsn31/3's own checkpoint (front.log:111 xchg_bounce=15.75, front.log:106
lanes=5 source=measured), and the sleep-leg cushion floor (1.50 GiB) latches
at 0.20 (W98 Weg2HostRateLatched) because that growth ate the room. sgl-project#1370
made the bounce PRICED HONESTLY; it did not make it SMALLER.

ONE SOURCE, the --xchg-bounce-depth shape (48adc00) reused rather than a
second publication path: `BounceTerms.lanes_concurrent` (0 = "not stated",
byte-identical -- the same convention `max_tag_bytes` already uses two
fields over) caps how many of `n_lanes` price at once through a new
`lanes_priced` property; `total_bytes` reads that property instead of
`n_lanes` directly. The field rides `_TERM_FIELDS`, so P, D and the host
ledger recompute the identical capped total from the published inputs,
never a second formula. `checkpoint_census.widest_layer_terms` and
`launcher.choose_host_ledger` / `xchg_bounce_terms_for_arm` pass it through
unchanged; `main()` resolves the CLI value exactly once
(`xchg_bounce.resolve_lanes_concurrent`) and hands the same resolved int to
both the ranks' publication call and the ledger's own call, so the two
sides cannot disagree about which values are refused.

REFUSAL, NOT SILENT DEGRADATION: `--xchg-lanes-concurrent 0` (or negative)
is refused (W103 Weg2XchgLanesConcurrentInvalid) rather than folded into
the same 0 sentinel BounceTerms uses for "unset" -- collapsing them would
run every lane concurrently while the argv says the opposite. W103 is the
next free number after a tree-wide census (`grep -rhoE 'W[0-9]+'` tops out
at W102); W52/W53/W54/W56/W58 are a documented collision class (sgl-project#1265/sgl-project#1306)
of guessed digits, so this one is taken from the census.

NAMED AND COUNTED, NEVER SILENT: `WEG2-XCHG-LANES-CONCURRENT
lanes_concurrent= lanes_total= lanes_priced= serialised=` is appended to the
arm's own line list (appended, not inserted, so lines[0..2]'s existing
positional readers are untouched) so a boot can put a number beside the
flip-time cost of serialising the lanes this cap does not price.

THE COMPUTED EFFECT, on xsn31/3's own geometry (largest tag 2907 MiB, 128
MiB slots -> 24 slots/lane -> 3072 MiB/lane, 0.75 GiB staging, 5 measured
lanes): concurrent=2 charges 2 x 3.00 + 0.75 = 6.75 GiB (a 9.00 GiB
reduction from the measured 15.75); concurrent=1 charges 3.75 GiB (12.00
GiB reduction). Against xsn31/3's own cushion_min=0.20 (floor 1.50):
0.20 - (-9.00) = 9.20 >= 1.50 at concurrent=2, and 0.20 - (-12.00) = 12.20
>= 1.50 at concurrent=1 -- the invariant holds with wide margin either way,
using the boot record's own linear-tracking method (6.99 -> 0.20 explained
by the +7.96 GiB bounce growth). NOTE: depth (1 vs 2) changes NOTHING on
this checkpoint -- Option 1's tag-need (23 slots + 1 shadow = 24) dominates
the depth floor (2 or 3) at both depth=1 and depth=2, so the entire saving
here comes from lanes_concurrent alone, not from --xchg-bounce-depth.

HONESTY GATE, NAMED HERE NOT BUILT: this commit wires the cap through
PRICING only. `weight_updater.py`'s per-rank leg driver still allocates a
buffer for every lane it owns unconditionally -- no cross-process
concurrency permit exists yet, so a real boot's tmpfs usage may still
reach `lanes_total`'s worth even though the ledger now charges
`lanes_priced`. A WEG2-XCHG-LANES-CONCURRENT-CAVEAT line names this
explicitly whenever a cap actually serialises lanes, pointing at the same
3-way measurement (sgl-project#1358: tmpfs holders, cgroup d_shmem, host-slot lines)
that must confirm the real peak before this ARM number is trusted.

Tests: test_weg2_xchg_lanes_concurrent_1385.py, 23 cases (hermetic,
CUDA_VISIBLE_DEVICES=""), covering the default byte-identical path, the cap
actually shrinking the charge (the mutant guard for the OOM direction --
manually verified: reverting `lanes_priced` to `n_lanes` in `total_bytes`
fails 3 tests immediately, restored after), refusal for N<1, the W103
census-not-guess check, the named/counted log line (source and execution
smoke through a real fake checkpoint), and the one-source property (single
`resolve_lanes_concurrent(` call in `main`, both call sites take the same
resolved value). test_weg2_widest_layer_census_1332b.py's line-count
assertion updated 3->4 for the new appended line (positional indices
unchanged). 193 tests green across the full bounce/lane/ledger neighbour
suite plus the new file; ruff clean.

Default is byte-identical: lanes_concurrent=0 is the "not stated" sentinel,
`lanes_priced` returns `n_lanes` unchanged, and no existing caller passes
the new keyword.
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