test_gh108_config_benchmark.cpp

tests/model/test_gh108_config_benchmark.cpp

@file test_gh108_config_benchmark.cpp @brief Decode-configuration benchmarks: the gh#108 quant/config comparison and the gh#153 four-arm MTP throughput measurement.

Owners: @tvanfossen

measure_cold_prefill

PrefillPoint gh153::measure_cold_prefill(const BenchModel &m, entropic::config::BundledModels &registry, const std::string &prompt)

Measure one cold prefill at one residency level.

tests/model/test_gh108_config_benchmark.cpp:1430

Show on the map →

Called by none

Tested by

1 testsrun_prefill_residency_bench

Calls REQUIRE, build_orchestrator, config_yaml, describe_run, dir

Checks

  • REQUIRE(result.error_code == ENTROPIC_OK);
  • REQUIRE_FALSE(records.empty());
  • REQUIRE(p.prefill_tokens > 0);

Result: absent

Verifies

requirementlinkedpath to the implementer
REQ-INFER-019tagmeasure_cold_prefill → build_orchestrator → initialize → ensure_vram_budget
Source · 59 lines
PrefillPoint measure_cold_prefill(const BenchModel& m,
                                  entropic::config::BundledModels& registry,
                                  const std::string& prompt) {
    PrefillPoint p;
    p.gpu_layers = m.gpu_layers;
    p.n_ubatch = m.n_ubatch;
    BenchProject project(m.label + "_" + m.gpu_layers);
    auto orch = build_orchestrator(config_yaml(m, project.dir()), registry);
    const RunInfo run = describe_run(m, registry, *orch);
    p.resolved_layers = run.resident_layers;
    // v2.14.6: what the engine resolved, not what was asked for — `auto` can
    // move experts host-side on its own.
    p.cpu_moe_layers = run.cpu_moe_layers;

    entropic::Message u;
    u.role = "user";
    u.content = prompt;
    entropic::GenerationParams params;
    params.temperature = 0.0f;
    params.max_tokens = 1;  // prefill plus one token: this IS the TTFT call

    const auto t0 = std::chrono::steady_clock::now();
    const auto result = orch->generate({u}, params, "plain");
    const auto t1 = std::chrono::steady_clock::now();
    p.ttft_ms = std::chrono::duration<double, std::milli>(t1 - t0).count();

    INFO("generation error: " << result.error_message);
    REQUIRE(result.error_code == ENTROPIC_OK);
    const auto records = orch->generation_records();
    REQUIRE_FALSE(records.empty());
    p.prefill_tokens = records.back().prefill_tokens;
    // gh#194 shipped in v2.13.2. If this is 0 the figure below is
    // meaningless, and silently reporting it would be worse than failing.
    REQUIRE(p.prefill_tokens > 0);
    if (p.ttft_ms > 0.0) {
        p.prefill_tok_s =
            static_cast<double>(p.prefill_tokens) / p.ttft_ms * 1000.0;
    }

    // Decode, on the SAME context the cold pass just filled — so it is warm
    // by construction and measures the bandwidth-bound half. Without this the
    // prefill figures alone would recommend trading layers for batch, and
    // decode is exactly what that trade should cost: it streams every weight
    // per token and gains nothing from a larger batch.
    entropic::GenerationParams decode = params;
    decode.max_tokens = 128;
    const auto d0 = std::chrono::steady_clock::now();
    const auto dres = orch->generate({u}, decode, "plain");
    const auto d1 = std::chrono::steady_clock::now();
    if (dres.error_code == ENTROPIC_OK && dres.token_count > 0) {
        const double ms =
            std::chrono::duration<double, std::milli>(d1 - d0).count();
        if (ms > 0.0) {
            p.decode_tok_s =
                static_cast<double>(dres.token_count) / ms * 1000.0;
        }
    }
    return p;
}
Activity · 36 steps
lines 1433–1433PrefillPoint p;lines 1434–1434p.gpu_layers = m.gpu_layers;lines 1435–1435p.n_ubatch = m.n_ubatch;lines 1436–1436BenchProject project(m.label + "_" + m.gpu_layers);lines 1437–1437auto orch = build_orchestrator(config_yaml(m, project.dir()), registry);lines 1438–1438const RunInfo run = describe_run(m, registry, *orch);lines 1439–1439p.resolved_layers = run.resident_layers;lines 1442–1442p.cpu_moe_layers = run.cpu_moe_layers;lines 1444–1444entropic::Message u;lines 1445–1445u.role = "user";lines 1446–1446u.content = prompt;lines 1447–1447entropic::GenerationParams params;lines 1448–1448params.temperature = 0.0f;lines 1449–1449params.max_tokens = 1;lines 1451–1451const auto t0 = std::chrono::steady_clock::now();lines 1452–1452const auto result = orch->generate({u}, params, "plain");lines 1453–1453const auto t1 = std::chrono::steady_clock::now();lines 1454–1454p.ttft_ms = std::chrono::duration<double, std::milli>(t1 - t0).count();lines 1456–1456INFO("generation error: " << result.error_message);lines 1457–1457REQUIRE(result.error_code == ENTROPIC_OK);lines 1458–1458const auto records = orch->generation_records();lines 1459–1459REQUIRE_FALSE(records.empty());lines 1460–1460p.prefill_tokens = records.back().prefill_tokens;lines 1463–1463REQUIRE(p.prefill_tokens > 0);lines 1464–1464◇ if (p.ttft_ms > 0.0)lines 1465–1466p.prefill_tok_s = static_cast<double>(p.prefill_tokens) / p.ttft_ms * 1000.0;lines 1474–1474entropic::GenerationParams decode = params;lines 1475–1475decode.max_tokens = 128;lines 1476–1476const auto d0 = std::chrono::steady_clock::now();lines 1477–1477const auto dres = orch->generate({u}, decode, "plain");lines 1478–1478const auto d1 = std::chrono::steady_clock::now();lines 1479–1479◇ if (dres.error_code == ENTROPIC_OK && dres.token_count > 0)lines 1480–1481const double ms = std::chrono::duration<double, std::milli>(d1 - d0).count();lines 1482–1482◇ if (ms > 0.0)lines 1483–1484p.decode_tok_s = static_cast<double>(dres.token_count) / ms * 1000.0;lines 1487–1487return p;

run_prefill_residency_bench

void gh153::run_prefill_residency_bench(const BenchModel &base, const std::vector< std::pair< std::string, int > > &levels)

Sweep residency and report what cold prefill costs at each level.

tests/model/test_gh108_config_benchmark.cpp:1505

Show on the map →

Called by TEST_CASE

Calls REQUIRE, get, large_prompt, load_registry, measure_cold_prefill, resolve, skip_if_absent

Checks

  • REQUIRE(load_registry(registry));
  • REQUIRE(registry.get(base.target_key) != nullptr);

Result: absent

Verifies

requirementlinkedpath to the implementer
REQ-INFER-019tagrun_prefill_residency_bench → measure_cold_prefill → build_orchestrator → initialize → ensure_vram_budget
Source · 37 lines
void run_prefill_residency_bench(
    const BenchModel& base,
    const std::vector<std::pair<std::string, int>>& levels) {
    entropic::config::BundledModels registry;
    REQUIRE(load_registry(registry));
    REQUIRE(registry.get(base.target_key) != nullptr);
    skip_if_absent(base.target_key, registry.resolve(base.target_key));

    const std::string prompt = large_prompt(6000);
    std::vector<PrefillPoint> points;
    for (const auto& [layers, ubatch] : levels) {
        BenchModel m = base;
        m.gpu_layers = layers;
        m.n_ubatch = ubatch;
        points.push_back(measure_cold_prefill(m, registry, prompt));
    }

    std::printf("\ngh193 COLD PREFILL vs RESIDENCY — %s\n", base.label.c_str());
    std::printf("  one cold pass per level, max_tokens=1, prompt ~%d tokens\n",
                points.empty() ? 0 : points.front().prefill_tokens);
    std::printf("  %-10s %-9s %-9s %-11s %-14s %s\n",
                "gpu_layers", "resolved", "n_ubatch", "TTFT ms",
                "prefill tok/s", "decode tok/s");
    for (const auto& p : points) {
        std::printf("  %-10s %-9d %-9d %-11.1f %-14.1f %.1f\n",
                    p.gpu_layers.c_str(), p.resolved_layers, p.n_ubatch,
                    p.ttft_ms, p.prefill_tok_s, p.decode_tok_s);
    }
    if (points.size() >= 2) {
        const double best = points.front().prefill_tok_s;
        const double worst = points.back().prefill_tok_s;
        if (worst > 0.0) {
            std::printf("  most-resident is %.2fx the least-resident on "
                        "prefill\n", best / worst);
        }
    }
}
Activity · 21 steps
lines 1508–1508entropic::config::BundledModels registry;lines 1509–1509REQUIRE(load_registry(registry));lines 1510–1510REQUIRE(registry.get(base.target_key) != nullptr);lines 1511–1511skip_if_absent(base.target_key, registry.resolve(base.target_key));lines 1513–1513const std::string prompt = large_prompt(6000);lines 1514–1514std::vector<PrefillPoint> points;lines 1515–1515◇ for (const auto& [layers, ubatch] : levels)lines 1516–1516BenchModel m = base;lines 1517–1517m.gpu_layers = layers;lines 1518–1518m.n_ubatch = ubatch;lines 1519–1519points.push_back(measure_cold_prefill(m, registry, prompt));lines 1522–1522std::printf("\ngh193 COLD PREFILL vs RESIDENCY — %s\n", base.label.c_str());lines 1523–1524std::printf(" one cold pass per level, max_tokens=1, prompt ~%d tokens\n", points.empty() ? 0 : points.front().prefill_tokens);lines 1525–1527std::printf(" %-10s %-9s %-9s %-11s %-14s %s\n", "gpu_layers", "resolved", "n_ubatch", "TTFT ms", "prefill tok/s", "decode tok/s");lines 1528–1528◇ for (const auto& p : points)lines 1529–1531std::printf(" %-10s %-9d %-9d %-11.1f %-14.1f %.1f\n", p.gpu_layers.c_str(), p.resolved_layers, p.n_ubatch, p.ttft_ms, p.prefill_tok_s, p.decode_tok_s);lines 1533–1533◇ if (points.size() >= 2)lines 1534–1534const double best = points.front().prefill_tok_s;lines 1535–1535const double worst = points.back().prefill_tok_s;lines 1536–1536◇ if (worst > 0.0)lines 1537–1538std::printf(" most-resident is %.2fx the least-resident on " "prefill\n", best / worst);