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

Function sam3_test_dump_text_encoder

sam3.cpp:12650–12767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12648}
12649
12650bool sam3_test_dump_text_encoder(const sam3_model& model,
12651 const std::vector<int32_t>& token_ids,
12652 const std::string& output_dir,
12653 int n_threads) {
12654 const int L = model.hparams.text_ctx_len;
12655 if ((int)token_ids.size() != L) {
12656 fprintf(stderr, "%s: expected %d token IDs, got %zu\n",
12657 __func__, L, token_ids.size());
12658 return false;
12659 }
12660
12661 const size_t buf_size = ggml_tensor_overhead() * 8192 + ggml_graph_overhead() * 2;
12662 struct ggml_init_params gparams = {
12663 /*.mem_size =*/buf_size,
12664 /*.mem_buffer =*/nullptr,
12665 /*.no_alloc =*/true,
12666 };
12667 struct ggml_context* ctx0 = ggml_init(gparams);
12668 if (!ctx0) {
12669 fprintf(stderr, "%s: failed to init compute context\n", __func__);
12670 return false;
12671 }
12672
12673 auto* inp_tokens = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, L);
12674 ggml_set_name(inp_tokens, "text_token_ids");
12675 ggml_set_input(inp_tokens);
12676
12677 auto* text_features = sam3_build_text_encoder_graph(ctx0, inp_tokens, model);
12678 std::vector<std::string> tensor_names = {
12679 "causal_mask",
12680 "text_token_embed",
12681 "text_after_pos_embed",
12682 "text_final_ln",
12683 "text_features_2d",
12684 };
12685 for (int i = 0; i < model.hparams.text_layers; ++i) {
12686 char name[64];
12687
12688 snprintf(name, sizeof(name), "text_block_%02d_after_ln1", i);
12689 tensor_names.emplace_back(name);
12690
12691 snprintf(name, sizeof(name), "text_block_%02d_qkv", i);
12692 tensor_names.emplace_back(name);
12693
12694 snprintf(name, sizeof(name), "text_block_%02d_attn_out", i);
12695 tensor_names.emplace_back(name);
12696
12697 snprintf(name, sizeof(name), "text_block_%02d_after_attn_residual", i);
12698 tensor_names.emplace_back(name);
12699
12700 snprintf(name, sizeof(name), "text_block_%02d_after_ln2", i);
12701 tensor_names.emplace_back(name);
12702
12703 snprintf(name, sizeof(name), "text_block_%02d_mlp_fc1", i);
12704 tensor_names.emplace_back(name);
12705
12706 snprintf(name, sizeof(name), "text_block_%02d_mlp_gelu", i);
12707 tensor_names.emplace_back(name);

Callers 3

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

sam3_fill_causal_maskFunction · 0.85
sam3_graph_computeFunction · 0.85
sam3_dump_tensor_to_pathFunction · 0.85

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68