Skip to content

Time cost utils - #355

Merged
hnyls2002 merged 3 commits into
mainfrom
time-cost
Apr 9, 2024
Merged

hnyls2002 merged 3 commits into
mainfrom
time-cost

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Apr 9, 2024 •

Copy link
Copy Markdown
Collaborator

This PR introduces --show-cost-time server argument and change the cost time mark style.

@hnyls2002
hnyls2002 merged commit 62b3812 into main Apr 9, 2024
@hnyls2002
hnyls2002 deleted the time-cost branch April 9, 2024 15:27
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
@csbo98

csbo98 commented Jul 29, 2025

Copy link
Copy Markdown

@hnyls2002 Hi, thank you for your outstanding contribution for this pr. I'm quite interested in the feature proposed in this PR, but I still have some questions. As of now, it hasn't been actively used in sglang. What is the purpose of --show-cost-time, and in what scenarios would it be enabled? Since both mark_start and mark_end involve CUDA synchronization, I assume this feature wouldn't be suitable for production use?

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

@csbo98 It is only for debugging and profiling. For now, we'd better suggest using torch profile or nsys. It is true that if you want to profile every part of SGLang precisely, the extra synchronization overhead cannot be avoided.

In the production, we have /metrics API, which is not for directly calculating the running time for each part of the code, but it can reflect our performance through metrics such as throughput.

@hnyls2002

Copy link
Copy Markdown
Collaborator Author

@csbo98 There is another way to get the real-time consumption for each part of the code. There are some natural synchronizations in SGLang, like all the to_list or cpu operations. You can add a time counter here to get the profiling without loss.

@csbo98

csbo98 commented Jul 30, 2025

Copy link
Copy Markdown

@hnyls2002 Thank you very much for your detailed reply.

shiyu7 pushed a commit to shiyu7/sglang that referenced this pull request Dec 26, 2025
vschandramourya pushed a commit to vschandramourya/sglang that referenced this pull request Feb 3, 2026
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
liuxianglong17 pushed a commit to shun8686/sglang that referenced this pull request Apr 20, 2026
change assert method of speculative decoding parameters
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…iformity note, byte-identity test

kv_bound_check_enabled() is 683 ns/call (200k reps) and kv_store_bound() 291 ns;
at 16 full-attention layers per Qwen3.6-27B step that is ~11 us of host time per
decode step, below 0.1% of a 15-25 ms step on this rig. Recorded as a number
rather than left as an adjective, together with why it stays uncached.

Both asserts sit after BLOCK-UNIFORM early returns. Triton's assert lowering may
emit a barrier and a barrier reached by only part of a block hangs, so the
uniformity is now stated where a future early return would be added.

New test: the store_cache arm is byte-identical to the pre-sgl-project#355 inline
expression for three real pool geometries -- 'no behaviour change on the raw
path' is now a fact rather than a claim. 21 CPU cases green.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…plit

agent-354 held all three cards through this window (0/1/2 at 19787/30031/18685
MiB, phase-optimal sgl-project#354 runs), so the two card-side proofs did not run. Package
them as one command a later card window runs turnkey:

  CARD=0 bash scripts/dev/run_355_gpu.sh

Bounded (600s), gpu-arb holder with heartbeat, feasibility-arith preflight
(refuses a card with >900 MiB used, corridor >=400 MiB free), signals only its
own PIDs, self-releases on every exit path. It runs the microbench (ns/call
off-vs-on, A/B interleaved with an A-vs-A noise floor, Qwen3.6-27B decode row),
the 4-case out-of-range falsifier, and the sgl-project#352 regression on the shared helper.

Interpreter smoke test (TRITON_INTERPRET=1) confirms the kernel runs with the
new bound parameter and writes in-range correctly; device-assert semantics need
a real card, hence the follow-up. Validation doc records the honest split:
desk-complete, GPU falsifier/microbench pending one card window.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…riters (DCP owner-mask + commit-lens), shared kv_store_bound helper (sgl-project#355)

# Conflicts:
#	docs/dev/INTEGRATION_R3_VALIDATION.md
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…8 where it cannot compile

Two defects in scripts/dev/run_355_gpu.sh, both found by running it.

The script set CUDA_VISIBLE_DEVICES but not CUDA_DEVICE_ORDER. CUDA's default
is FASTEST_FIRST, which on this rig is not NVML's order, so the run did its
free-memory preflight on NVML 0, wrote a gpu-arb holder claiming card 0, and
then benchmarked the 5090. Caught only because the benchmark prints
torch.cuda.get_device_name(0) itself. This is the trap TASK_333 SS9.3 records
for the video chunk workers, in a script written after it.

The fp8 arm cannot compile on sm86 -- "type fp8e4nv not supported in this
architecture" -- so on a 3080 it has no result to report, which is not the
same as a failed proof though the script returned rc=1 for it. Skipped by
compute capability, and the skip is printed so the arm cannot silently
vanish.

Card results, 2026-07-31 18:49-18:54Z, both cards, recorded in
/spinning/gpu-battery-results/2026-07-31_355_gpu/:

  falsifier, 4 subprocess cases        4 passed on 5090 and on 3080
  sgl-project#352 regression on the shared helper 3 passed on 5090 and on 3080

The microbench falsified its own stated expectation. The script predicted the
bound check would cost less than the A-vs-A noise floor; 9 of 10 shape points
came back MEASURABLE. It costs +21 to +137 ns per call against a floor of
4-28 ns, which is 0.18% to 1.14% of a ~12 us launch and does not grow with N.
The claim to carry forward is "under 1% of launch cost, and measurable".
efschu added a commit to efschu/htsglang that referenced this pull request Jul 31, 2026
…sweep that fills them

Regime-B groundwork. The 1.78x multi-card ceiling measured in TASK_333 SS9.4
is the ceiling of Regime A replicated -- every card running the whole chain
over a share of the frames -- and a frame split cannot beat it by
construction: the best it can do is finish every card at once, and then the
aggregate is the sum of the whole-chain rates. Exceeding it needs stage
specialisation by comparative advantage, and that needs a fact nobody had
measured: how each card's rate varies BY STAGE. A whole-chain number cannot
answer it. If a 3080 is uniformly 0.39 of a 5090 there is nothing to trade
and Regime B cannot win; if it is 0.39 on super-resolution and 0.64 on
encode, moving encode onto it costs less than its whole-chain rate implies.

Three things were missing and all three are here:

1. The probe grid had no decode and no encode row, so the table had a hole at
   each end and no assignment that moved either onto another card could be
   priced at all. probe_decode and probe_encode are added, with their caveats
   in the code rather than in a footnote: encode is measured on synthetic
   content, which is a floor and is comparable across cards but is not a
   prediction for an arbitrary clip; decode is clip-dependent, so the probe
   records which clip it used and a table built from two clips is not
   internally comparable on that row.

2. The pricing had no home in the shared library. Per SS348b it belongs in
   cost_model.py, not in a planner's private structure, so StageRateTable
   lives there: keyed (stage, card, resolution), every cell a provenance-
   tagged Rate, so a combination nobody measured is a named absence rather
   than a KeyError at plan time or an extrapolation. coverage() names the
   (stage, card) pairs a candidate assignment would need and nobody measured,
   which turns "the plan is surprising" into "the plan could not be made".
   advantage() is the comparative-advantage view: each card's time normalised
   to the fastest on that row, which is the form the assignment question is
   actually asked in.

3. shard_plan.RateTable had no production loader -- it was only ever built by
   hand in tests, so every plan made on a real rig was made from numbers a
   human typed. RateTable.from_stage_rates closes that.

One bug found by its own test while writing it: a failed repeat of an already
measured cell overwrote the good value with an absence, so a probe grid that
measured a point twice and hit one transient would delete a real number and
surface later as a planner refusing to price a card it could price. A failure
now only fills a cell that is empty.

scripts/video_enhance/stage_rate_sweep.py drives the sweep one card at a time
in its own process -- two probes sharing a rig measure contention, not
capability -- with CUDA_DEVICE_ORDER=PCI_BUS_ID ahead of CUDA_VISIBLE_DEVICES,
because without it the sweep files the 5090's numbers under a 3080's name.
That is the trap SS9.3 recorded and sgl-project#355 repeated last window.

Two framing corrections from the user are recorded in the code: the historical
vs-pipeline mapping (ESRGAN on the 3080s, RIFE on the 5090) was a convenience
of an early development state and is one candidate among many, not a template;
and the optimiser this table feeds must be free to search the full space --
Regime A replicas, Regime B stage assignment, and mixed forms.

Desk-complete. The sweep itself has not run: the cards have been held by
agent-358 and then sgl-project#357 for this whole window. RIFE on a 3080 is still
unmeasured and is NOT estimated here.

455 video tests pass (23 new in test_stage_rates.py), 32 cost-model tests
pass, ruff and codespell clean. Six failures in test/registered/unit/planner
are pre-existing and reproduce identically with these changes stashed.
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