@@ -4532,6 +4532,78 @@ struct test_moe_swiglu_down : public test_case {
45324532 }
45334533};
45344534
4535+ // [P1 bf16-stream] Standing coverage for the bf16-native residual-stream segment
4536+ // executor (LLAMA_BF16_STREAM). Builds a residual-stream norm feeding a large-M
4537+ // cuBLAS-bf16 projection (the exact shape ggml_cuda_try_fuse owns): kind 1 = plain
4538+ // rms_norm+mul -> proj (attention / GDN input norm), kind 2 = 0044 gated-DeltaNet
4539+ // output norm silu(z)*rms(x)*w -> proj (ssm_out). Whole-graph so the fusion pass runs;
4540+ // with the env off it validates the f32 path, and with LLAMA_BF16_STREAM=1 it validates
4541+ // the bf16-activation path (the projection reads the bf16 norm output directly). The
4542+ // weight is BF16 so the projection deterministically routes to the cuBLAS-bf16 branch.
4543+ struct test_bf16_stream_segment : public test_case {
4544+ const int kind; // 1 = plain rms+mul, 2 = gated-DeltaNet output norm
4545+ const int64_t n_embd; // K (contraction)
4546+ const int64_t n_out; // N (projection rows)
4547+ const int64_t n_tokens; // M (>= 128 so the executor engages)
4548+
4549+ std::string vars () override {
4550+ return VARS_TO_STR4 (kind, n_embd, n_out, n_tokens);
4551+ }
4552+
4553+ double max_nmse_err () override {
4554+ // bf16 activation rounding on both the default and opt-in paths (the BF16 weight
4555+ // GEMM already rounds the activation); generous but tight enough to catch a bug.
4556+ return 1e-2 ;
4557+ }
4558+
4559+ uint64_t op_flops (ggml_tensor * t) override {
4560+ GGML_UNUSED (t);
4561+ return 2 * n_embd * n_out * n_tokens;
4562+ }
4563+
4564+ test_bf16_stream_segment (int kind = 1 , int64_t n_embd = 4096 , int64_t n_out = 2048 , int64_t n_tokens = 256 )
4565+ : kind(kind), n_embd(n_embd), n_out(n_out), n_tokens(n_tokens) {}
4566+
4567+ ggml_tensor * build_graph (ggml_context * ctx) override {
4568+ const float eps = 1e-5f ;
4569+
4570+ ggml_tensor * x = ggml_new_tensor_2d (ctx, GGML_TYPE_F32 , n_embd, n_tokens);
4571+ ggml_set_name (x, " x" );
4572+ ggml_tensor * w = ggml_new_tensor_1d (ctx, GGML_TYPE_F32 , n_embd);
4573+ ggml_set_name (w, " rms_w" );
4574+ ggml_tensor * proj_w = ggml_new_tensor_2d (ctx, GGML_TYPE_BF16 , n_embd, n_out);
4575+ ggml_set_name (proj_w, " proj_w" );
4576+
4577+ ggml_tensor * rms = ggml_rms_norm (ctx, x, eps);
4578+ ggml_set_name (rms, " rms" );
4579+ ggml_tensor * mul = ggml_mul (ctx, rms, w);
4580+ ggml_set_name (mul, " rms_mul" );
4581+
4582+ ggml_tensor * norm_out = mul;
4583+ if (kind == 2 ) {
4584+ ggml_tensor * z = ggml_new_tensor_2d (ctx, GGML_TYPE_F32 , n_embd, n_tokens);
4585+ ggml_set_name (z, " gate_z" );
4586+ ggml_tensor * silu = ggml_silu (ctx, z);
4587+ ggml_set_name (silu, " silu" );
4588+ // silu as src0 so the topological order is {SILU, RMS_NORM, MUL, MUL},
4589+ // matching the fusion-pass pattern (and the real q36 gated-output norm).
4590+ norm_out = ggml_mul (ctx, silu, mul);
4591+ ggml_set_name (norm_out, " gate_mul" );
4592+ }
4593+
4594+ ggml_tensor * out = ggml_mul_mat (ctx, proj_w, norm_out);
4595+ ggml_set_name (out, " proj" );
4596+ return out;
4597+ }
4598+
4599+ bool run_whole_graph () override { return true ; }
4600+
4601+ std::string op_desc (ggml_tensor * t) override {
4602+ GGML_UNUSED (t);
4603+ return " BF16_STREAM_SEGMENT" ;
4604+ }
4605+ };
4606+
45354607// MoE down projection -> router-weight multiply -> rank-ordered expert add.
45364608struct test_moe_weighted_combine : public test_case {
45374609 const ggml_type type_a;
@@ -9043,6 +9115,13 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
90439115 test_cases.emplace_back (new test_moe_swiglu_down (GGML_TYPE_NVFP4 , 128 , 8 , 768 , n, 2048 ));
90449116 }
90459117
9118+ // [P1 bf16-stream] bf16-native residual-stream segment executor coverage. Small-M
9119+ // (bails, f32 path) + large-M (engages under LLAMA_BF16_STREAM=1) for both norm kinds.
9120+ for (int kind : {1 , 2 }) {
9121+ test_cases.emplace_back (new test_bf16_stream_segment (kind, 4096 , 2048 , 64 ));
9122+ test_cases.emplace_back (new test_bf16_stream_segment (kind, 4096 , 2048 , 256 ));
9123+ }
9124+
90469125 // [paged Phase 7] MoE down projection -> router-weight multiply -> rank-ordered
90479126 // expert add gate for the weighted-combine fusion candidate.
90489127 test_cases.emplace_back (new test_moe_weighted_combine (GGML_TYPE_F32 , 8 , 2 , 32 , 8 , 64 ));
0 commit comments