From 6476f8b197324df0ce879ab3139af9eb32dbcf13 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Fri, 13 Nov 2026 02:02:15 -0400 Subject: [PATCH] vision tower test: the join's two row counts, pinned on a real pack with no oracle needed `npu/vision_plan.h` defines `PiecePlan::rows` as "grid_h/4 * grid_w/4" -- the rows the text model receives -- and `npu/vision_tower.h:44` says the optional `tower` out-parameter receives "step 5's output, (gh/2 x gw/2, hidden): the tower *before* the merger". Two different quantities, one merger apart, and until now the only place they were forced to agree was `minicpm_image_probe.cpp:252,260` -- at run time, on a 21 GB text model. This adds that to the tower's own test, gated on `ONEBIT_MINICPM_PACK` alone: out.size() / geometry().out_hidden == plan.source.rows one text row per placeholder tower.size() == (gh/2) * (gw/2) * hidden the tower before the merger Measured on the real `MiniCPM-V-4.7-35B-A3B-NPU2` vision component: **17 checks, 0 failed**. Without the pack the arm prints "did not run" and the suite reports 15 checks, so CI -- which has no pack -- is unaffected. Three things worth knowing, all of which cost me a failed attempt first: 1. **The plan is built at four patches per side, not at the pack's 980-pixel image.** `scale_resolution` must be at least `4 * patch`, and a larger request is *resized* by `best_resize()`, which silently changes the grid the plan describes. 4 * patch is the smallest geometry the planner leaves alone, and this arm is about the row counts rather than about running a 70 x 70 grid on four cores. 2. **The first version of this arm compared the plan against `tower`, and was wrong by exactly the merger's second halving** -- `tower` is the pre-merger buffer. That is the mistake the arm now pins against. 3. `const vis::Pack pk(std::string(pdir));` is a *function declaration* (most vexing parse); it needs a named string. The reference arm is unchanged: it still needs `ONEBIT_MINICPM_ORACLE` for its pixel/tower/out goldens, and this one deliberately needs nothing but the pack a lane already has. --- tests/npu_vision_tower_test.cpp | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/npu_vision_tower_test.cpp b/tests/npu_vision_tower_test.cpp index 139295ff0..db8d1591a 100644 --- a/tests/npu_vision_tower_test.cpp +++ b/tests/npu_vision_tower_test.cpp @@ -27,6 +27,7 @@ // ONEBIT_VISION_KEEP_FIXTURE=1 leaves the container and its config.json in the working directory (that is how the // goldens were produced). ONEBIT_MINICPM_PACK= with ONEBIT_MINICPM_ORACLE= compares a published pack's output with a reference run of the same input. +#include "../npu/vision_plan.h" // engine#2324: text-side rows vs the tower's own row count #include "../npu/vision_tower.h" #include @@ -312,6 +313,44 @@ int main() { std::remove(kContainer); std::remove(kConfig); } + // engine#2324: the join's invariant on a REAL vision pack, with no oracle needed -- one text-side row per + // placeholder, and the tower's own row count is the merger's second halving away from it. The reference arm below + // needs ONEBIT_MINICPM_ORACLE (pixels.f32/tower.f32/out.f32/grid.txt); this one needs only the pack, which is the + // thing a lane actually has. What it pins is the arithmetic that only minicpm_image_probe.cpp checked, and only on a + // 21 GB model: `PiecePlan::rows` is "grid_h/4 * grid_w/4", so `out.size()/out_hidden` must equal it, and the tower + // before the merger must be "grid_h/2 * grid_w/2" rows. + { + const char* pdir = std::getenv("ONEBIT_MINICPM_PACK"); + if (pdir && *pdir) { + try { + // `Pack(pack_dir)` reads config.json and the container it names. The plan is built at FOUR PATCHES PER SIDE + // over the pack's own patch size, not at the pack's 980-pixel image: 4 * patch is the smallest geometry the + // planner leaves alone (scale_resolution must be at least 4 * patch, and a bigger request is resized), and + // this arm is about the two row counts, not about running a 70 x 70 grid on four cores. + const std::string pdir_s = pdir; // `Pack pk(std::string(pdir))` is a function declaration + const vis::Pack pk(pdir_s); + const vis::Geometry& g = pk.geometry(); + const int side = 4 * g.patch; + const vis::ImagePlan plan = vis::plan_image(side, side, /*max_slice_nums=*/1, + /*scale_resolution=*/side, /*patch=*/g.patch); + const vis::PiecePlan& src = plan.source; + const int gh = src.grid_h, gw = src.grid_w; + std::vector px(size_t(3) * size_t(gh * g.patch) * size_t(gw * g.patch)); + for (size_t k = 0; k < px.size(); ++k) px[k] = float(int(k % 251) - 125) / 128.0f; + std::vector tower; + const std::vector out = vis::tower_forward(pk, px.data(), gh, gw, &tower); + const size_t text_rows = g.out_hidden ? out.size() / size_t(g.out_hidden) : 0; + check(int(text_rows) == src.rows, + "join (real pack): the merger hands the text model exactly PiecePlan::rows rows"); + check(tower.size() == size_t(gh / 2) * size_t(gw / 2) * size_t(g.hidden), + "join (real pack): the tower before the merger is grid/2 x grid/2 rows"); + } catch (const std::exception& e) { + check(false, std::string("join (real pack): opened and ran (") + e.what() + ")"); + } + } else { + std::printf(" (ONEBIT_MINICPM_PACK not set: the join arm did not run)\n"); + } + } const char* pack = std::getenv("ONEBIT_MINICPM_PACK"); const char* oracle = std::getenv("ONEBIT_MINICPM_ORACLE"); if (pack && *pack && oracle && *oracle) test_published(pack, oracle);