Skip to content

Remove useless variables in infer_batch.py - #651

Merged
Ying1123 merged 1 commit into
mainfrom
fix-infer-batch
Jul 18, 2024
Merged

Ying1123 merged 1 commit into
mainfrom
fix-infer-batch

Conversation

@Ying1123

Copy link
Copy Markdown
Contributor

No description provided.

@Ying1123
Ying1123 merged commit 21ba3a8 into main Jul 18, 2024
@Ying1123
Ying1123 deleted the fix-infer-batch branch July 18, 2024 12:31
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 7, 2026
…efill benchmark

The target shape (laptop: one CPU + one GPU sharing RAM; prefill as an uneven
CPU/GPU PP layer split, decode GPU-only, speculation on) is NOT achievable on
this tree. Recorded with the numbers so nobody re-derives it.

THE CEILING, which needs no measurement: in a balanced two-stage pipeline the
best possible prefill gain from adding a CPU stage is 1 + R_cpu/R_gpu -- the
CPU's share of total compute. At a GPU:CPU prefill ratio of 10x that is +10 %,
at 20x it is +5 %. And PP pipelines microbatches; it does not speed up a single
prefill, so even that needs several chunked-prefill chunks or concurrent
requests in flight.

THE PRICE: a CPU stage cannot hold GGUF K-quants (below), so its layers must be
materialized dense -- measured 3.17x expansion, 506.2 -> 1604.2 MiB per layer.
The balanced split at 10x is 3.6 layers = 5.7 GiB of dense weights to buy +10 %.
On shared RAM those GiB compete with the GPU's own weights.

FOUR BLOCKERS:
1. GGUF K-quant ops are registered for torch::kCUDA only (common_extension.cc
   :431-441); get_quant_method has an _is_npu branch and no _is_cpu. A CPU
   stage cannot execute one GGUF layer. Trap: _is_cuda is a BUILD probe, not
   server_args.device, so on a CUDA laptop the gguf.py:79 warning never fires
   and the failure arrives late as a dispatcher NotImplementedError.
2. Device type is global (server_args.py:1623); only the GPU INDEX is per-rank,
   and GroupCoordinator picks its device from a platform probe
   (parallel_state.py:656-668). --device cpu puts BOTH stages on CPU.
3. PP forbids speculation in one server (server_args.py:16264, DESIGN_625 B1).
4. The two-process escape refuses it too: both PD arms reject
   --speculative-algorithm (pd_disaggregation_hook.py:194-229); the only env
   escape disables spec rather than enabling it. DESIGN_631b is
   specification-only. So BOTH routes to "PP prefill + speculative decode" are
   closed -- on every machine, not just this one. That is Route A's gap.

WHAT IS BUILT AND GOOD: uneven PP layer split is merged and tested
(--pp-layer-ratio, --pp-stage-ratio, SGLANG_PP_LAYER_PARTITION), and the PP p2p
wire has a working gloo/CPU path. The weighting idea is expressible; it just
cannot address a CPU stage. Two gotchas recorded: the ratio must sum to the
backbone depth (40), NOT the GGUF block_count (41, the extra block is MTP); and
max_total_num_tokens is min-reduced across the world group.

SHARED RAM (user): the prefill->decode reshard is logically real but physically
free, since nothing moves between pools. Charged correctly: it removes the
handover cost, makes the phase-split shape attractive on this hardware once
buildable, and probably dissolves the GPU-carve-out question. It does NOT touch
the compute ceiling (FLOPs, not bytes), and it makes the dequantization penalty
worse rather than better, because those GiB now compete with the GPU's weights.

RESTATED GOAL: on one GPU + one CPU, TP is impossible (needs 2 GPUs), PP is
impossible (blockers 1-2, and capped by the ceiling anyway), speculation is
achievable only without PP. The achievable bring-up is GGUF Q4 35B, TP=1, PP=1,
GPU-only, with NEXTN speculation -- stages a and b of docs/dev/651/boot.sh. If
memory is tight, use the CPU as a memory TIER (--cpu-offload-gb keeps compute on
the GPU) rather than a compute stage; whether that composes with GGUF is
unverified and is the thing to test first.

docs/dev/651/bench_prefill.py measures the two rates the split arithmetic needs
(TTFT with max_tokens=1, unique prompts so prefix caching cannot serve them, an
A-vs-A noise floor before any cross-device claim, warmup discarded, time-bounded
runs, a length sweep) and does the balance arithmetic via --split-from.
docs/dev/651/{vram_budget,layer_split,dequant_cost}.py reproduce every number
quoted above.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…backends are closed

The user supplied the real target hardware, which the 2026-08-07 revision never
had: a ThinkPad P14s Gen5 AMD -- Ryzen 7 PRO 8840HS, Radeon 780M iGPU (gfx1103,
RDNA3), 32 GB DDR5 shared between CPU and iGPU. The old revision assumed a
discrete NVIDIA laptop and its conclusions are wrong. The geometry, the sgl-project#647
fix, and the parallelism analysis survive unchanged and are kept.

The laptop is REACHABLE from the rig box ([email protected], efeu-TP14); the
earlier "unreachable" note is stale. Everything in section 1 is measured on it.

BOTH BACKENDS ARE CLOSED, each for an independent, evidenced reason.

iGPU via ROCm: the GGUF K-quant kernels are not in the ROCm build at all -- not
broken, absent. The sources exist (8328 lines under csrc/quantization/gguf/) and
CMakeLists.txt:323 compiles them for CUDA, but setup_rocm.py:43-60 is the whole
ROCm source list and contains no csrc/quantization/ entry; there is no hipify
step. common_extension.cc:428-480 binds every ggml op to torch::kCUDA, while the
ROCm build compiles common_extension_rocm.cc (setup_rocm.py:47), which has zero
ggml_* symbols -- so the op does not exist as a SCHEMA on ROCm. The omission is
deliberate, not a stale shared list: setup_musa.py:91 does list the file.
Independently, setup_rocm.py:77-81 exits 1 for any arch other than gfx942/gfx950,
so sgl-kernel will not build for gfx1103 at all.

Worse, it fails silently. is_cuda() (common.py:146-148) is False on a ROCm torch
build and is_hip() is True, and in gguf.py:41-62 the ggml imports AND their None
fallbacks are all nested inside `if _is_cuda:`. So on ROCm the names are never
bound and the first forward dies with a bare NameError (gguf.py:840, :927, :932,
:1010, :1092, :1107) -- after a clean load. The warning at :78-79 is suppressed
on exactly this hardware (`if not _is_hip`), and supports_current_device()
(:134-152) returns None off CUDA so _enforce_capability_floor abstains. Do not
read a clean load, or the absent warning, as support. The tree already documented
the conclusion twice and it was missed: quantization.md:39 (gguf ROCm = No) and
amd_gpu.md:119.

CPU-only: no CPU K-quant kernel exists (get_quant_method, gguf.py:165-192,
branches only on _is_npu), so a CPU stage must materialize dense at the measured
3.17x (506.2 -> 1604.2 MiB/layer) = ~67 GiB against 29.5 GiB of MemTotal, a 2.27x
overshoot. Dense bf16 is quant-independent, so the Q2 checkpoint lands on the
same ~67 GiB and does not rescue it. This is arithmetic, not a tuning problem.

CONSTRUCTIVE HALF: the port is mechanically shallow. The gguf kernels contain no
CUDA-only hardware intrinsics (zero hits for __ldg, cp.async, asm volatile, mma,
wmma, __shfl, __ballot), the AMD shims are already inherited -- ggml-common.h:1019
supplies __vsubss4, __dp4a via __builtin_amdgcn_sdot4 (:1046-1048) and __vcmpeq4
-- moe.cuh carries ~20 USE_ROCM tuning branches, and WARP_SIZE_GGUF 32
(ggml-common.h:6) is already correct for RDNA wave32. So section 7 orders the
real work: widen the gfx allow-list, add the source + register the ops, bind an
elif _is_hip: arm in gguf.py, then validate numerics on RDNA.

MEASURED BUDGET (docs/dev/651/apu_budget.py, new). MemTotal 30211 MiB; BIOS UMA
VRAM 1024 MiB, which the user confirms is the BIOS MINIMUM and cannot go lower;
GTT 24576 MiB pinned by amdgpu.gttsize=24576. The binding ceiling is therefore
GPU-addressable 25600 MiB, not MemTotal, and GTT is backed by the same DDR5 --
it caps what the iGPU may pin, it is not extra memory. Against that ceiling
Q4_K_M (21614 MiB) leaves 3137 MiB of slack and Q2_K_XL (11992 MiB) leaves 12758.
Context is not the binding constraint -- weights are; even Q4 clears ~82k tokens
at fp16 KV. The laptop carries Q4_K_M and Q2_K_XL in /root/lh/models/, NOT the
rig's Q4_K_XL, so the earlier "no smaller fallback without a new download" is
false there: staging now starts on Q2_K_XL.

RESHARD ON SHARED MEMORY (user-confirmed): the PP-prefill/TP-decode flip is
logical only -- everything already lives in one RAM, so it is an ownership/view
reinterpretation and bytes never move. Route A's hardest problem, that the two
layouts want different weight bytes per rank, simply does not exist with one pool
and one process. Latent optimization recorded: on unified memory the PD KV
transfer could hand over ownership, where today the code copies unconditionally.

ACHIEVABLE GOAL, once a backend exists: TP=1/PP=1 + NEXTN speculation, CPU/RAM as
the only tier, --cpu-offload-gb for headroom (composition with GGUF unverified --
first test), MoE expert-offload walled for GGUF by sgl-project#123. PP+spec stays mutually
exclusive tree-wide (server_args.py:16264 one-server assert; both PD arms reject
spec at pd_disaggregation_hook.py:194-229) -- owned by Route A / sgl-project#631, not built
here. Carried forward: --pp-layer-ratio sums to backbone depth 40 not block_count
41, max_total_num_tokens is min-reduced across the world group, and the sgl-project#647 fix
is 0155ff2.

Also noted: docs/dev/651/boot.sh is NVML/CUDA-only (pynvml UUIDs,
CUDA_VISIBLE_DEVICES, nvidia/cu13 LD_LIBRARY_PATH) and must be rewritten for
ROCm before use; its staging logic still applies.

No GPU ran any of this. The model has still never generated a token.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…recting rev1's verdict

Rev1 concluded the bring-up "cannot run on this laptop". That was right about
THIS TREE and wrong about the MACHINE, because it was written before anyone
looked at the laptop. A read-only sweep of it found a complete working setup
left by a prior session in /root/lh/, unrecorded anywhere.

WHAT ACTUALLY RUNS: Qwen3.6-35B-A3B Q4_K_M GGUF serves on the Radeon 780M iGPU
through htsglang at ~12.3-12.8 tok/s decode and ~157-172 tok/s prefill, bs=1,
ctx 8192, TP=1, no speculation. Eight logs reach "server is fired up"; q4_d/e/f
ran clean and answered POST /generate 200 OK, ended only by operator SIGTERM.
Weight load 74.33 s, 21.38 GB resident, 2.86 GB left for KV at ctx 8192.

That measurement VALIDATES the rev1 budget model: predicted room under the
25600-MiB ceiling was 3137 MiB, measured free-after-weights 3.38 GB. Section 4
is retitled accordingly and can now be trusted for planning.

HOW, given section 2 is still entirely correct: the gap was closed OUTSIDE the
repository. torch 2.10.0+rocm7.0 (hip 7.0.51831, cuda None), sglang editable
from /root/lh/sglang_src, no sgl_kernel at all, and a purpose-built standalone
sglang_gguf_rocm extension built for gfx1100 exporting every op the GGUF path
needs plus ggml_mmvq_kq_tuned and ggml_mxfp4_native, which have no in-tree
counterpart. The modified gguf.py imports it at :99 behind an `elif _is_hip:`
arm at :75 -- precisely the binding rev1 section 7 listed as work to be done.
HSA_OVERRIDE_GFX_VERSION=11.0.0 is load-bearing and verified: without it a
64x64 matmul fails hipErrorInvalidDeviceFunction.

The decisive schema check was run and its OBSERVED output now replaces rev1's
"Expect False" in section 2.6: sgl_kernel is not installed (it cannot be -- the
gfx gate), so the in-tree question is moot on this machine; the ops come from
the out-of-tree extension instead.

THE TWO REAL PROBLEMS NOW:
1. Speculation hard-faults the HIP context. NEXTN boots, serves a batch, then
   dies with "unspecified launch failure" within 10-40 s -- twice, at ctx 2048
   and 8192, against a same-config no-spec control four minutes apart that ran
   clean. The crash site (scheduler.py:5206, a .to("cpu")) is only where an
   async fault surfaces; AMD_SERIALIZE_KERNEL=3 was never run to localize it.
   Prime suspect: the draft path reusing a GGUF op validated only on the target
   path. Two earlier spec bugs were already fixed:
   --speculative-draft-model-quantization gguf is REQUIRED (without it the sgl-project#647
   pair of section 9.1 shows up live as 2 unloaded MTP parameters), and at ctx
   8192 the spec arm cannot fit its mamba cache (max_mamba_cache_size=0).
2. The working code is unversioned. /root/lh/sglang_src is NOT a git repo and
   has no baked commit id. The port that makes this machine run exists in one
   unversioned copy on one laptop. This is now the largest risk in the ticket.

NEW CORRECTNESS FINDING, section 1.5.4: Q6_K dequant is non-deterministically
WRONG on gfx1103 -- eight runs on one fixed input differ, worst max|d| 5.8e-01
vs the numpy reference, up to 75 non-finite of 262144, wrong on the first call
in a fresh process, while Q4_K and Q5_K are byte-identical across the same runs.
Eight hypotheses recorded as falsified, including that it is an HSA_OVERRIDE
artefact (a native gfx1103 build is worse -- Q5_K becomes affected too).
Contained, not fixed: ggml_mul_mat_a8 is validated correct for Q6_K on gfx1103
(max|d| 5.5e-04) so Q6_K is pinned to MMQ, and the load path is rescued by an
exact one-time CPU dequantise. Narrow -- 4 tensors of 753 -- but one is the
lm_head this checkpoint ships as Q6_K.

Section 7 is rewritten as a real work queue: localize the spec fault, save a
bandwidth floor and bench output (none survives -- the 12.5 tok/s figure has no
denominator and bench_spec.py's accept-length instrument has never executed),
free headroom for the spec arm, then recover sglang_src into version control and
land the kernel build + HIP binding in-tree.

Also corrected: the marker preamble claimed the model had never generated a
token -- it has; what remains UNVERIFIED is coherence, since no content-checked
probe.py run survives. And rev1's own falsification of "no smaller fallback
without a new download" is kept -- Q2_K_XL is on the laptop and is the right
first bring-up vehicle.

Not evidence, recorded so nobody miscites it: boot_pd631.sh runs a safetensors
2B model, not the GGUF, so it proves PD plumbing only.

Nothing on the laptop was started, stopped or modified; the sweep was read-only.
No rig GPU was used.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…pt the PP-prefill goal

Two things: a rescue, and a goal correction from the user.

=== RECOVERY (provenance: unversioned /root/lh on efeu-TP14, session 2026-08-07) ===

The prior sgl-project#651 strand was killed by the token outage before committing anything.
Its work existed in exactly one copy, on one laptop, in a directory that is not
a git repository and carries no commit id. Losing it would have cost days. This
commit brings it into version control verbatim; reconciliation comes second.

sgl-kernel/recovered-rocm-gguf/ -- the standalone ROCm build of the GGUF K-quant
kernels that is what actually makes Qwen3.6-35B-A3B Q4_K_M serve on the Radeon
780M. Recovered from /root/lh/ggufbuild and /root/lh/ggufmod (two iterations
differing only in extension name: gguf_rocm_probe vs sglang_gguf_rocm). The port
proper is the eight *_hip.{cuh,h} / gguf_kernel.hip files. Laptop originals were
copied out READ-ONLY and left untouched; their SHA-256 sums are recorded in the
directory README so reconciliation stays possible.

It answers the question its own setup.py docstring posed: excluding the GGUF
sources from setup_rocm.py was MISSING BUILD WIRING, not a genuine porting gap.
The sources already carry USE_ROCM branches and torch's HIP extension path
defines -DUSE_ROCM=1.

Also recovered: tests/ with the Q6_K investigation harness -- test_kquant.py,
test_correctness.py, determinism_all.py, oneshot_q6k.py, debug_q6k{,2,3,4,5}.py
-- plus real GGUF block fixtures slice_q{4,5,6}_K.bin and slices.json, which is
what makes comparison against the numpy reference meaningful. The README records
the Q6_K correctness bug and its containment (MMQ pin + one-time CPU dequantise
at load) so the pin cannot be silently dropped: Q6_K dequant is
non-deterministically wrong on gfx1103, eight runs on one fixed input differ,
worst max|d| 5.8e-01, wrong on the first call in a fresh process, while Q4_K and
Q5_K are byte-identical. Eight hypotheses falsified, including "HSA_OVERRIDE
artefact" -- a native gfx1103 build is worse, Q5_K becomes affected too. This
matters concretely because the checkpoint ships a Q6_K lm_head.

docs/dev/651/recovered/gguf.py.laptop.patch -- the gguf.py delta, 6 hunks,
+233/-8 against this branch. Kept as a patch rather than applied, because the
laptop file has a different base. Its core is the elif _is_hip: arm with a
two-source probe (sgl_kernel.quantization first, then the standalone
sglang_gguf_rocm), an exact torch.sum fallback for the unregistered moe_sum, and
a lazily-built activation fallback that documents why it must not construct at
import time. It also removes the `if not _is_hip` guard that was suppressing the
"Only CUDA, MUSA and NPU" warning on exactly the hardware that needed it.

HSA_OVERRIDE_GFX_VERSION=11.0.0 is recorded as load-bearing: without it a bare
64x64 matmul fails hipErrorInvalidDeviceFunction, because torch's ROCm wheels
carry no gfx1103 code objects.

=== GOAL CORRECTION (user, 2026-08-08) -- handoff section 6 rewritten ===

Prefill runs pipeline-parallel across the APU with TWO workers: the CPU part and
the iGPU part are the two PP stages. Decode: only the iGPU computes. Reshard
between the phases. Prefill is compute-bound so PP ADDS the APU's two compute
pools; decode is bandwidth-bound where two workers on the same DDR5 buy nothing.
The CPU is explicitly NOT a fallback and NOT a memory tier -- it is an active
PP-prefill stage. This supersedes rev1's "CPU as a memory tier".

This reopens the CPU question, because rev1's verdict was scoped too widely: it
priced a CPU stage holding ALL 40 layers. A PP stage holds a layer SHARE k.
New docs/dev/651/cpu_stage_k.py solves for max feasible k:

  ROUTE A, dense-materialize only the CPU stage's layers (no porting):
    Q4_K_M   max k 0.119 ->  4.8 CPU layers
    Q2_K_XL  max k 0.281 -> 11.2 CPU layers
  Both leave the iGPU share far under the 25600-MiB GTT ceiling, so RAM binds
  route A, not the GTT window. Against the balanced split L_cpu = 40/(R+1) and
  ceiling 1 + 1/R, route A is VIABLE on Q2_K_XL for any R >= ~3 (+33% at R=3),
  and on Q4_K_M only for R >= ~8 where the payoff is already down to ~+12%.

  ROUTE B, CPU-native K-quant (llama.cpp ggml-cpu is the existence proof; the
  8840HS is Zen4 so the AVX-512 paths apply): no 3.17x at all, the CPU stage
  costs only its packed share, 5263 MiB spare on Q4_K_M and 14885 on Q2_K_XL.
  k is then bounded by the balance point, not by memory, and Q4_K_M stays in.

  Effort/yield stated rather than silently chosen: A is nearly free and buys a
  cheap measurement of R on real layers, but caps k, forces Q2_K_XL and burns
  RAM the iGPU wants. B is real work but is the correct destination. Use A as
  the probe that measures R, then commit to B if R justifies it.

R IS UNMEASURED. iGPU prefill is 157-172 tok/s; CPU prefill on real layers has
never been measured, so every speedup figure above is conditional.
--pp-layer-ratio must be set proportional to measured stage throughput, not to
core counts, and still sums to backbone depth 40.

The phase flip: decode after the flip is single-worker, so PP-vs-spec should
bind only the prefill phase -- but in this tree it does not, and that is the
crux. server_args.py:16264 is a server-level argument assert evaluated once at
startup, so a server booted pp_size=2 for prefill cannot have speculation at
all, however single-worker its decode is. That needs the assert made phase-aware
or two world shapes in one process -- the sgl-project#297 envelope / Route A question,
whose laptop degenerate case may be trivial precisely because bytes never move.
Check what Route A gives before building flip machinery.

Engineering unknowns mapped, as blockers to verify rather than assumptions: a
mixed-device world is not expressible today (--device is one string,
server_args.py:1623-1626, and GroupCoordinator picks its device from a platform
probe not from server_args.device, parallel_state.py:656-668); the p2p wire is
fine (gloo cpu_group unconditional at :701-717, send/recv already branches on
tensor.is_cpu at :2334-2364); the concrete break is that the receiver allocates
on the SENDER's device type (:238-246, :2395) so a GPU stage receiving from a
CPU stage gets a CPU tensor and nothing inserts the .to(device); zero-copy
stage-to-stage over shared DDR5 is unbuilt and gloo will memcpy;
cpu_graph_runner.py:609-610 asserts pp_size == 1.

Prerequisite sgl-project#1 remains the ROCm port for the iGPU part regardless, since decode
is iGPU-only -- and it is now recovered rather than pending. Staging: iGPU-only
boot -> verify coherence -> spec stable -> measure both stages' prefill floors
-> add the CPU stage as PP=2 -> the phase flip.

Nothing on the laptop was started, stopped or modified. No rig GPU was used.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…route, co-run != solo

Three user corrections (2026-08-08), folded into the handoff and the pricing
script.

1. CHECKPOINT POLICY -- Q4 is the target, NOT Q2. Q2 is "zu dumm". Order of
preference: Q4_K_M primary (it already serves, 21614 MiB, ~3.1 GiB slack); then
a Q3 variant (UD-Q3_K_XL class, NOT on the laptop, would need a download) if a
configuration stops fitting once the CPU stage takes memory; only then anything
smaller. Q2_K_XL stays useful as a cheap DEBUG vehicle -- kernel validation,
spec-fault hunting, fast iteration -- but never as the quality target, and no Q2
number may be quoted as a result. Staging table reworked accordingly: stages a
and b may use Q2 to isolate "does anything work at all", stages c and d are on
Q4_K_M and are the ones that count. The section 1.1 line recommending Q2 as the
staging default is corrected.

2. THE 67-GiB FRAMING IS KILLED AT THE ROOT. That number is the cost of the
fork's ONLY CURRENT CPU path -- dense bf16 materialization at 3.17x, forced
because this tree has no CPU K-quant kernels. It is NOT an inherent cost of
running this model on a CPU: llama.cpp computes directly on quantized blocks and
Q4 stays ~22 GB there. Section 3's headline is rewritten from "the CPU-only
fallback is physically impossible" to "the 67 GiB figure is a property of THIS
FORK, not of CPUs", with an explicit true/false table so the old version cannot
be quoted back. "This model cannot run on CPU in 32 GB" is marked FALSE.

Consequently the route ordering inverts. CPU-native quantized compute is now the
PRIMARY route to price: the CPU stage costs ~k * quant-size, no 3.17x, k bounded
by the balance point rather than by memory, and Q4_K_M stays the target. Three
things make it much smaller than "port the GGUF surface to CPU": the CPU stage
needs only the quant types this checkpoint uses on the layers it will own;
llama.cpp's ggml-cpu is the reference and the 8840HS is Zen4 so AVX-512 applies;
and CPU compute sidesteps the gfx1103 Q6_K bug entirely for its tensors, because
the CPU dequant is the already-validated-correct reference the containment leans
on. Dense materialization is demoted to a stopgap comparator, kept only because
it can buy co-run numbers sooner -- on Q4 it is viable only for R >= ~8 where the
payoff is already down to ~+12%, which is exactly why it is not the destination.

3. SPLIT MEASUREMENT DISCIPLINE. The user's expectation is that the CPU part is
much slower and takes far fewer layers, and that the optimum must be measured --
but critically, SOLO measurements do not predict co-run: under parallel operation
both parts throttle each other. On this APU the coupling is threefold and is the
mechanism, not a caveat: shared TDP/thermal envelope (CPU load steals the iGPU's
power budget and vice versa), shared DDR5 bandwidth, and shared memory-controller
contention. New section 6.0.2 records the plan: (a) solo baselines per stage in
prefill ms per layer-block on real layers, (b) CO-RUN measurement with both
stages active at representative shares -- the co-run numbers, not the solo ones,
feed --pp-layer-ratio -- and (c) a sweep of 2-3 candidate splits around the
co-run-derived optimum, since contention shifts the optimum away from the solo
ratio. Clocks and power are recorded alongside every point. The existing host
smoke (temp_max 57 C, ppt_max 19.14 W) is flagged as a QUIESCENT sample, not a
co-run. And explicitly: if the co-run measurement shows the CPU stage's net
contribution is negligible or negative after throttling, that is a REPORTABLE
VERDICT, not a failure -- the user wants the real optimum, whatever it is.

cpu_stage_k.py updated: route B documented first as primary, checkpoint policy
and the co-run caveat in the module docstring, R relabelled as a parameter to
sweep rather than a measurement, and the checkpoint keys carry TARGET/debug-only
labels so the table cannot be misread. Also made an f-string quote nesting
3.11-safe.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
… clocks or throughput

Measurement correction from the user, overriding the "record clocks and power"
line committed in 41b9e57. Verbatim:

  "es muss nicht der takt mitgeschrieben werden sondern die ms zeiten der karten
   selbst. der takt sagt nichts aus ueber die verteilung die wir spaeter
   brauchen. einzig und allein ms 'runden' zeiten."

Clocks and power are NOT the measurement basis and are not to be recorded as
one. They say nothing about the distribution the split needs, and they are
redundant: the entire throttling interaction -- shared TDP/thermal envelope,
shared DDR5 bandwidth, shared memory-controller contention -- is ALREADY FULLY
CAPTURED in the measured ms times. That redundancy is exactly why co-run ms is
the number that matters, and why solo ms and derived clock models are not
substitutes for it.

This is the rig's standing ms-per-round doctrine applied to the APU. Section
6.0.2 now states it as the only quantity that counts: ms per round per worker
(wall-clock ms for a stage to forward ITS OWN layer share for one pipeline
round), split into compute time vs wait time so an unbalanced split is visible,
runs >= 10 s, warmup discarded, never tok/s.

The optimum condition is written out explicitly, because it is what the whole
measurement is for:

    co-run ms per round (CPU stage) == co-run ms per round (iGPU stage)

--pp-layer-ratio is derived so those two come out equal. Core counts, solo
throughput and FLOP estimates are named as invalid bases.

Section 6.0.3 is retitled and rewritten accordingly: R is a SWEEP PARAMETER for
pricing the routes and at most a derived summary of a finished measurement
(R = ms_cpu_per_layer / ms_igpu_per_layer under co-run), never the measurement
itself, and a solo-derived R is not valid input to a split decision. Its old
wording -- "set proportional to measured stage prefill throughput" -- was the
tok/s framing this correction removes.

Also flagged in both sections: the one existing iGPU number, ~157-172 tok/s, is
in the WRONG UNIT for this purpose and must be restated as ms/round before it
can feed a split decision. And bench_prefill.py, while it supplies the A-vs-A
noise floor, warmup discard, unique prompts and time-bounded runs, measures TTFT
rather than per-stage ms/round -- that per-worker round instrumentation is the
piece that does not exist yet and is the thing to build.

The quiescent host-smoke sample (57 C, 19.14 W) is dropped from the plan; it was
only ever cited as evidence of thermal headroom and has no role now.

cpu_stage_k.py's docstring carries the same correction, so the k/R table cannot
be mistaken for the basis of the split.

Everything else from the previous correction stands: Q4_K_M is the target,
CPU-native quantized compute is the primary route, co-run measurements over
solo, and a sweep of 2-3 candidate splits around the co-run-derived optimum.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…(7 files, verbatim + checksums)

The first recovery pass captured only gguf.py. mtime sweep of the laptop
tree (tgz-extracted 2026-08-07 10:53:59, so later mtimes = real edits)
plus git-blob provenance checks found seven more unversioned files of
laptop-authored work, including the load-bearing early expert-stack
materialization without which Q4_K_M cannot load at all on unified
memory, and the malloc_trim arena release (9,455 MiB returned).

All copies verified byte-identical against the laptop via SHA-256.
Not reconciled; boots run against the laptop tree which carries these.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…ed, no-Q6K containment, disk-park directive

Q4_K_M serving on the 780M was NOT coherent: probe 2/6 -> 1/6, greedy
non-deterministic, first-token logit wobble ~1e-1. Root cause: Q6_K is
broken on gfx1103 in dequantize, MMVQ, ggml_moe_a8 and ggml_moe_a8_vec
(only MMQ clean); the checkpoint carries Q6_K on three MoE expert stacks
that run the defective kernels every forward. Suspend/resume widens the
family to Q5_K until reboot (measured, reboot-reversible).

Containment: requant_no_q6k.py derives a checkpoint with the four Q6_K
tensors requantized to Q8_0 (validated clean type; +250 MiB; error 5e-4
vs removed noise 1e-1). Records the user's disk-park directive for the
phase flip.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…, derived-checkpoint provenance

- audit_all_types: per-kernel x per-type verdicts on real fixtures. NEW:
  IQ2_XS/IQ3_XXS/IQ4_XS MMQ catastrophically broken on gfx1103 (up to
  6.5e4, non-finite, nondet) while their dequant/MMVQ are clean -
  explains the Q2_K_XL boot's hipErrorLaunchFailure. Q2_K/Q3_K clean.
- Derived no-Q6K checkpoint restores full greedy determinism (8/8);
  residual incoherence is deterministic and NOT in the quant kernels
  (moe_align validated, rocBLAS validated, attention backend swap
  changes nothing).
- pins_gfx1103.py: red/green pin harness against KNOWN_BROKEN; already
  caught Q5_K dequant breaking under concurrent CPU memory load -
  the defect family is load-dependent, co-run PP validation must
  include kernel correctness under contention.
- gpu_sanity_guard.py wired into all boot scripts: refuses to serve on
  a poisoned GPU (2 s determinism probe).
- DERIVED_CHECKPOINT_PROVENANCE.md: source/derived SHA-256, exact
  tensor deltas, error bounds, reproduction command.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…ce is the fork's 35B GGUF path

Checkpoint bit-perfect vs upstream; llama.cpp CPU answers cleanly; all
dispatched quant kernels, rocBLAS, moe_align, attention backend
individually exonerated. Suspect: missing/wrong llama.cpp-inverse
transforms in the qwen35moe (35B) adapter map vs the six
coherence-critical ones the 27B adapter needed. Load-dependence of the
gfx11 defect family recorded (Q5_K breaks under CPU memory load).
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
… no-Q6K checkpoint

186 s continuous NEXTN generation, 22 reqs, 2816 tokens, accept 1.87,
zero faults (was: death in 10-40 s on the original file). Draft path
exercises the lm_head (Q6_K in the original) every draft step. Also:
iGPU read bandwidth 79.3 GB/s measured; decode is launch-bound, not
bandwidth-bound.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…cal to the on-card-verified tree

stream_digest_gate.py reproduces d68d807's gate for the qwen35moe arm
it never covered: 63,841 tensors, ordered digest 8aaa592250f43568 equal
between HEAD and dff1ef1 on the rig's Q4_K_XL. Also corrects the
handoff: rig DID content-verify 35B GGUF (4 ledgers, 2026-07-17/18);
no on-card run since. Laptop incoherence localizes device-side.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…device-weight verifier reconstructed

rig_window_probe.sh: turnkey, smoke-tested, tree-pinned, full arb
protocol; runs only on the coordinator go-signal. Honesty bounds
documented: rig Q4_K_XL type census near-identical to laptop Q4_K_M,
lm_head delta already neutralized by the laptop derived-file experiment.
verify_device_weights.py: byte-exact device-resident expert/linear
verification vs GGUFReader (in-process, no server) for the laptop's
return. Laptop blocked: suspended, Wi-Fi, WoL ineffective.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…guard, queued falsifiers

Single-command recovery for the suspended laptop: poisoned-state reboot,
permanent no-suspend (systemd masks + logind lid/idle ignore), sanity
guard, sgl-project#644 pyc recovery, then the ordered falsifier queue
(device-weight bytes -> GDN triton vs torch-naive -> activation
bisection).
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…is 19.58 GiB (BAR1 env), Q4_K_XL cannot fit TP=1

OOM in expert-stack materialization classified as environment capacity:
mem_get_info total 19.58 GiB on the 32 GiB card, weights 21.8 GiB. Zero
coherence signal; discriminator re-queued on Q3_K_XL (16 GiB, fits;
downloading, sha pending). Window script gains a desk-time capacity
gate and MODEL override.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…APU design doc

Arm 2 closes the Q4_K_M-specific suspect on CUDA TP=2 (TP-split delta
stated honestly). DESIGN_651_pp_apu.md: CPU stage as ggml-cpu shim
(route B concretized, prototype in flight), mixed-device world work
items W1-W4 with red-first falsifiers, zero-copy handoff deferred with
arithmetic, disk-park inventory per the user directive, measurement
gate order.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…via minimal ggml-cpu shim

qmatmul_shim.c (150 lines over ggml-cpu MUL_MAT, zero-copy in/out) +
falsifier on real checkpoint slices vs the numpy oracle: Q4_K/Q5_K/
Q6_K/Q8_0 all ~1e-2 rel (same class as the GPU kernels), 3-run
byte-identical, hardened can-fail proofs (targeted block-scale byte
flips; random flips can hide in low-order nibbles and NaN-masking).
Rig-CPU throughput (recipe validation only, laptop re-measures):
dense-eq 4096x2048 Q4_K T=1024: 211.7/30.2/19.3 ms at 1/8/16 threads;
8-expert MoE pass costs only 6-16% over dense-equivalent. Native CPU
coverage includes every type in the checkpoint plus the IQ family.
Integration frictions recorded (threadpool reuse, work-buffer cache,
one-shot activation quant via mul_mat_id, direct type-id match).
llama.cpp clone and .so are gitignored; build_shim.sh reproduces.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…ving group's device

recv_tensor_dict allocated the wire buffer on the SENDER's device type
(metadata) and never moved it -- a CPU prefill stage feeding a GPU
stage delivered CPU tensors. Single post-recv _move_received_tensor
hop; same-device worlds take the identity branch (same object, no
copy). Falsifiers CPU-only via a meta-device receiver group: red with
the hop neutralized, 5/5 green with it; 2-proc gloo roundtrip
byte-identical same-device. Test drives the REAL send/recv path over
real gloo through a stub with bound helpers.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…top-fallback decision point (routing containment preferred)
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…k device string is the real content (is_hip build-probe trap), rank-uniform gloo world, W2b send-side gap
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
… MoE dispatch, not MMQ; sharpens Q2 crash hypothesis
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…lier dl_q2/q3 attempts may have left files) + LAN push path for Q3
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…sume), not system suspend

Same-boot evidence: guard PASS 09:15 under continuous GPU work, FAIL
13:2x after 4 h idle, zero system suspends. power/control=on forced
persistently; falsifier owed (idle 30 min -> guard PASS). Also: laptop
DHCP moved .116->.164 — the unwakeable-suspend episode was a wrong
diagnosis; Q3_K_XL was once on the laptop and was deleted.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…rank device, gloo world, wire staging)

--pp-device-map cpu,cuda (PP-only, tp=1, single node; refuses
rank-gpu-id combination this slice). Per-rank device threaded: parent
hides all device env for a cpu stage; child installs the device
override before dist init; GroupCoordinator._coordinator_device
outranks the is_cuda_alike BUILD probe (the ROCm trap); mixed world
forces a rank-uniform gloo backend and skips pynccl + nccl pre-warm.
W2b: p2p tensors stage through cpu BEFORE metadata split when the wire
is gloo, so metadata declares cpu and the receiver's
_move_received_tensor restores its device.

37 new tests; 763 passed across the affected suites; 10/10
neutralize-red/restore-green falsifier proofs (device-override seam
falsified with the probe forced, since a CUDA-host world test cannot
reach the ROCm trap). Open ends recorded in DESIGN_651_pp_apu.md.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…OCm binding corrupt MoE expert indexing

Bit-for-bit reproduced: int64 ids through fused_moe_gguf give corr
0.5431 vs the fp64 oracle == the incoherent serving dump exactly;
int32 ids give corr 1.0000. Routing itself healthy (ids/weights equal
llama.cpp). Window-2 arm 1: CUDA COHERENT 6/6 greedy-deterministic ->
tree-regression closed, arm 2 moot. Fix staged in the laptop overlay
tree; binding dtype assertions queued for reconciliation. GFXOFF
attribution still open; guard-gated boots prevent leakage. Evidence
and falsifier scripts committed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
…oundary

The ggml MoE kernels index expert weights through int32 ids; the
standalone ROCm binding forwards the tensor unchecked and int64 ids
corrupt every second expert lookup (the laptop incoherence root,
bit-for-bit reproduced). Defensive cast at the function boundary covers
every binding; binding.cpp carries the reconciliation requirement for
proper TORCH_CHECK dtype assertions.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 8, 2026
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.

1 participant