| 6 | #include <sys/stat.h> |
| 7 | |
| 8 | int main(int argc, char ** argv) { |
| 9 | if (argc < 3) { |
| 10 | fprintf(stderr, "Usage: %s <model_path> <output_dir>\n", argv[0]); |
| 11 | return 1; |
| 12 | } |
| 13 | |
| 14 | const std::string model_path = argv[1]; |
| 15 | const std::string output_dir = argv[2]; |
| 16 | |
| 17 | // Create output directory |
| 18 | mkdir(output_dir.c_str(), 0755); |
| 19 | |
| 20 | // Load tokenizer from embedded data in model file |
| 21 | if (!sam3_test_load_tokenizer(model_path)) { |
| 22 | fprintf(stderr, "Failed to load tokenizer from %s\n", model_path.c_str()); |
| 23 | return 1; |
| 24 | } |
| 25 | |
| 26 | // Tokenize "shoe" |
| 27 | auto token_ids = sam3_test_tokenize("shoe"); |
| 28 | fprintf(stderr, "Token IDs: ["); |
| 29 | for (size_t i = 0; i < token_ids.size(); ++i) { |
| 30 | if (i > 0) fprintf(stderr, ", "); |
| 31 | fprintf(stderr, "%d", token_ids[i]); |
| 32 | if (token_ids[i] == 0 && i > 1) { fprintf(stderr, ", ..."); break; } |
| 33 | } |
| 34 | fprintf(stderr, "]\n"); |
| 35 | |
| 36 | // Load model |
| 37 | sam3_params params; |
| 38 | params.model_path = model_path; |
| 39 | params.n_threads = 1; |
| 40 | params.use_gpu = false; |
| 41 | |
| 42 | auto model = sam3_load_model(params); |
| 43 | if (!model) { |
| 44 | fprintf(stderr, "Failed to load model from %s\n", model_path.c_str()); |
| 45 | return 1; |
| 46 | } |
| 47 | |
| 48 | // Dump text encoder tensors |
| 49 | if (!sam3_test_dump_text_encoder(*model, token_ids, output_dir, params.n_threads)) { |
| 50 | fprintf(stderr, "Failed to dump text encoder tensors\n"); |
| 51 | sam3_free_model(*model); |
| 52 | return 1; |
| 53 | } |
| 54 | |
| 55 | fprintf(stderr, "All tensors dumped to %s/\n", output_dir.c_str()); |
| 56 | sam3_free_model(*model); |
| 57 | return 0; |
| 58 | } |
nothing calls this directly
no test coverage detected