Archived
Gemma 4 multiplies each renormalised routing weight by per_expert_scale of the expert it chose. In the conventional vocabulary that is an `embed_lookup` of the [n_expert, 1] table by the ids and a `mul` into the weights -- two launches a MoE layer, a few dozen elements each at decode (--profile-ops: ~0.26 and ~0.22 ms a step across the 30 layers). gemma4k's `expert_scale` is the pair as one kernel, ew = bf16(ew * w_e[id]), with an id outside the table reading 0 as embed_lookup's missed row does: one product rounded once, so the pair's value bit for bit. Like the joins it has no libref row on purpose, so arch/gemma4 falls back to the pair wherever gemma4k is not loaded, and RADIANCE_GEMMA4_FUSE=0 turns it off with them. 30 launches a step the fewer. g4k_emu: device and host rows against the pair over 32 shapes -- top-k 1 and 8, pitched rows, pads and one-past-the-end ids, rows past M untouched -- every element equal. arch_test: a decode step scales in one launch, and in two with it refused. docs/OPS.md: the row and its paragraph; GUIDE: what the switch now covers. Not yet run on the cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.2 KiB
Bash
28 lines
1.2 KiB
Bash
#!/bin/sh
|
|
# tests/g4k_emu/run.sh -- build and run g4k_emu with a clang that is not the build's C++ compiler.
|
|
#
|
|
# A build whose C++ compiler is clang builds these as ordinary targets (tests/CMakeLists.txt). The
|
|
# docker image compiles host C++ with g++, which has no ext_vector_type; its HIP compiler is ROCm's
|
|
# own clang++, and with `-x c++` that compiles the kernel sources as the host code this test needs.
|
|
#
|
|
# run.sh <clang++> <abi dir> <gemma4k dir> <work dir> [sweep cases]
|
|
set -e
|
|
CXX=${1:?usage: run.sh <clang++> <abi dir> <gemma4k dir> <work dir> [sweep cases]}
|
|
ABI=$2; G=$3; B=$4; N=${5:-40}
|
|
HERE=$(cd "$(dirname "$0")" && pwd)
|
|
mkdir -p "$B"
|
|
F="-std=c++20 -O2 -ffp-contract=off -Wno-psabi -I$HERE/emu -I$ABI -I$G"
|
|
for u in attn pick norm escale; do $CXX $F -x c++ -c "$G/g4k_$u.hip" -o "$B/k_$u.o"; done
|
|
$CXX $F -c "$G/g4k_rows.cpp" -o "$B/rows.o"
|
|
$CXX $F -c "$HERE/emu/emu.cpp" -o "$B/emu.o"
|
|
for t in attn pick norm escale; do
|
|
$CXX $F -c "$HERE/test_$t.cpp" -o "$B/test_$t.o"
|
|
$CXX "$B/test_$t.o" "$B/k_attn.o" "$B/k_pick.o" "$B/k_norm.o" "$B/k_escale.o" "$B/rows.o" \
|
|
"$B/emu.o" -o "$B/test_$t"
|
|
done
|
|
"$B/test_attn"
|
|
"$B/test_attn" sweep "$N"
|
|
"$B/test_pick"
|
|
"$B/test_norm"
|
|
"$B/test_escale"
|