MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / main

Function main

src/test/gemma_embedding/test.cpp:79–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79int main(int argc, char* argv[]) {
80 arg_utils::po::options_description desc("Allowed options");
81 arg_utils::po::variables_map vm;
82 desc.add_options()("model,m", arg_utils::po::value<std::string>()->required(), "Model file");
83 desc.add_options()("Short,s", arg_utils::po::value<bool>()->default_value(true), "Short Prompt");
84 desc.add_options()("Preemption,p", arg_utils::po::value<bool>()->default_value(false), "Preemption");
85
86 arg_utils::po::store(arg_utils::po::parse_command_line(argc, argv, desc), vm);
87
88 std::string tag = vm["model"].as<std::string>();
89 bool short_prompt = vm["Short"].as<bool>();
90 bool preemption = vm["Preemption"].as<bool>();
91
92 std::cout << "Model: " << tag << std::endl;
93 std::string exe_dir = utils::get_executable_directory();
94 std::string model_dir = utils::get_models_directory();
95 std::string model_list_path = exe_dir + "/model_list.json";
96 model_list model_list(model_list_path, model_dir);
97
98 header_print("info", "Initializing embedding model...");
99 std::string model_path = model_list.get_model_path(tag);
100 nlohmann::json model_info = model_list.get_model_info(tag);
101 std::cout << "Model path: " << model_path << std::endl;
102 std::cout << "Model info: " << model_info.dump() << std::endl;
103
104 auto npu_device_global = xrt::device(0);
105
106 // Use model-specific factory
107 std::unique_ptr<AutoEmbeddingModel> embedding = std::make_unique<Gemma_Embedding>(&npu_device_global);
108 model_path = model_list.get_model_path(tag);
109 model_info = model_list.get_model_info(tag);
110
111 embedding->load_model(model_path, model_info, preemption);
112
113 std::string text = "Alice's Adventures in Wonderland ALICE'S ADVENTURES IN WONDERLAND Lewis Carroll THE MILLENNIUM FULCRUM EDITION 3.0 CHAPTER I Down the Rabbit-HoleAlice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, and what is the use of a book,'thought Alice without pictures or conversation?' So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!'";
114
115 time_utils::time_point start_time = time_utils::now();
116 auto y = embedding->embed(text, task_query);
117 buffer<bf16> y_bf16(y.size());
118 for (int i = 0; i < y.size(); i++){
119 y_bf16[i] = (bf16)y[i];
120 }
121 time_utils::time_point end_time = time_utils::now();
122 std::cout << "Time: " << time_utils::duration_ms(start_time, end_time).first << "ms" << std::endl;
123 utils::print_matrix(y_bf16, 128);
124
125 buffer<bf16> ref_bf16 = buffer<bf16>(y_bf16.size());
126
127 for (int i = 0; i < y_bf16.size(); i++){
128 ref_bf16[i] = (bf16)reference[i];
129 }
130
131 print_error_metrics(get_error_metrics(y_bf16, ref_bf16));
132
133 return 0;
134}

Callers

nothing calls this directly

Calls 13

get_executable_directoryFunction · 0.85
get_models_directoryFunction · 0.85
nowFunction · 0.85
duration_msFunction · 0.85
print_matrixFunction · 0.85
get_error_metricsFunction · 0.85
get_model_pathMethod · 0.80
get_model_infoMethod · 0.80
embedMethod · 0.80
print_error_metricsFunction · 0.50
dumpMethod · 0.45
load_modelMethod · 0.45

Tested by

no test coverage detected