Files
Strata/engine/tests/core/tap_plan_test.cpp
T
Saatvik Viniak bd90b8c526 drafting: a run config's own DFlash2 pack and tap; --draft-tap block-input
A run config may now name its own DFlash2 drafter instead of the pinned
incoai/Flash-Next packs: "draft_model": "<path>", or
"dflash2": {"pack": ..., "family": ..., "tap": "block-input"}.

- supported_model() takes a config-named pack and lifts the model-family
  gate for that config only; pack_ready()/drafter_ready() check that exact
  file (a whole DF2P v1 pack: magic, version, an index whose tensors lie
  inside the file, and its own size + SHA-256 kept in a .ok marker); nothing
  is fetched, tuned, converted or replaced for it.  Decision.pack reaches
  decide()/apply() and an explicit --draft-model in user_args is the same
  assertion.  A config without the keys keeps the pinned flow byte-identical.
- "tap": "block-input" (or "draft_tap") adds the engine's new
  --draft-tap block-input.  The pinned packs read each target layer's
  completed output (mean of the hc streams); the RadixArk/Qwen4-DFlash2
  checkpoint and SGLang's DFLASH taps read the NEXT layer's input, after the
  hyper-connection mix and per-stream norm, before attention (vLLM captures
  it at layer+1).
- engine: core/tap_plan.hpp maps a pack's target ids to the tapped layer for
  both styles (count, per-stage share of a layer split, slot0), with a
  CPU-only test.  Verifier::set_taps(layers, block_input) captures the block
  input from the window's mixed buffer in pre() and keeps the completed-output
  tap unchanged in post(); generate.cpp parses --draft-tap output|block-input,
  refuses block-input on Metal (its window writes output taps), and ends a
  start whose pack cannot be served in block-input style rather than let the
  drafter read a short tap row.  Default unchanged.

Tests: terminal/tests/terminal/test_drafting_custom_pack.py (new),
test_drafting_pin.py now uses a whole DF2P pack, engine tap_plan_test.
Engine built with -DCMAKE_CUDA_ARCHITECTURES=70 -DSTRATA_GEOMETRY=q4_lite
(sm_70, CUDA 12.6).
2026-12-04 00:39:17 -06:00

79 lines
5.2 KiB
C++

// tests/core/tap_plan_test.cpp - the DFlash2 tap styles (header-only, CPU).
//
// 1. a pack's target ids map to the completed output (default) or to the block input of the next layer;
// 2. both styles stop one short of the last layer, so the count the drafter allocated is the count the chain keeps;
// 3. a layer split's stage keeps the taps inside its own range, and its slot0 is the number of taps below it - for both styles,
// including a tap at a stage boundary (the next layer lives on the next stage);
// 4. --draft-tap parses output / block-input / block and refuses anything else.
#include "strata/core/tap_plan.hpp"
#include <cstdio>
#include <vector>
namespace tp = strata::core::tap_plan;
namespace {
int g_fail = 0;
void check(bool ok, const char* what) {
std::printf(" %-84s %s\n", what, ok ? "ok" : "FAIL");
if (!ok) ++g_fail;
}
std::vector<int> ids(std::initializer_list<int> v) { return std::vector<int>(v); }
} // namespace
int main() {
std::printf("tap_plan_test\n");
const std::vector<int> qwen4 = ids({19, 23, 27, 31, 35});
const std::vector<int> flash = ids({5, 15, 25, 35, 45});
tp::Style out = tp::Style::BlockInput, in = tp::Style::BlockInput;
check(tp::parse_style("output", &out) && out == tp::Style::Output, "--draft-tap output");
check(tp::parse_style("block-input", &in) && in == tp::Style::BlockInput, "--draft-tap block-input");
check(tp::parse_style("block", &in) && in == tp::Style::BlockInput, "--draft-tap block (the short word)");
check(tp::parse_style("", &in) && in == tp::Style::Output, "--draft-tap '' (the default)");
check(!tp::parse_style("pooled", &in) && !tp::parse_style("streams_mean", &in), "--draft-tap refuses a word it does not know");
// 1-2: the mapping and the count
check(tp::layer_of(19, tp::Style::Output) == 19 && tp::layer_of(19, tp::Style::BlockInput) == 20, "output keeps the id; block-input reads the next layer");
check(tp::total(qwen4, 40) == 5, "40-layer model: all five Qwen4 taps are served");
check(tp::total(ids({5, 15, 25, 35, 47}), 48) == 4, "a target id at the last layer is not served (47 of 48)");
check(tp::total(ids({0, 46}), 48) == 2, "0 and n_layers - 2 are the edges: both are served on a 48-layer model");
check(tp::total(ids({47}), 48) == 0 && tp::total(ids({46}), 48) == 1, "46 of 48 is served; 47 is not");
// 3: one card keeps them all, in the pack's order
{
const auto all = tp::stage_layers(qwen4, tp::Style::Output, 0, 40, 40);
check(all == qwen4, "one card: output taps at 19,23,27,31,35");
const auto blk = tp::stage_layers(qwen4, tp::Style::BlockInput, 0, 40, 40);
check(blk == ids({20, 24, 28, 32, 36}), "one card: block-input taps at 20,24,28,32,36");
check(tp::slot0(qwen4, tp::Style::BlockInput, 0, 40) == 0, "one card: slot0 is 0");
}
{
// a 3-GPU split 12,28,40: stage 0 [0,12), stage 1 [12,28), stage 2 [28,40)
check(tp::stage_layers(qwen4, tp::Style::Output, 0, 12, 40).empty(), "split: stage 0 keeps no Qwen4 output tap (none below 12)");
check(tp::stage_layers(qwen4, tp::Style::Output, 12, 28, 40) == ids({19, 23, 27}), "split: stage 1 keeps 19,23,27");
check(tp::stage_layers(qwen4, tp::Style::Output, 28, 40, 40) == ids({31, 35}), "split: stage 2 keeps 31,35");
check(tp::slot0(qwen4, tp::Style::Output, 12, 40) == 0 && tp::slot0(qwen4, tp::Style::Output, 28, 40) == 3, "split: output slot0 0 then 3");
check(tp::stage_layers(qwen4, tp::Style::BlockInput, 0, 12, 40).empty(), "split: stage 0 keeps no block-input tap either");
check(tp::stage_layers(qwen4, tp::Style::BlockInput, 12, 28, 40) == ids({20, 24}), "split: block-input stage 1 keeps 20,24 (28 is stage 2's)");
check(tp::stage_layers(qwen4, tp::Style::BlockInput, 28, 40, 40) == ids({28, 32, 36}), "split: block-input stage 2 keeps 28,32,36");
check(tp::slot0(qwen4, tp::Style::BlockInput, 28, 40) == 2, "split: block-input slot0 counts the taps below stage 2");
}
{
// a tap exactly at a boundary: target 11 is layer 11's output (stage 0) but layer 12's block input (stage 1)
check(tp::stage_layers(ids({11}), tp::Style::Output, 0, 12, 40) == ids({11}), "boundary: output 11 is stage 0's");
check(tp::stage_layers(ids({11}), tp::Style::BlockInput, 0, 12, 40).empty(), "boundary: block-input 11 is not stage 0's");
check(tp::stage_layers(ids({11}), tp::Style::BlockInput, 12, 28, 40) == ids({12}), "boundary: block-input 11 is stage 1's layer 12");
check(tp::slot0(ids({11}), tp::Style::BlockInput, 12, 40) == 0 && tp::slot0(ids({11}), tp::Style::Output, 12, 40) == 1,
"boundary: slot0 follows the style");
}
{
// the pinned Flash-Next pack on one card and on a split
check(tp::stage_layers(flash, tp::Style::Output, 0, 48, 48) == flash, "Flash-Next: output taps 5,15,25,35,45 unchanged");
const auto s1 = tp::stage_layers(flash, tp::Style::Output, 12, 28, 48);
check(s1 == ids({15, 25}) && tp::slot0(flash, tp::Style::Output, 12, 48) == 1, "Flash-Next split: stage 1 keeps 15,25 at slot0 1");
}
if (g_fail != 0) std::printf("tap_plan_test: %d FAILED\n", g_fail);
return g_fail == 0 ? 0 : 1;
}