Skip to content

serve: the placement report covers every graph, and --strict-device reads it - #473

Merged
bong-water-water-bong merged 4 commits into
mainfrom
1bit/placement-report-all-graphs
Oct 20, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
1bit/placement-report-all-graphs

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Census gap G2 (pi goal mvgdshw8).

  • --placement-report covered only the warmup graph. It now records every graph and keeps the worst one.
  • --strict-device never received the report, so it read nothing and started normally. It now gets the report and refuses a model with nodes off HRX.

Evidence (strixhalo, from the goal): unit test (tests/hrx_placement_test.cpp) green; device runs: LFM2 --parallel 4 reports 20 of 548 nodes off HRX (MUL_MAT x 20, worst of 2 graphs); ZAYA --parallel 4 reports 43 of 6449 (worst of 6 graphs). Those are now strict-mode refusals, tracked as gaps G3/G4.

🤖 Generated with Claude Code

bcloud and others added 2 commits October 20, 2026 06:45
--placement-report passed GGML_HRX_REPORT=1, and the backend's 1 is the
first graph only, so serve printed a clean report for a model that leaves
nodes on the CPU in later graphs: the 20 Oct census found LFM2 --parallel 4
(20 nodes, 5 splits) and ZAYA1-8B (1-3 nodes) reading "all nodes on HRX".

Ask for every graph (2), keep the worst one instead of the last, and print
serve's line again whenever a graph is worse than every graph before it,
with the graph count. --strict-device reads the same worst graph. Without
--placement-report serve keeps 1, so no log volume is added by default.

tests/hrx_placement_test.cpp covers a clean warmup followed by a par4 graph
and a later clean graph.

Co-Authored-By: Claude Opus 5 <[email protected]>
--strict-device only passed GGML_HRX_STRICT=1 to the backend. It did not pass GGML_HRX_REPORT=2 and it
did not add the -lv 4 that lets llama-server's log level carry the placement report through, so the graph
that would have been refused was never reported and serve fell through to "the backend printed no
placement line" while starting normally. Both flags are now treated the same way: GGML_HRX_REPORT=2 and
-lv 4 whenever either is set, so the refusal reads the same worst graph that --placement-report prints.

Found on device: `1bit serve ... --strict-device --parallel 4` (LFM2-1.2B) answered requests instead of
refusing, with that "no placement line" message in its log.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 81b6753)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Placement Report Logic

The change modifies how placement reports are handled by updating the logic to track the worst graph across multiple reports instead of just the first one. This is important for correctness when using --placement-report and --strict-device flags, as it ensures that the most problematic graph (with the highest number of nodes off HRX) is considered for reporting and strict device checks. The implementation correctly updates the placement_worst atomic variable and ensures that the worst report is printed and used for strict device checks.

std::atomic<long> placement_worst{-1};
ProgressWatch watch(o.watchdog);
ServeMetrics metrics(device);   // GET /metrics (app/serve_metrics.h)
Lifecycle lifecycle(id);
std::mutex wedged_mu;
std::string wedged;   // set by the watchdog: why the backend is taken down
auto backend_line = [&metrics, &placement_worst, &wedged_mu, &wedged](const std::string& line) {
    metrics.backend_line(line);
    if (device_lost_line(line)) {
        std::lock_guard<std::mutex> lock(wedged_mu);
        if (wedged.empty()) wedged = "the backend lost its GPU: " + line.substr(0, 200);
    }
    const auto report = metrics.placement();
    // engine #390: the backend's placement report becomes serve's own line at load.
    if (!report) return;
    const long off = report->cpu_fallback_total.value_or(0);
    if (off > placement_worst.load() && placement_worst.exchange(off) < off)
        std::fprintf(stderr, "1bit serve: HRX placement: %s\n", placement_summary(*report).c_str());
};
Backend Line Handling

The backend line handling logic in serve_child has been updated to correctly process placement reports. The previous implementation only printed the placement report once, but now it correctly tracks and prints the worst graph's report whenever a new graph has more nodes off HRX than previously seen. This ensures that the most problematic graph is always reported, which is essential for the functionality of --placement-report and --strict-device.

auto backend_line = [&metrics, &placement_worst, &wedged_mu, &wedged](const std::string& line) {
    metrics.backend_line(line);
    if (device_lost_line(line)) {
        std::lock_guard<std::mutex> lock(wedged_mu);
        if (wedged.empty()) wedged = "the backend lost its GPU: " + line.substr(0, 200);
    }
    const auto report = metrics.placement();
    // engine #390: the backend's placement report becomes serve's own line at load.
    if (!report) return;
    const long off = report->cpu_fallback_total.value_or(0);
    if (off > placement_worst.load() && placement_worst.exchange(off) < off)
        std::fprintf(stderr, "1bit serve: HRX placement: %s\n", placement_summary(*report).c_str());
};
Placement Line Tracking

The BackendLogFacts struct now tracks placement_lines to count how many placement reports have been seen. This is crucial for determining the worst graph when multiple reports are present. The logic in feed method correctly updates cpu_fallback_total, cpu_fallback_ops, placement_nodes, and placement_splits only when a new, worse report is encountered, ensuring that the worst graph's data is retained.

size_t              placement_lines = 0;   // placement reports seen; the worst one is kept

void feed(const std::string& line) {
    // every backend line passes here: plain substring tests first, a regex only on a hit
    if (line.find("HRX graph program cache over its limit") != std::string::npos) {
        static const std::regex flush(R"(flush (\d+))");
        std::smatch m;
        const uint64_t n = std::regex_search(line, m, flush) ? std::stoull(m[1]) : 0;
        program_cache_flushes = std::max(program_cache_flushes + 1, n);
        return;
    }
    const size_t at = fallback_at(line);
    if (at == std::string::npos) return;
    static const std::regex op_count(R"(\b([A-Z][A-Z0-9_]{2,})\s*(?:=|:|x)\s*(\d+))");
    static const std::regex number(R"((\d+))");
    const std::string rest = line.substr(at);
    std::map<std::string, long> ops;
    long sum = 0;
    for (auto it = std::sregex_iterator(rest.begin(), rest.end(), op_count); it != std::sregex_iterator(); ++it) {
        ops[(*it)[1]] += std::stol((*it)[2]);
        sum += std::stol((*it)[2]);
    }
    std::smatch m;
    // "34 off HRX": the placement report states its own count, so the first number after the
    // phrase (which may be the split count) is not it.
    static const std::regex off_count(R"((\d+) off HRX\b)");
    const bool stated = std::regex_search(line, m, off_count);
    if (stated) {
        const long stated_off = std::stol(m[1]);
        ++placement_lines;
        // the WORST graph is what serve reports: with GGML_HRX_REPORT=2 the backend reports every graph,
        // and the warmup graph that reports first is the one that looks clean while a --parallel
        // multi-sequence graph leaves 20 nodes on the CPU (census 2026-10-20, finding 1).
        if (!cpu_fallback_total || stated_off > *cpu_fallback_total) {
            cpu_fallback_total = stated_off;
            cpu_fallback_ops = ops;   // empty for a clean graph ("none")
            static const std::regex nodes_count(R"((\d+) nodes\b)");
            static const std::regex splits_count(R"((\d+) graph splits\b)");
            std::smatch sized;
            if (std::regex_search(line, sized, nodes_count)) placement_nodes = std::stol(sized[1]);
            if (std::regex_search(line, sized, splits_count)) placement_splits = std::stol(sized[1]);
        }
        return;
    }
Placement Summary Logic

The placement_summary function has been updated to include information about the number of graphs considered when reporting placement. When more than one graph is reported, it appends ", worst of N graphs" to the summary, which is essential for providing accurate information to users when using --placement-report.

inline std::string placement_summary(const BackendLogFacts& f) {
    const std::string nodes  = f.placement_nodes ? std::to_string(*f.placement_nodes) : "?";
    const std::string splits = f.placement_splits ? std::to_string(*f.placement_splits) : "?";
    const long        off    = f.cpu_fallback_total.value_or(0);
    // more than one graph reported: the numbers are the worst of them (GGML_HRX_REPORT=2)
    const std::string which = f.placement_lines > 1 ? ", worst of " + std::to_string(f.placement_lines) + " graphs" : "";
    if (off == 0) return "all " + nodes + " nodes on HRX, " + splits + " graph splits" + which;
    return std::to_string(off) + " of " + nodes + " nodes off HRX (" + off_ops_detail(f) + "), " + splits +
           " graph splits" + which;
}

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) October 20, 2026 16:40
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 8c9a15a

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 81b6753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant