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

Function main

src/test/qwen2_npu/test.cpp:10–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8xrt::device npu_device_global;
9
10int main(int argc, char* argv[]) {
11 #ifdef __WINDOWS__
12 SetConsoleOutputCP(CP_UTF8);
13 SetConsoleCP(CP_UTF8);
14 // Set thread priority to low
15 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
16 #endif
17
18 arg_utils::po::options_description desc("Allowed options");
19 arg_utils::po::variables_map vm;
20 desc.add_options()("model,m", arg_utils::po::value<std::string>()->required(), "Model file");
21 desc.add_options()("Short,s", arg_utils::po::value<bool>()->default_value(true), "Short Prompt");
22 desc.add_options()("Preemption,p", arg_utils::po::value<bool>()->default_value(false), "Preemption");
23 arg_utils::po::store(arg_utils::po::parse_command_line(argc, argv, desc), vm);
24
25 std::string tag = vm["model"].as<std::string>();
26 bool short_prompt = vm["Short"].as<bool>();
27 bool preemption = vm["Preemption"].as<bool>();
28 std::cout << "Model: " << tag << std::endl;
29 std::string exe_dir = utils::get_executable_directory();
30 std::string model_dir = utils::get_models_directory();
31 std::string model_list_path = exe_dir + "/model_list.json";
32 model_list model_list(model_list_path, model_dir);
33
34
35
36 header_print("info", "Initializing chat model...");
37 std::string model_path = model_list.get_model_path(tag);
38 std::pair<std::string, nlohmann::json> model_info_pair = model_list.get_model_info(tag);
39 nlohmann::json model_info = model_info_pair.second;
40 std::cout << "Model path: " << model_path << std::endl;
41 npu_device_global = xrt::device(0);
42
43 std::unique_ptr<AutoModel> chat = std::make_unique<Qwen2>(&npu_device_global);
44
45 chat->load_model(model_path, model_info, -1, preemption);
46 chat->set_topp(0.8f);
47 chat->set_temperature(0.7f);
48 chat->set_repetition_penalty(1.01f);
49 chat->set_frequency_penalty(1.01f);
50 chat_meta_info_t meta_info;
51 lm_uniform_input_t uniformed_input;
52
53 if (short_prompt) {
54 uniformed_input.prompt = "Hello";
55 std::cout << "Prompt: " << uniformed_input.prompt << std::endl;
56 std::cout << "Response: ";
57 chat->start_total_timer();
58 std::string response = chat->generate_with_prompt(meta_info, uniformed_input, 32, std::cout);
59 chat->stop_total_timer();
60 std::cout << std::endl;
61 std::cout << std::endl;
62 std::cout << chat->show_profile() << std::endl;
63 // uniformed_input.prompt = "How are you";
64 // std::cout << "Prompt: " << uniformed_input.prompt << std::endl;
65 // std::cout << "Response: " << std::endl;
66 // chat->start_total_timer();
67 // response = chat->generate_with_prompt(meta_info, uniformed_input, 1024, std::cout);

Callers

nothing calls this directly

Calls 15

get_executable_directoryFunction · 0.85
get_models_directoryFunction · 0.85
get_model_pathMethod · 0.80
get_model_infoMethod · 0.80
set_toppMethod · 0.80
set_temperatureMethod · 0.80
set_frequency_penaltyMethod · 0.80
start_total_timerMethod · 0.80
stop_total_timerMethod · 0.80
show_profileMethod · 0.80
get_historyMethod · 0.80

Tested by

no test coverage detected