MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / main

Function main

tests/test_phase5.cpp:109–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109int main(int argc, char ** argv) {
110 if (argc < 4) {
111 fprintf(stderr, "Usage: %s <ref_dir> <model_path> <image_path>\n", argv[0]);
112 return 1;
113 }
114
115 const std::string ref_dir = argv[1];
116 const std::string model_path = argv[2];
117 const std::string image_path = argv[3];
118 const std::string cpp_dir = ref_dir + "/cpp_out_phase5";
119 if (!ensure_dir(cpp_dir)) {
120 fprintf(stderr, "Failed to create %s\n", cpp_dir.c_str());
121 return 1;
122 }
123
124 std::string prompt = load_prompt(ref_dir + "/prompt.txt");
125 if (prompt.empty()) {
126 prompt = "yellow school bus";
127 }
128
129 auto ref_token_ids = load_ref_i32(ref_dir + "/token_ids");
130
131 if (!sam3_test_load_tokenizer(model_path)) {
132 fprintf(stderr, "Failed to load tokenizer from %s\n", model_path.c_str());
133 return 1;
134 }
135
136 auto cpp_token_ids = sam3_test_tokenize(prompt);
137 std::vector<int32_t> run_token_ids = cpp_token_ids;
138
139 report_row token_row;
140 if (!ref_token_ids.data.empty()) {
141 const int token_bad = compare_exact_i32(cpp_token_ids, ref_token_ids.data);
142 token_row.measured = true;
143 token_row.ok = token_bad == 0;
144 token_row.r.max_diff = token_bad == 0 ? 0.0f : 1.0f;
145 token_row.r.mean_diff = token_bad == 0 ? 0.0f : 1.0f;
146 token_row.r.cosine_sim = token_bad == 0 ? 1.0f : 0.0f;
147 token_row.note = token_bad == 0 ? "exact int compare" : "tokenizer mismatch";
148 run_token_ids = ref_token_ids.data;
149 } else {
150 token_row.measured = false;
151 token_row.ok = false;
152 token_row.note = "missing token_ids reference";
153 }
154
155 sam3_params params;
156 params.model_path = model_path;
157 params.n_threads = 1;
158 params.use_gpu = false;
159
160 auto model = sam3_load_model(params);
161 if (!model) {
162 fprintf(stderr, "Failed to load model from %s\n", model_path.c_str());
163 return 1;
164 }
165
166 (void) image_path;

Callers

nothing calls this directly

Calls 13

ensure_dirFunction · 0.85
load_promptFunction · 0.85
load_ref_i32Function · 0.85
sam3_test_load_tokenizerFunction · 0.85
sam3_test_tokenizeFunction · 0.85
compare_exact_i32Function · 0.85
sam3_load_modelFunction · 0.85
load_ref_f32Function · 0.85
tensor_casesFunction · 0.70
tolerance_forFunction · 0.70
compare_tensorsFunction · 0.70

Tested by

no test coverage detected