Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成速度的评估 #47

Open
Vincent131499 opened this issue Jul 11, 2023 · 1 comment
Open

生成速度的评估 #47

Vincent131499 opened this issue Jul 11, 2023 · 1 comment

Comments

@Vincent131499
Copy link

感谢杰出的工作!
对于下列表格的生成速度有疑问,请问这个速度(ms/token)是怎么计算出来的呢?
image

@li-plus
Copy link
Owner

li-plus commented Jul 13, 2023

耗时都是用这个 benchmark 在一台 Linux 服务器上实测的:

static void run_benchmark(const fs::path &model_path) {
if (!fs::exists(model_path)) {
GTEST_SKIP() << "Skipping benchmark test (model " << model_path << " not found)";
}
ggml_time_init();
int64_t start_ms = ggml_time_ms();
Pipeline pipeline(model_path.string());
int64_t load_model_ms = ggml_time_ms() - start_ms;
start_ms = ggml_time_ms();
std::vector<std::string> history{"你好", "你好👋!我是人工智能助手 ChatGLM-6B,很高兴见到你,欢迎问我任何问题。",
"晚上睡不着应该怎么办"};
GenerationConfig gen_config;
gen_config.do_sample = false;
char *num_threads_env = getenv("CHATGLM_NUM_THREADS");
if (num_threads_env) {
gen_config.num_threads = std::stoi(num_threads_env);
}
PerfStreamer streamer;
start_ms = ggml_time_ms();
pipeline.chat(history, gen_config, &streamer);
int64_t gen_s = (ggml_time_ms() - start_ms) / 1000.f;
std::cout << "======== benchmark results for " << model_path.filename() << " ========\n"
<< "using #threads: " << gen_config.num_threads << "\n"
<< "model loaded within: " << load_model_ms << " ms\n"
<< "generation finished within: " << gen_s << " s\n"
<< streamer.to_string() << "\n"
<< "===========================================================\n";
}
TEST(Benchmark, ChatGLM) {
fs::path model_path = fs::path(__FILE__).parent_path() / "chatglm-ggml.bin";
run_benchmark(model_path);
}
TEST(Benchmark, ChatGLM2) {
fs::path model_path = fs::path(__FILE__).parent_path() / "chatglm2-ggml.bin";
run_benchmark(model_path);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants