| 26 | } |
| 27 | |
| 28 | int main(int argc, char ** argv) { |
| 29 | if (argc < 3) { |
| 30 | fprintf(stderr, |
| 31 | "Usage: %s <ref_dir> <model_path> [n_threads]\n" |
| 32 | "\n" |
| 33 | " ref_dir : directory with Python-dumped fenc tensors\n" |
| 34 | " (from dump_fenc_from_package.py)\n" |
| 35 | " model_path : path to sam3_f32.ggml weights\n" |
| 36 | " n_threads : optional (default 1)\n", |
| 37 | argv[0]); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | const std::string ref_dir = argv[1]; |
| 42 | const std::string model_path = argv[2]; |
| 43 | const int n_threads = (argc > 3) ? std::atoi(argv[3]) : 1; |
| 44 | |
| 45 | const std::string cpp_dir = ref_dir + "/cpp_out_fenc"; |
| 46 | if (!ensure_dir(cpp_dir)) { |
| 47 | fprintf(stderr, "Failed to create output dir %s\n", cpp_dir.c_str()); |
| 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | // ── Load model ── |
| 52 | sam3_params params; |
| 53 | params.model_path = model_path; |
| 54 | params.n_threads = n_threads; |
| 55 | params.use_gpu = false; |
| 56 | |
| 57 | fprintf(stderr, "Loading model from %s...\n", model_path.c_str()); |
| 58 | auto model = sam3_load_model(params); |
| 59 | if (!model) { |
| 60 | fprintf(stderr, "Failed to load model\n"); |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | // ── Run fenc-only test ── |
| 65 | fprintf(stderr, "\nRunning fusion encoder with Python-dumped inputs from %s\n", ref_dir.c_str()); |
| 66 | if (!sam3_test_fenc_only(*model, ref_dir, cpp_dir, n_threads)) { |
| 67 | fprintf(stderr, "sam3_test_fenc_only failed\n"); |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | // ── Compare per-layer outputs ── |
| 72 | fprintf(stderr, "\n══════════════════════════════════════════════════════════════\n"); |
| 73 | fprintf(stderr, " Fusion Encoder: Python vs C++ Comparison\n"); |
| 74 | fprintf(stderr, "══════════════════════════════════════════════════════════════\n\n"); |
| 75 | |
| 76 | // First verify inputs are loaded correctly |
| 77 | { |
| 78 | auto ref_img = load_ref_f32(ref_dir + "/fenc_input_tgt"); |
| 79 | auto cpp_img = load_ref_f32(cpp_dir + "/fenc_img_input"); |
| 80 | if (!ref_img.data.empty() && !cpp_img.data.empty() && |
| 81 | ref_img.numel() == cpp_img.numel()) { |
| 82 | auto r = compare_tensors(cpp_img.data.data(), ref_img.data.data(), |
| 83 | ref_img.numel(), 1e-6f); |
| 84 | fprintf(stderr, " Input check: img_feats max_diff=%.2e (should be ~0)\n", |
| 85 | r.max_diff); |
nothing calls this directly
no test coverage detected