[LD] FULL Inkling-2-Mini forward runs end-to-end (loop + controllers + MXFP8)
The complete 48-visit Inkling forward now runs on real weights on gfx1150: prelude [0,6) -> core [6,18) x3 passes (bank rollback + cross-pass msgs + gain/forget controllers on passes 1,2) -> coda [18,24) -> final depth mix + unembed + softcap. Produces finite, softcap-bounded logits over vocab 201024 (argmax 120533, logit 19.219) in ~1.9s. - k_mxfp8_gemv / vetta_mxfp8_gemv + ue8m0_to_f32: MXFP8 experts (layers 20..23 are F8_E4M3 + UE8M0/32, NOT NVFP4). y[n] = sum_k e4m3(W[n,k]) * ue8m0(scale[n,k/32]) * x[k], no outer scale. Real layer-20 expert parity 1.45e-4 vs CPU dequant oracle. This is the engine-side per-layer precision composition: layers 0..19 NVFP4, 20..23 MXFP8, dispatched transparently. - packer: ExpertMatrix.mxfp8 flag + load_expert_matrix auto-detects the format (amax tensor presence) + expert_gemv dispatch. - ld::layer: ControllerWeights/load_controllers + apply_controller (RMS pack -> down GEMM -> gain/forget GEMM -> gating); LoopMsgs; layer_forward_swa/full take Option<(&ControllerWeights,&LoopMsgs)> (has_msgs path: 3 separate controlled inputs for SWA, controllers before attn norm / after mlp norm). - is_swa + load_msg_queries (stacked cross-pass queries) + run_layer (SWA/full dispatch, persistent per-layer state across passes) + forward_inkling (the proven schedule from proofs/inkling_loop.lean, incl. bank rollback). - full_inkling_forward_logits test: whole-model forward -> finite bounded logits. NOTE: the forward RUNS and is bounded; bit-parity of the generated token vs the reference engine is the next verification step (no correctness claim yet). Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS; lean proofs (5 files) green; GPU 18/18 + MXFP8 real parity + full forward PASS (--features hip, --ignored).
This commit is contained in:
1 parent
38ac957b26
commit
3c870743fe
5 files changed
+354
-33
No files matched your search
@@ -522,6 +522,54 @@ extern "C" int vetta_nvfp4_gemv(const uint8_t* packed, const uint8_t* scales,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- k_mxfp8_gemv (M=1 decode): MXFP8 experts (layers 20..23) --------------
|
||||
// Exact strata MX8: y[N] = sum_k e4m3fn(W[n,k]) * ue8m0(scale[n,k/32]) * x[k].
|
||||
// W [N,K] F8_E4M3 bytes (full K), scale [N,K/32] U8 UE8M0, NO outer scale.
|
||||
|
||||
__device__ __forceinline__ float ue8m0_to_f32(uint8_t e) {
|
||||
if (e == 255u) return 0.0f;
|
||||
if (e == 0u) return __builtin_bit_cast(float, 0x00400000u); // 2^-127
|
||||
return __builtin_bit_cast(float, (uint32_t)e << 23);
|
||||
}
|
||||
|
||||
__global__ void k_mxfp8_gemv(const uint8_t* __restrict__ weights,
|
||||
const uint8_t* __restrict__ scales,
|
||||
const float* __restrict__ x, float* __restrict__ y,
|
||||
int N, int K) {
|
||||
const int n = blockIdx.x;
|
||||
if (n >= N) return;
|
||||
const int tid = threadIdx.x;
|
||||
const int nt = blockDim.x;
|
||||
const uint8_t* wp = weights + (size_t)n * K;
|
||||
const uint8_t* ws = scales + (size_t)n * (K >> 5);
|
||||
const int nblk = K >> 5;
|
||||
float acc = 0.f;
|
||||
for (int b = tid; b < nblk; b += nt) {
|
||||
const float sc = ue8m0_to_f32(ws[b]);
|
||||
const int k0 = b << 5;
|
||||
const uint8_t* w8 = wp + k0;
|
||||
for (int j = 0; j < 32; ++j) acc += x[k0 + j] * e4m3fn_to_f32(w8[j]) * sc;
|
||||
}
|
||||
__shared__ float red[256];
|
||||
red[tid] = acc;
|
||||
__syncthreads();
|
||||
for (int s = nt / 2; s > 0; s >>= 1) {
|
||||
if (tid < s) red[tid] += red[tid + s];
|
||||
__syncthreads();
|
||||
}
|
||||
if (tid == 0) y[n] = red[0];
|
||||
}
|
||||
|
||||
extern "C" int vetta_mxfp8_gemv(const uint8_t* weights, const uint8_t* scales,
|
||||
const float* x, float* y, int N, int K,
|
||||
vetta_stream_t stream) {
|
||||
if (N <= 0 || K <= 0 || (K % 32) != 0) return 1;
|
||||
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
|
||||
k_mxfp8_gemv<<<N, 256, 0, s>>>(weights, scales, x, y, N, K);
|
||||
HIP_CHECK(hipGetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ---- SiTU activation (exact strata situ_f32, double-softcapped) ------------
|
||||
// gu = [gate(inter); up(inter)] from w13. act[j] = g_act * u_act where
|
||||
// g_act = beta*tanh(g/beta)*sigmoid(g), u_act = lb*tanh(u/lb).
|
||||
|
||||
Reference in new issue
Block a user