| 16 | |
| 17 | |
| 18 | int main(int argc, char* argv[]) { |
| 19 | #ifdef __WINDOWS__ |
| 20 | SetConsoleOutputCP(CP_UTF8); |
| 21 | SetConsoleCP(CP_UTF8); |
| 22 | // Set thread priority to low |
| 23 | SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); |
| 24 | #endif |
| 25 | |
| 26 | arg_utils::po::options_description desc("Allowed options"); |
| 27 | arg_utils::po::variables_map vm; |
| 28 | desc.add_options()("model,m", arg_utils::po::value<std::string>()->required(), "Model file"); |
| 29 | desc.add_options()("Short,s", arg_utils::po::value<bool>()->default_value(true), "Short Prompt"); |
| 30 | desc.add_options()("Preemption,p", arg_utils::po::value<bool>()->default_value(false), "Preemption"); |
| 31 | arg_utils::po::store(arg_utils::po::parse_command_line(argc, argv, desc), vm); |
| 32 | |
| 33 | std::string tag = vm["model"].as<std::string>(); |
| 34 | bool short_prompt = vm["Short"].as<bool>(); |
| 35 | bool preemption = vm["Preemption"].as<bool>(); |
| 36 | std::cout << "Model: " << tag << std::endl; |
| 37 | std::string exe_dir = utils::get_executable_directory(); |
| 38 | std::string model_dir = utils::get_models_directory(); |
| 39 | std::string model_list_path = exe_dir + "/model_list.json"; |
| 40 | model_list model_list(model_list_path, model_dir); |
| 41 | |
| 42 | |
| 43 | |
| 44 | header_print("info", "Initializing chat model..."); |
| 45 | std::string model_path = model_list.get_model_path(tag); |
| 46 | std::pair<std::string, nlohmann::json> model_info_pair = model_list.get_model_info(tag); |
| 47 | nlohmann::json model_info = model_info_pair.second; |
| 48 | std::cout << "Model path: " << model_path << std::endl; |
| 49 | npu_device_global = xrt::device(0); |
| 50 | |
| 51 | std::unique_ptr<AutoModel> chat = std::make_unique<Phi4>(&npu_device_global); |
| 52 | |
| 53 | |
| 54 | chat->load_model(model_path, model_info, -1, preemption); |
| 55 | chat->set_topk(5); |
| 56 | chat->set_temperature(0.6f); |
| 57 | chat_meta_info_t meta_info; |
| 58 | lm_uniform_input_t uniformed_input; |
| 59 | |
| 60 | |
| 61 | if (short_prompt) { |
| 62 | uniformed_input.prompt = "Hello, I am a freshman student in EE major."; |
| 63 | std::cout << "Prompt: " << uniformed_input.prompt << std::endl; |
| 64 | std::cout << "Response: "; |
| 65 | chat->start_total_timer(); |
| 66 | std::string response = chat->generate_with_prompt(meta_info, uniformed_input, 1024, std::cout); |
| 67 | chat->stop_total_timer(); |
| 68 | std::cout << std::endl; |
| 69 | std::cout << std::endl; |
| 70 | std::cout << chat->show_profile() << std::endl; |
| 71 | uniformed_input.prompt = "Can you explain Maxwell equations and its applications?"; |
| 72 | std::cout << "Prompt: " << uniformed_input.prompt << std::endl; |
| 73 | std::cout << "Response: "; |
| 74 | chat->start_total_timer(); |
| 75 | response = chat->generate_with_prompt(meta_info, uniformed_input, 4096, std::cout); |
nothing calls this directly
no test coverage detected