Skip to content

[Feature, Hardware] Enable SGLang on AMD GPUs via PyTorch for ROCm - #1420

Merged
merrymercy merged 8 commits into
sgl-project:mainfrom
HaiShaw:main
Sep 17, 2024
Merged

merrymercy merged 8 commits into
sgl-project:mainfrom
HaiShaw:main

Conversation

@HaiShaw

@HaiShaw HaiShaw commented Sep 14, 2024 •

Copy link
Copy Markdown
Collaborator

Motivation

  • Enable SGLang on AMD GPUs

Modifications

  • Bypass FlashInfer backend untill it is available on AMD/ROCm

  • Add proper fix for AMD FP8 e4m3fnuz to support Fused_MoE

  • Dependency over vLLM>=0.5.5, I modified pyproject.toml just to confirm that it works up to 0.6.0 as well.

  • Misc.

  • TODO: follow-up to address one error (below) when cuda-graph is enabled.

File "/sglang/python/sglang/srt/layers/sampler.py", line 164, in top_k_top_p_min_p_sampling_from_probs_torch
    min_p_thresholds = probs_sort[:, 0] * min_ps
    TypeError: unsupported operand type(s) for *: 'Tensor' and 'NoneType' (where min_ps is None)

How to run

  • An example on one MI3xx (not performance benchmark)
root@x:/sglang# VLLM_MOE_PADDING=0 python -m sglang.bench_latency --batch-size 32 --input 1024 --output 8 --model dummy_half_grok1/ --tokenizer-path Xenova/grok-1-tokenizer --load-format dummy --tp 8 --quant fp8  --attention-backend triton --sampling-backend  pytorch --disable-cuda-graph
Warmup ...
Prefill. latency: 25.79838 s, throughput:   1270.16 token/s
Decode.  latency: 0.53607 s, throughput:     59.69 token/s
Decode.  latency: 0.31325 s, throughput:    102.15 token/s
Decode.  latency: 0.04105 s, throughput:    779.47 token/s
Decode.  latency: 0.04075 s, throughput:    785.31 token/s
Decode.  median latency: 0.17715 s, median throughput:    180.64 token/s
Total. latency: 26.730 s, throughput:   1230.70 token/s
Benchmark ...
Prefill. latency: 1.11868 s, throughput:  29291.72 token/s
Decode.  latency: 0.02593 s, throughput:   1234.10 token/s
Decode.  latency: 0.02575 s, throughput:   1242.87 token/s
Decode.  latency: 0.02559 s, throughput:   1250.46 token/s
Decode.  latency: 0.02646 s, throughput:   1209.23 token/s
Decode.  latency: 0.02574 s, throughput:   1243.42 token/s
Decode.  median latency: 0.02574 s, median throughput:   1243.15 token/s
Total. latency:  1.325 s, throughput:  24925.60 token/s
root@x:/sglang#

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.

@HaiShaw HaiShaw changed the title Enable SGLang on AMD GPUs via PyTorch for ROCm (#1419) Enable SGLang on AMD GPUs via PyTorch for ROCm Sep 14, 2024
@Ying1123 Ying1123 mentioned this pull request Sep 14, 2024
15 of 29 tasks

@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.

  1. We deprecated --disable-flashinfer --disable-flashinfer-sampling. Please use --attention-backend triton --sampling-backend pytorch instead.
  2. Alternatively, you can set these backends automatically here https://github.com/HaiShaw/sglang/blob/8715deff22727382ce6f74768213e3e72f413f71/python/sglang/srt/server_args.py#L155
if is_hip():
    self.attention_backend = "triton"
    self.sampling_backend = "pytorch"
  1. The sampler + cuda graph issue has been fixed by #1392. You can rebase and try it again.
    python -m sglang.bench_latency --model-path TinyLlama/TinyLlama-1.1B-Chat-v0.4 --attention-backend triton --sampling-backend pytorch This runs correctly.

Comment thread python/pyproject.toml Resolved
Comment thread python/sglang/srt/layers/activation.py Resolved
Comment thread python/sglang/srt/layers/activation.py Resolved
Comment thread python/sglang/srt/layers/layernorm.py Resolved
Comment thread scripts/deprecated/test_flashinfer.py Resolved
Comment thread python/sglang/srt/server.py Resolved
Comment thread python/sglang/srt/layers/layernorm.py Resolved
@HaiShaw
HaiShaw requested a review from merrymercy September 16, 2024 05:21
@Ying1123 Ying1123 changed the title Enable SGLang on AMD GPUs via PyTorch for ROCm [Feature, Hardware] Enable SGLang on AMD GPUs via PyTorch for ROCm Sep 16, 2024
Comment thread python/sglang/srt/layers/activation.py Resolved
@merrymercy
merrymercy enabled auto-merge (squash) September 17, 2024 07:31
@merrymercy
merrymercy merged commit 3a6e041 into sgl-project:main Sep 17, 2024
@rj-linqingxu

Copy link
Copy Markdown

rocm 6.1.2
Memory access fault by GPU node-1 (Agent handle: 0x5629173ccc50) on address 0x7fcbccfeb000. Reason: Page not present or supervisor privilege.
Aborted (core dumped)
root@7acc50a881cf:/usr/local/lib/python3.10/dist-packages# /usr/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
warnings.warn('resource_tracker: There appear to be %d '

@merrymercy

Copy link
Copy Markdown
Collaborator

@linqingxu try --disable-cuda-graph for now? We are working on more fixes.

efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 16, 2026
… the match walk names the child keys it has vs wants when it stops with key left (D reached 4314 of 98550 with the prefetched chain below); write_backup names its refusal branch (sweep refused=34 at in_flight=2, drain W3). Tests: 1417, 1175: 10 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…NG_ANTHROPIC_INLINE_SYSTEM_IN_PLACE, default off)

Claude Code 2.1.280 sends mid-conversation role:"system" messages
(api_system: tool additions/removals, output_config). With the Qwen3.8
template (head-only system turn) the Anthropic adapter hoisted them into the
head system turn, so the first turn that carries one re-renders every token
behind the system text. Measured on D: radix sgl-project#1420 WALK-STOP and the arena
key chain (sgl-project#1439 leading_complete) both stop at the end of the system turn
-- depth 3876 (dkr27bnvfp4bar1agent09252328, weg2-14-16/-17) and 4655
(dkr27bbar1final09260145, weg2-12-12), stored (13,248046)=".<|im_end|>",
new (13,198)=".\n" (the "\n".join of the hoist). The sgl-project#904 census then reads
MambaComponent:absent at that depth, X-GATE W31, X-REQUEUE, one P epoch.
The front's request_text renders the same message in place and credits the
whole previous turn (presence_span 19335/20168), so it routes SHORT.

Switch on: non-leading inline system messages become a user turn at their
position, wrapped in <system-reminder>; the leading run is still merged into
the head. Must be set identically on P and D (handoff keys are P's
tokenization). Off = byte-identical to before.

Tests (test27b.sh, CPU):
  test_inline_system_in_place.py 5 passed (off pins the break at ".\n",
  on pins turn N as a rendered prefix of turn N+1);
  anthropic/test_serving.py + test_anthropic_557.py + test_anthropic_rid_h90.py
  + weg2/test_weg2_messages_wire_rc7_0925.py: 100 passed together.

UNIFY (UN6, Operator 26.09.): pick of desk/27b-mambaend-0926 (2303948, MZ, base 0644c6f) after
the sgl-project#49-rest port, clean. dup_defs_gate: 0 new. test27b.sh: test_inline_system_in_place +
anthropic/test_serving + test_anthropic_557 + test_anthropic_rid_h90 91 passed, 9 subtests.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…gl-project#49 armed lines

Every prefix miss of an agent-load boot gets a token receipt. With
SGLANG_WEG2_PREFIX_TRACE=1 (min rest SGLANG_WEG2_PREFIX_TRACE_MIN_TOKENS,
default 1024), read once per process (weg2/prefix_trace.py, armed line
"#PT PREFIX-TRACE armed=<0|1> min_tokens=M group=G pid=P"):

- sgl-project#1420 WALK-STOP: one line per (rid, stop depth) with rest >= min, no
  process cap, root stops included; appends
  "rid=<full> trace=1 stop_node=N stop_hash=H want_run=[..] have_run=[[..]]".
  A split stop now names the TRUE rest and want (the un-advanced key made
  depth+remaining exceed pt-1 by the split's matched part; also untraced).
- sgl-project#1400/sgl-project#1416/#1416d/#1416e (and TK's sgl-project#1442 ADOPT / TK ABS-TOLD): full rid,
  8/256 sampling lifted.
- sgl-project#1442 HANDOFF-KEYS REG, sgl-project#1040 EXTENT STATE-ALIGN: one line per distinct
  (rid, matched, span) / (rid, extent).
- sgl-project#1469 EVICT: uncapped (outside the 600), + parent, pages, hash_first,
  hash_last, key_len, trace=1.
- sgl-project#1427 ARENA-DROP: uncapped, + "trace=1 claim=<stem> dropped=<lo64 hex,..>".
- sgl-project#1439 ARENA-PRESENT: once per distinct (keys, leading, first stem) with
  rest >= min, + "trace=1 break_stem_full=<stem>" (joinable to dropped=).
No traced line sits on the decode round path.

Armed lines (once per process): "#MZ INLINE-SYSTEM-IN-PLACE armed= merge=
group= pid=" (anthropic adapter, P and D HTTP process) and "WEG2-FRONT sgl-project#49
SPAN-INFLIGHT armed= role=front pid=" (front start).

Tests (desk, CUDA_VISIBLE_DEVICES="", test27b.sh):
Base: desk/27b-unified-0926 @ 2bddf04 (rebased from f4b6f21, clean).
- new test/registered/unit/mem_cache/test_weg2_prefix_trace_in.py: 16 passed
- rebased run, all files below plus test_weg2_store_told_{hold,positive}_tk:
  324 passed
- managers/test_weg2_store_told_{1400,paced_1416e}, test_weg2_p_twin_defer,
  test_prefetch_deferral_1068, test_weg2_p_burst_clock_h42c,
  test_weg2_p_multi_anchor_tails_h42, anthropic/test_inline_system_in_place,
  mem_cache/test_arena_{queue_refs_27b,inner_anchor_release_0924},
  test_backup_ack_drain_tp_asymmetry_h74, test_hicache_drain_budget_27b,
  weg2/test_weg2_{p_intake_h91a,front_span_inflight_fs,arena_reset_release_h81,
  node_value_trail_1469}, test_producer_phase_census_wiring_1061: 232 passed
- test_hicache_arena_claim_1427, test_weg2_handoff_1442,
  test_weg2_store_short_tail_xsn437, test_evict_frees_the_bound_allocator_941,
  test_weg2_p_trim_end_anchor_0924: 50 passed
- test_unified_radix_cache_unittest.py, per class, against the base:
  identical FAILED sets (pre-existing on the CPU desk; ps128_sw4/sw128
  OOM in the 3 GiB cgroup on both trees)

Unify note (RM, pick onto 2a7f992): conflicts line by line (store_told: PF fallback forget kept + IN _rt(rid); front: IN line helper + the P49 request_text signature). The sgl-project#49 SPAN-INFLIGHT armed line also names agent_span (the inflight credit needs the sgl-project#49 span, profile field agent_span); its test pin follows.
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.

3 participants