| 26 | // } |
| 27 | |
| 28 | int main(int argc, char* argv[]) { |
| 29 | #ifdef __WINDOWS__ |
| 30 | SetConsoleOutputCP(CP_UTF8); |
| 31 | SetConsoleCP(CP_UTF8); |
| 32 | // Set thread priority to low |
| 33 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); |
| 34 | #endif |
| 35 | |
| 36 | arg_utils::po::options_description desc("Allowed options"); |
| 37 | arg_utils::po::variables_map vm; |
| 38 | desc.add_options()("model,m", arg_utils::po::value<std::string>()->required(), "Model file"); |
| 39 | desc.add_options()("Short,s", arg_utils::po::value<bool>()->default_value(true), "Short Prompt"); |
| 40 | desc.add_options()("Preemption,p", arg_utils::po::value<bool>()->default_value(false), "Preemption"); |
| 41 | arg_utils::po::store(arg_utils::po::parse_command_line(argc, argv, desc), vm); |
| 42 | |
| 43 | std::string tag = vm["model"].as<std::string>(); |
| 44 | bool short_prompt = vm["Short"].as<bool>(); |
| 45 | bool preemption = vm["Preemption"].as<bool>(); |
| 46 | std::cout << "Model: " << tag << std::endl; |
| 47 | std::string exe_dir = utils::get_executable_directory(); |
| 48 | std::string model_dir = utils::get_models_directory(); |
| 49 | std::string model_list_path = exe_dir + "/model_list.json"; |
| 50 | model_list model_list(model_list_path, model_dir); |
| 51 | |
| 52 | |
| 53 | |
| 54 | header_print("info", "Initializing chat model..."); |
| 55 | std::string model_path = model_list.get_model_path(tag); |
| 56 | std::pair<std::string, nlohmann::json> model_info_pair = model_list.get_model_info(tag); |
| 57 | nlohmann::json model_info = model_info_pair.second; |
| 58 | std::cout << "Model path: " << model_path << std::endl; |
| 59 | |
| 60 | std::unique_ptr<AutoModel> chat = std::make_unique<Gemma4e>(&npu_device_global); |
| 61 | std::cout <<"Chat model initialized" << std::endl; |
| 62 | npu_device_global = xrt::device(0); |
| 63 | std::cout << "NPU Device initialized: " << npu_device_global.get_info<xrt::info::device::name>() << std::endl; |
| 64 | chat->load_model(model_path, model_info, -1, preemption); |
| 65 | header_print("info", "Model loaded"); |
| 66 | chat_meta_info_t meta_info; |
| 67 | lm_uniform_input_t uniformed_input; |
| 68 | chat->set_topk(1); |
| 69 | |
| 70 | if (short_prompt) { |
| 71 | std::string response; |
| 72 | // Phase 0: test text input |
| 73 | uniformed_input.prompt = "Hello, introduce yourself briefly."; |
| 74 | |
| 75 | std::cout << "Prompt: " << uniformed_input.prompt << std::endl; |
| 76 | std::cout << "Response: " << std::endl; |
| 77 | chat->start_total_timer(); |
| 78 | response = chat->generate_with_prompt(meta_info, uniformed_input, 8192, std::cout); |
| 79 | chat->stop_total_timer(); |
| 80 | std::cout << std::endl; |
| 81 | std::cout << std::endl; |
| 82 | std::cout << chat->show_profile() << std::endl; |
| 83 | uniformed_input.images.clear(); |
| 84 | uniformed_input.audios.clear(); |
| 85 | chat->clear_context(); |
nothing calls this directly
no test coverage detected