Merge hugypufy/radiance m2xfp: M2XFP4 weights (upstream PR #203)

The M2XFP4 encoding (e2m1 codes, e8m0 per-32 scales, a u8 per-subgroup metadata plane, learned
Givens rotations): libref and libavx kernels, libr4d HIP kernels, the packer and the tests, as on
the branch (8 commits on 9eaf10d, radiance 1.11.0). Taken for Qwen3.8-27B-DFLASH2-PARO-M2XFP4,
the container used for testing and optimisation from now on; merged without conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-23 23:09:18 +02:00
commit d3609e585d
68 files changed
+4847 -193

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
NAME=$1; HIP=$2; SKIP_CONV=$3
IFS=$'\t' read -r _n _h DIR OUT EXTRA <<< "$(grep -P "^$NAME\t" /tmp/night/lanes.tsv)"
LOG=/tmp/night/cpk-$NAME.log
R=/home/zee/orca/workspaces/radiance/m2xfp
if [ "$SKIP_CONV" != "skip" ]; then
echo "$(date -Is) $NAME convert start (hip$HIP)" >> $LOG
cd /home/zee/code/vllm/ggz14/paroquant || exit 1
env FORCE=1 PARO_HIP_VISIBLE=$HIP PARO_NAME=paro_cnv_$NAME FT_RESULTS=$DIR OUT=$OUT $EXTRA ./stage2-m2xfp4.sh convert >> $LOG 2>&1 || { echo "$(date -Is) $NAME CONVERT FAILED" >> $LOG; exit 1; }
fi
echo "$(date -Is) $NAME pack start" >> $LOG
cd $R || exit 1
PATH=$R/build-r4d/bin:$PATH python3 tools/rad_pack_m2xfp4.py /home/zee/models/$OUT --home $R/build-r4d/radiance_home --recipe data/recipes/q38-27b-paro-m2xfp4-df2.recipe --draft /home/zee/models/hf/Qwen3.8-27B-DFlash2 -o /media/zee/ai/radiance/containers/q38-27b-m2xfp4-ft-$NAME.rad >> $LOG 2>&1 || { echo "$(date -Is) $NAME PACK FAILED" >> $LOG; exit 1; }
echo "$(date -Is) $NAME kld start" >> $LOG
cd $R/build-r4d || exit 1
HIP_VISIBLE_DEVICES=$HIP GPU_MAX_ALLOC_PERCENT=100 GPU_MAX_HEAP_SIZE=100 ./bin/radiance --model /media/zee/ai/radiance/containers/q38-27b-m2xfp4-ft-$NAME.rad --radiance-home radiance_home --kld-ref /home/zee/models/rad/kld-bf16 --kld-out /home/zee/models/rad/kld-$NAME-vs-bf16.json >> $LOG 2>&1
echo "$(date -Is) $NAME CHAIN DONE rc=$?" >> $LOG
+13
View File
@@ -0,0 +1,13 @@
import json, sys, time, urllib.request, threading
PORT=int(sys.argv[1])
def one(out):
body=json.dumps({"model":"qwen35","messages":[{"role":"user","content":"Write a detailed essay about the history of computing, covering many decades."}],"max_tokens":256,"temperature":0.7,"stream":False}).encode()
t0=time.time()
r=urllib.request.urlopen(urllib.request.Request(f"http://127.0.0.1:{PORT}/v1/chat/completions",data=body,headers={"Content-Type":"application/json"}),timeout=600).read()
out.append(json.loads(r)["usage"]["completion_tokens"]/(time.time()-t0))
for c in (1,4,8,16):
out=[]; th=[threading.Thread(target=one,args=(out,)) for _ in range(c)]
t0=time.time()
for t in th: t.start()
for t in th: t.join()
print(f"conc={c}: {sum(out):.1f} tok/s aggregate ({time.time()-t0:.0f}s)")
+16
View File
@@ -0,0 +1,16 @@
#!/bin/bash
LOG=/tmp/night/eval.log
cd /home/zee/orca/workspaces/radiance/m2xfp/build-r4d
pkill -f 'bin/radianc[e].*39476' 2>/dev/null; sleep 2
HIP_VISIBLE_DEVICES=2 GPU_MAX_ALLOC_PERCENT=100 GPU_MAX_HEAP_SIZE=100 nohup ./bin/radiance \
--model /media/zee/ai/radiance/containers/q38-27b-m2xfp4.rad \
--radiance-home radiance_home --host 127.0.0.1 --port 39476 \
--max-num-seqs 16 --max-model-len 16384 > /tmp/night/eval-serve.log 2>&1 &
SPID=$!
for i in $(seq 1 180); do curl -sf :39476/health >/dev/null 2>&1 && break; sleep 5; done
curl -sf :39476/health >/dev/null 2>&1 || { echo "$(date -Is) SERVE FAILED (host)" >> $LOG; exit 1; }
echo "$(date -Is) healthy (host, hip2)" >> $LOG
python3 /tmp/night/gsm8k1.py 200 39476 /home/zee/models/rad/gsm8k-m2xfp4-rtn.json >> $LOG 2>&1
python3 /tmp/night/conc.py 39476 >> $LOG 2>&1
kill $SPID 2>/dev/null
echo "$(date -Is) EVAL DONE (hip2 free)" >> $LOG
+30
View File
@@ -0,0 +1,30 @@
import json, re, sys, urllib.request
from concurrent.futures import ThreadPoolExecutor
N=int(sys.argv[1]); PORT=int(sys.argv[2]); OUT=sys.argv[3]
items=json.load(open("/home/zee/models/calib/gsm8k/test.json"))[:N]
PROMPT=("Solve this maths problem step by step. End with exactly: The answer is <number>\n\nProblem: %s")
def norm(a):
a=a.replace(",","").replace("$","").strip()
try: return float(a)
except: return None
def ask(q):
body=json.dumps({"model":"qwen35","messages":[{"role":"user","content":PROMPT%q}],
"max_tokens":700,"temperature":0,"reasoning_effort":"none"}).encode()
r=urllib.request.urlopen(urllib.request.Request(f"http://127.0.0.1:{PORT}/v1/chat/completions",data=body,
headers={"Content-Type":"application/json"}),timeout=600).read()
return json.loads(r)["choices"][0]["message"].get("content") or ""
def extract(t):
m=re.findall(r"answer is\s*\$?([-\d][\d,\.]*)", t, re.I)
if m: return norm(m[-1])
m=re.findall(r"([-\d][\d,\.]*)\s*$", t.strip())
return norm(m[-1]) if m else None
res={}
def one(i):
q=items[i]["q"]; g=norm(items[i]["a"])
try: t=ask(q)
except Exception: res[i]=(False,g,None,"ERR"); return
p=extract(t); res[i]=(p is not None and g is not None and abs(p-g)<1e-6, g, p, t)
with ThreadPoolExecutor(max_workers=8) as ex: list(ex.map(one, range(len(items))))
c=sum(1 for v in res.values() if v[0])
print(f"GSM8K {N}: {c}/{len(res)} = {100*c/len(res):.1f}%")
json.dump({str(k):v[:3] for k,v in res.items()},open(OUT,"w"))
+3
View File
@@ -0,0 +1,3 @@
MAIN 4 /media/zee/ai/paro-out-ft-m2xfp4 Qwen3.8-27B-PARO-M2XFP4-FT
EXACT 1 /media/zee/ai/paro-out-ft-m2xfp4-exact Qwen3.8-27B-PARO-M2XFP4-FT-EXACT M2XFP4_FOLD=exact
SEED1 0 /media/zee/ai/paro-out-ft-m2xfp4-seed1 Qwen3.8-27B-PARO-M2XFP4-FT-SEED1 PARO_SEED=1
1 MAIN 4 /media/zee/ai/paro-out-ft-m2xfp4 Qwen3.8-27B-PARO-M2XFP4-FT
2 EXACT 1 /media/zee/ai/paro-out-ft-m2xfp4-exact Qwen3.8-27B-PARO-M2XFP4-FT-EXACT M2XFP4_FOLD=exact
3 SEED1 0 /media/zee/ai/paro-out-ft-m2xfp4-seed1 Qwen3.8-27B-PARO-M2XFP4-FT-SEED1 PARO_SEED=1
+18
View File
@@ -0,0 +1,18 @@
import json, random, threading, time, urllib.request
PORT=39476; T0=time.time(); rounds=0; faults=0
def fire(i, kill):
try:
body=json.dumps({"model":"qwen35","messages":[{"role":"user","content":f"Explain in detail topic {i}: write a long essay."}],"max_tokens":512,"temperature":0.8}).encode()
req=urllib.request.Request(f"http://127.0.0.1:{PORT}/v1/chat/completions",data=body,headers={"Content-Type":"application/json"})
r=urllib.request.urlopen(req, timeout=2 if kill else 300)
if not kill: r.read()
except Exception:
pass
while time.time()-T0 < 1800:
ths=[threading.Thread(target=fire,args=(i,random.random()<0.5),daemon=True) for i in range(8)]
for t in ths: t.start()
time.sleep(random.uniform(0.5,3)); rounds+=1
try: urllib.request.urlopen(f"http://127.0.0.1:{PORT}/health",timeout=10).read(); ok="ok"
except Exception as e: ok=f"FAULT {e}"; faults+=1
if rounds%20==0: print(f"{time.strftime('%T')} rounds={rounds} health={ok} faults={faults}",flush=True)
print(f"SOAK DONE: {rounds} abort-heavy rounds, {faults} health faults in {(time.time()-T0)/60:.0f} min",flush=True)
+29
View File
@@ -0,0 +1,29 @@
#!/bin/bash
NAME=$1; CTR=paro_s2_$NAME
IFS=$'\t' read -r _name HIP DIR OUT EXTRA <<< "$(grep -P "^$NAME\t" /tmp/night/lanes.tsv)"
LOG=/tmp/night/watch-$NAME.log; : >> $LOG
last=""; since=$(date +%s); up=0
while :; do
n=$(ls $DIR/Qwen3.8-27B-fp16/*.pt 2>/dev/null | wc -l)
lb=$(docker logs $CTR 2>&1 | wc -c)
io=$(docker exec $CTR sh -c 'awk "/^rchar/{print \$2}" /proc/1/io' 2>/dev/null)
fp="$n:$lb:${io:-0}"; now=$(date +%s)
[ "$fp" != "$last" ] && { last=$fp; since=$now; }
cap=$(docker logs $CTR 2>&1 | grep -ac "Capturing original"); opt=$(docker logs $CTR 2>&1 | grep -ac "Optimizing layer")
echo "$(date -Is) $NAME files=$n idle=$(( (now-since)/60 ))m" >> $LOG
[ "$n" -ge 400 ] && { echo "$(date -Is) $NAME COMPLETE" >> $LOG; break; }
docker ps --filter name=$CTR --format '{{.ID}}' | grep -q . && up=1
if [ "$up" = 0 ] && [ $(( now - since )) -lt 420 ]; then sleep 60; continue; fi
if ! docker ps --filter name=$CTR --format '{{.ID}}' | grep -q .; then
echo "$(date -Is) $NAME gone -> relaunch" >> $LOG
else
thresh=15; [ "$cap" = "0" ] && [ "$opt" = "0" ] && thresh=45
if [ $(( (now-since)/60 )) -lt $thresh ]; then sleep 90; continue; fi
docker exec $CTR /src/.pyspy/bin/py-spy dump --pid 1 > /tmp/ft-hang-$NAME-$(date +%H%M%S).txt 2>&1
echo "$(date -Is) $NAME FROZEN -> dump+relaunch" >> $LOG
docker rm -f $CTR >/dev/null 2>&1; sleep 8
fi
cd /home/zee/code/vllm/ggz14/paroquant && env FORCE=1 PARO_HIP_VISIBLE=$HIP FT_EPOCHS=1 PARO_ROT_KERNEL=1 $EXTRA \
PARO_NAME=$CTR FT_RESULTS=$DIR OUT=$OUT setsid nohup ./stage2-m2xfp4.sh finetune >> /tmp/ft-$NAME.log 2>&1 < /dev/null &
sleep 300
done