diff --git a/arch/common/rad_block_glm_kda.h b/arch/common/rad_block_glm_kda.h index ab8b4e61..feacfde7 100644 --- a/arch/common/rad_block_glm_kda.h +++ b/arch/common/rad_block_glm_kda.h @@ -170,15 +170,20 @@ struct GlmKda { RAD_ARCH_TRY(beta.declare(b, nm, bg, nm.f("blk.%d.attn_beta", layer), heads, 4096, RAD_SHARD_ROW, group, { nm.ckpt("%s.b_proj.weight", prefix) }, input, w.core.beta)); + /* Both low-rank down-projections before either up-projection, in step() as here: the + * four reads of the input then share one ordered point of a recorded pass and the two + * up-projections the next, where forget_b between them cost a third. Declared in the + * issue order because the buffer plan takes lifetimes from this list, and forget_low and + * gate_low must not share bytes while both are live. */ RAD_ARCH_TRY(forget_a.declare( b, nm, bg, nm.f("blk.%d.attn_forget_a", layer), 128, 4096, RAD_SHARD_NONE, group, { nm.ckpt("%s.f_a_proj.weight", prefix) }, input, w.forget_low)); - RAD_ARCH_TRY(forget_b.declare( - b, nm, bg, nm.f("blk.%d.attn_forget_b", layer), width, 128, RAD_SHARD_ROW, group, - { nm.ckpt("%s.f_b_proj.weight", prefix) }, act(w.forget_low), w.core.a)); RAD_ARCH_TRY(gate_a.declare(b, nm, bg, nm.f("blk.%d.attn_gate_a", layer), 128, 4096, RAD_SHARD_NONE, group, { nm.ckpt("%s.g_a_proj.weight", prefix) }, input, w.gate_low)); + RAD_ARCH_TRY(forget_b.declare( + b, nm, bg, nm.f("blk.%d.attn_forget_b", layer), width, 128, RAD_SHARD_ROW, group, + { nm.ckpt("%s.f_b_proj.weight", prefix) }, act(w.forget_low), w.core.a)); RAD_ARCH_TRY(gate_b.declare(b, nm, bg, nm.f("blk.%d.attn_gate_b", layer), width, 128, RAD_SHARD_ROW, group, { nm.ckpt("%s.g_b_proj.weight", prefix) }, act(w.gate_low), w.core.gate)); @@ -205,8 +210,8 @@ struct GlmKda { qkv.step(ctx, input, w.core.qkv, T); beta.step(ctx, input, w.core.beta, T); forget_a.step(ctx, input, w.forget_low, T); - forget_b.step(ctx, act(w.forget_low), w.core.a, T); gate_a.step(ctx, input, w.gate_low, T); + forget_b.step(ctx, act(w.forget_low), w.core.a, T); gate_b.step(ctx, act(w.gate_low), w.core.gate, T); core.step(ctx, batch); output.step(ctx, act(w.core.out), w.out, T); diff --git a/tests/glm5next_test.cpp b/tests/glm5next_test.cpp index 1205eca2..7bd28b4b 100644 --- a/tests/glm5next_test.cpp +++ b/tests/glm5next_test.cpp @@ -1234,6 +1234,11 @@ TEST(glm_kda_projects_local_heads_and_reduces_only_after_the_output_projection) CHECK_EQ(std::count(ops.begin(), ops.end(), "gemm_nt"), 7); CHECK_EQ(std::count(ops.begin(), ops.end(), "silu"), 0); REQUIRE_EQ(ctx.issues.size(), (size_t)11); + // The input's four readers first, then both up-projections. + CHECK_EQ(ctx.issues[2].op, block.forget_a.op); + CHECK_EQ(ctx.issues[3].op, block.gate_a.op); + CHECK_EQ(ctx.issues[4].op, block.forget_b.op); + CHECK_EQ(ctx.issues[5].op, block.gate_b.op); CHECK_EQ(ctx.issues[9].op, block.output.op); CHECK_EQ(ctx.issues[10].op, block.op_ar); CHECK_EQ(ctx.issues[10].opd[0].handle, w.out); @@ -1351,8 +1356,8 @@ TEST(glm53_is_the_pinned_graph_and_steps) { int world; uint64_t graph, steps; }; - const Case cases[] = { { 1, 0xed3fc26c486ea1b5ull, 0x33e5f136f0dbba15ull }, - { 8, 0x712f01858dbe1047ull, 0xf9e357b1333c638full } }; + const Case cases[] = { { 1, 0x906897570034f5f5ull, 0x68ffc03d2b640d51ull }, + { 8, 0x9f39f6f7a04dc4d3ull, 0x3818eedb4ac10d1bull } }; for (const Case& cs : cases) { RadBuilder b; b.kv_block = 4;