Skip to content

Commit 7591590

Browse files
authored
Merge pull request #13 from antmikinka/investigate/rocm-dual-load-segv
docs(rocm): gfx1150 dual-process large-model load SIGSEGV (exclusive OK)
2 parents 0dadb70 + ed14d5b commit 7591590

38 files changed

Lines changed: 1328 additions & 603 deletions
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# ROCm mlx investigation — are there confirmed issues?
2+
3+
**Date:** 2026-07-19
4+
**Repo:** [NripeshN/mlx](https://github.com/NripeshN/mlx) branch **`rocm-support`**
5+
**Local:** `/home/antmi/mlx`
6+
**mlx SHA:** `0dadb703d77301af29405cf7e12627efb88a6d0f`
7+
**Consumer:** lemon-mlx-engine (FetchContent same SHA), model `LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit`, **gfx1150**
8+
9+
---
10+
11+
## Executive verdict
12+
13+
## Upstream draft PR
14+
15+
**Draft PR (docs only):** https://github.com/NripeshN/mlx/pull/13
16+
**Head:** `antmikinka/mlx` → https://github.com/antmikinka/mlx-rocm branch `investigate/rocm-dual-load-segv`
17+
**Base:** `NripeshN/mlx` `rocm-support`
18+
19+
Note: GitHub renames `antmikinka/mlx` → **`antmikinka/mlx-rocm`**. NripeshN/mlx has **issues disabled**; draft PR is the discussion vehicle.
20+
PR #12 (lemonade-sdk head) was **closed** as wrong head.
21+
22+
23+
| Question | Answer |
24+
|----------|--------|
25+
| Is there a **confirmed mlx ROCm failure mode** on this machine? | **YES — dual large-model process load → SIGSEGV (exit 139)** |
26+
| Is there a confirmed **single-process correctness** bug blocking eager decode? | **NO** (exclusive loads pass; engine product path green) |
27+
| Should we open a **code PR** that “fixes GDN/copy” without more isolation? | **NO** |
28+
| Should we open a **GitHub issue** (robustness / OOM→SEGV)? | **OPTIONAL / YES if documenting** — frame as dual-process overcommit SEGV, not “copy kernel math wrong” |
29+
| Must product wait on mlx tip? | **NO** for eager single-process; ops rule: one process |
30+
31+
---
32+
33+
## Candidate inventory (from engine loops + this pack)
34+
35+
| ID | Symptom | Where stack dies | Confirmed? | Ownership |
36+
|----|---------|------------------|------------|-----------|
37+
| **M1** | 2nd process load SIGSEGV after MTP-skip | `hipLaunchKernel` ← mlx `copy_contiguous` / bf16→f32 | **YES** (this pack dual A/B) | mlx ROCm **or** HIP driver OOM path + allocator; **triggered by ops dual-load** |
38+
| **M2** | Exclusive chat/server load | — | **PASS** 2/2 chat exclusive | — |
39+
| **M3** | MTP `There is no Stream(cpu, N)` | `mlx/backend/cpu/encoder.cpp` | **Reproduced earlier in engine with `--use-mtp`**; **not re-tested here** (MTP deferred) | mlx stream TLS / engine MTP thread hygiene — **open if MTP productized** |
40+
| **M4** | Pure-graph / capture desync | rocm `device.cpp` capture/arena | **Not exercised** (eager only) | deferred |
41+
| **M5** | Engine ChatSession / stop / thinking | — | Engine-owned; fixed elsewhere | **not mlx** |
42+
43+
---
44+
45+
## Exclusive vs dual-load matrix (this run)
46+
47+
**Harness:** engine binaries linked against this mlx SHA (same `0dadb703`).
48+
**Env:** `MLX_DECODE_GRAPH_PURE_OFF=1`, no `MLX_LOAD_MTP_HEAD`, no quant fuse.
49+
50+
| Run | Result | Log |
51+
|-----|--------|-----|
52+
| exclusive chat #1 | **PASS** Model loaded | `logs/excl-chat-1.log` |
53+
| exclusive chat #2 | **PASS** Model loaded | `logs/excl-chat-2.log` |
54+
| server up (holds ~18 GB) | **PASS** health | `logs/dual-server.log` |
55+
| chat load **while server holds model** | **FAIL_SEGV rc=139** after MTP-skip line | `logs/dual-chat.log` |
56+
57+
**Interpretation:** Failure correlates with **second ~18 GB model** on unified-memory APU (~8.5 GiB VRAM report), not with exclusive first-forward GDN. Stack class matches historical gdb (copy → HIP), but root is **resource overcommit / ungraceful failure**, not proven single-stream kernel logic bug.
58+
59+
---
60+
61+
## Code map (mlx tree)
62+
63+
| Component | Path |
64+
|-----------|------|
65+
| Contiguous copy kernels | `mlx/backend/rocm/copy/copy_contiguous.hip` |
66+
| Copy dispatch | `mlx/backend/rocm/copy.hip` |
67+
| CPU stream missing | `mlx/backend/cpu/encoder.cpp` (“There is no Stream(cpu, {})…”) |
68+
| ROCm eval / graph decode | `mlx/backend/rocm/eval.cpp`, `device.cpp` |
69+
70+
Historical engine gdb (not re-run here):
71+
`Qwen35MoEGatedDeltaNet` → `eval` → `copy_contiguous` → `hipLaunchKernel` in `libamdhip64`.
72+
73+
---
74+
75+
## Decision matrix (for maintainers)
76+
77+
| Action | Do it? | Condition |
78+
|--------|--------|-----------|
79+
| Document dual-load SEGV in **this repo** | **Yes** | This RESULTS.md |
80+
| Open **issue** on NripeshN/mlx | **Optional** | Title like: *ROCm gfx1150: SIGSEGV on second concurrent large model load (copy_contiguous / hipLaunchKernel)* — include dual A/B, pins, “exclusive OK” |
81+
| Open **fix PR** without repro isolation | **No** | No minimal pure-mlx unit repro yet; dual-load is multi-process |
82+
| Blame product “gibberish” on mlx FA kernels | **No** | Loop6 engine gate: stop/C1/thinking floor pass exclusive |
83+
| Pursue MTP Stream(cpu) | **Later** | Only when product enables MTP |
84+
85+
---
86+
87+
## Recommended issue body (if filing)
88+
89+
```text
90+
Title: [ROCm] SIGSEGV (hipLaunchKernel) when loading a second large model while first process holds ~18GB (gfx1150)
91+
92+
mlx: 0dadb703 (rocm-support)
93+
GPU: gfx1150 AMD Radeon 890M
94+
Repro:
95+
1) start process A: load Qwen3.6-35B-A3B-MTP-mlx-4bit (lemon-mlx-engine server)
96+
2) while A healthy, process B: same model via chat CLI
97+
3) B dies exit 139 after device bind / early load (copy_contiguous path)
98+
Control: exclusive single process loads succeed repeatedly.
99+
Ask: should allocator/HIP return OOM cleanly instead of SEGV?
100+
```
101+
102+
---
103+
104+
## Product / ops (not mlx code)
105+
106+
On this APU: **never** run two full 35B MLX processes. Engine docs (loop6) already state this.
107+
108+
---
109+
110+
## Supervisors (quintuple)
111+
112+
| Role | Verdict |
113+
|------|---------|
114+
| Decode/ROCm | Dual-load SEGV confirmed; exclusive path clean |
115+
| QA | A/B exclusive vs dual is required evidence |
116+
| Ownership | M1 = mlx/HIP robustness + ops; M5 = engine; M3 MTP deferred |
117+
| Product | Unblocked single-process; do not block on mlx PR |
118+
| Clear Thought | Falsified “exclusive chat always broken”; confirmed dual-load |
119+
120+
*End of investigation pack. Next loop: optional issue draft PR or pure-mlx microbench for OOM handling.*
121+
122+
## CI / lint (PR #13)
123+
124+
CI runs `pre-commit` with **`--all-files`** (see `.github/workflows/build_and_test.yml` → pre-commit/action default).
125+
The investigation docs alone do not touch C++ sources, but **Check Lint** still formats the whole tree against clang-format v21 / cmake-format.
126+
127+
This branch includes a **lint-only** commit so `Check Lint` is green for maintainer review. No intentional behavior change in ROCm kernels.
128+
129+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Loading model: LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit
2+
[mlx-rocm] bound HIP device 0: gfx1150 (AMD Radeon 890M Graphics) cus=8 warp=32 lds=64KB
3+
[MTP] skipping optional MTP head build (set MLX_LOAD_MTP_HEAD=1 to enable; not needed for eager/no-MTP)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Device: ROCm GPU
2+
Loading model: LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit
3+
[mlx-rocm] bound HIP device 0: gfx1150 (AMD Radeon 890M Graphics) cus=8 warp=32 lds=64KB
4+
[MTP] skipping optional MTP head build (set MLX_LOAD_MTP_HEAD=1 to enable; not needed for eager/no-MTP)
5+
[mlx-rocm] gfx1150 native_wmma=1 cus=8 warp=32 low_cu=1 host_WARP_SIZE=32
6+
Model loaded. Memory: active=18.2 GB, peak=18.3 GB, cache=10.5 GB
7+
Endpoints:
8+
GET /health
9+
GET /v1/models
10+
POST /v1/chat/completions
11+
POST /v1/completions
12+
POST /load
13+
POST /unload
14+
Server listening on http://127.0.0.1:8080
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Loading model: LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit
2+
[mlx-rocm] bound HIP device 0: gfx1150 (AMD Radeon 890M Graphics) cus=8 warp=32 lds=64KB
3+
[MTP] skipping optional MTP head build (set MLX_LOAD_MTP_HEAD=1 to enable; not needed for eager/no-MTP)
4+
[mlx-rocm] gfx1150 native_wmma=1 cus=8 warp=32 low_cu=1 host_WARP_SIZE=32
5+
Model loaded. Memory: active=18.2 GB, peak=18.3 GB, cache=10.5 GB
6+
Type your message (or 'quit' to exit):
7+
8+
>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Loading model: LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit
2+
[mlx-rocm] bound HIP device 0: gfx1150 (AMD Radeon 890M Graphics) cus=8 warp=32 lds=64KB
3+
[MTP] skipping optional MTP head build (set MLX_LOAD_MTP_HEAD=1 to enable; not needed for eager/no-MTP)
4+
[mlx-rocm] gfx1150 native_wmma=1 cus=8 warp=32 low_cu=1 host_WARP_SIZE=32
5+
Model loaded. Memory: active=18.2 GB, peak=18.3 GB, cache=10.5 GB
6+
Type your message (or 'quit' to exit):
7+
8+
>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
excl_chat_1 PASS rc=0
2+
excl_chat_2 PASS rc=0
3+
server_up
4+
dual_chat FAIL_SEGV rc=139
5+
Loading model: LemonMLXE/Qwen3.6-35B-A3B-MTP-mlx-4bit
6+
[mlx-rocm] bound HIP device 0: gfx1150 (AMD Radeon 890M Graphics) cus=8 warp=32 lds=64KB
7+
[MTP] skipping optional MTP head build (set MLX_LOAD_MTP_HEAD=1 to enable; not needed for eager/no-MTP)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mlx_sha=0dadb703d77301af29405cf7e12627efb88a6d0f
2+
engine_server_md5=8984dfd5d95316662f784a4ef91eb414

‎mlx/backend/cuda/custom_kernel.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ void CustomKernel::eval_gpu(
284284
// Output index -> aliased input index (output reuses the input's buffer).
285285
std::vector<int> alias_of(outputs.size(), -1);
286286
for (auto& [oi, ii] : output_input_aliases_) {
287-
if (oi >= 0 && oi < (int)outputs.size() && ii >= 0 && ii < (int)inputs.size())
287+
if (oi >= 0 && oi < (int)outputs.size() && ii >= 0 &&
288+
ii < (int)inputs.size())
288289
alias_of[oi] = ii;
289290
}
290291

‎mlx/backend/gpu/primitives.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace mlx::core::rocm {
2323
// True from HIP-graph capture start until the captured graph is destroyed.
2424
bool graph_active();
25-
}
25+
} // namespace mlx::core::rocm
2626
#endif
2727

2828
namespace mlx::core {
@@ -45,8 +45,7 @@ void AsType::eval_gpu(const std::vector<array>& inputs, array& out) {
4545
return;
4646
}
4747
}
48-
CopyType ctype =
49-
in.flags().contiguous ? CopyType::Vector : CopyType::General;
48+
CopyType ctype = in.flags().contiguous ? CopyType::Vector : CopyType::General;
5049
copy_gpu(in, out, ctype);
5150
}
5251

‎mlx/backend/metal/custom_kernel.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void CustomKernel::eval_gpu(
3030
// Output index -> aliased input index (output reuses the input's buffer).
3131
std::vector<int> alias_of(outputs.size(), -1);
3232
for (auto& [oi, ii] : output_input_aliases_) {
33-
if (oi >= 0 && oi < (int)outputs.size() && ii >= 0 && ii < (int)inputs.size())
33+
if (oi >= 0 && oi < (int)outputs.size() && ii >= 0 &&
34+
ii < (int)inputs.size())
3435
alias_of[oi] = ii;
3536
}
3637

0 commit comments

Comments
 (0)