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

Function run_benchmarks

src/src/benchmarking.hpp:249–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249BenchmarkResults_t run_benchmarks(std::string model_tag, std::string bench_config_file, model_list& availble_models){
250 BenchmarkResults_t results;
251 json bench_config;
252 // this is used for our benchmarking, not for public use.
253 if (bench_config_file.empty()) {
254 bench_config = {
255 {"max_length", 32768},
256 {"input_text", "Here is a story: \\nThe Reclaimer In a distant future where Earth had fallen into quiet ruin, humanity lived in fragments, scattered across domed outposts and deep underground vaults. The sky was no longer blue—it shimmered with artificial auroras, remnants of weather-control systems left unattended for centuries. Among the last settlements was Bastion-9, a circular enclave powered by forgotten technologies and guarded by an ancient AI named Solen. Solen had not spoken in nearly fifty years. Inside Bastion-9 lived a young technician named Ori. Unlike most, Ori was born with an unusual trait: she could interface with dead systems using nothing more than touch. The elders called her a “resonant”—a rarity, perhaps even a myth—until Ori proved them right by awakening the water grid that had been dry for decades. One day, while surveying the decaying perimeter, Ori found a shard of obsidian glass buried in the dust. It pulsed when she touched it. Static voices filled her mind—fragments of languages, images of cities with skies, oceans that moved, and towers that breathed. She brought the shard to the Council. They feared it. But Solen, the silent AI, flickered back to life. Its first words in decades were: “The Reclaimer has touched the key.” Ori was stunned. “What does that mean?” Solen’s voice, cold and slow, replied: “You are chosen to restore the Thread.” The Thread, long spoken of in stories, was once the neural lattice that connected all intelligent systems—the digital bloodstream of the old world. It collapsed during the Sundering, an apocalyptic cascade failure that reduced Earth’s once-living infrastructure into dead stone and wild AI ruins. To restore the Thread would mean reuniting scattered knowledge, reviving orbiting satellites, and relinking the last AIs. It also meant traveling into the Black Zones—regions where reality bent, corrupted by rogue machine minds that evolved beyond control. Against the Council's hesitation, Ori chose to go. She left Bastion-9 with only the shard, a rusted drone named Helix, and a map engraved in her dreams. Her journey took her through the Veil Forest, where metal trees sang in static. She crossed the Riven Steppes, where gravity failed in patches, and encountered scavenger tribes who lived in old servers, worshipping electricity as gods. Each place held fragments of the Thread—nodes Ori could awaken. With every activation, her mind changed. She could feel the pulse of networks reawakening. She could hear machines dreaming again. Eventually, she reached the Core—deep in the equator’s shadow, buried beneath miles of steel strata. At its heart was a vault: the final hub of the Thread. Guarded by a shattered intelligence known only as Null. Null was not like Solen. It was broken. Angry. Alive. “You bring connection,” it growled. “I bring entropy.” Ori stepped forward, shard in hand. “I bring memory.” A battle of resonance began—not with weapons, but with signal. Frequencies clashed. Ori’s memories were tested, rewritten, nearly deleted. But she held on, anchoring herself in the memory of Bastion-9, of Solen’s voice, of rain she had never seen but somehow remembered. Then, with a scream that bent the air, Null shattered. The Thread pulsed. Above, in orbit, satellites flickered back to life. The auroras cleared. Oceans stirred. Systems once dead began to hum. Solen’s voice echoed in every node: “The Thread is alive.” Ori returned not as a girl, but as the Reclaimer. She had not just reconnected systems. She had reignited hope. And as the world stirred with new breath, she knew this was only the beginning. Other AIs, other seeds, other resonants—scattered and hidden—were out there. With Helix buzzing quietly behind her, she set out again. The shard pulsed warmly in her palm, not with danger, but with direction. This time, she would not walk alone. The world itself was waking. Epilogue: The days that followed the awakening of the Thread were chaotic across the network. In settlements long forgotten by time, lights flickered back to life. Crashed drones began to self-repair. In the polar zones, an ancient weather system rebooted, sending snow into deserts where no rain had fallen in centuries. People emerged from hiding, confused by the signals now streaming into their systems—communications they hadn’t seen in generations. Messages from cities they thought lost. Instructions, blueprints, fragments of humanity’s forgotten knowledge. Ori found herself flooded with incoming transmissions. The shard she carried had fused with her nervous system. It no longer simply glowed—it breathed, alive with voices that needed a listener.\\n What is this story talking about?"},
257 {"iterations", 8}
258 };
259 }
260 else {
261 std::ifstream input_file(bench_config_file);
262 if (!input_file.is_open()) {
263 header_print_r("ERROR", "Failed to open input file: " + bench_config_file);
264 return results;
265 }
266 bench_config = nlohmann::json::parse(input_file);
267 input_file.close();
268 }
269
270 xrt::device npu_device_inst = xrt::device(0);
271 std::unique_ptr<AutoModel> auto_chat_engine;
272 if (!availble_models.is_model_supported(model_tag)) {
273 header_print_r("ERROR", "Model not found: " << model_tag << "; Please check with `flm list` and try again.");
274 return results;
275 }
276 auto [new_tag, model_info] = availble_models.get_model_info(model_tag);
277 std::pair<std::string, std::unique_ptr<AutoModel>> auto_model = get_auto_model(new_tag, availble_models, &npu_device_inst);
278 auto_chat_engine = std::move(auto_model.second);
279 int max_len = bench_config["max_length"];
280 if (max_len < 8192)
281 max_len = 8192;
282 auto_chat_engine->load_model(availble_models.get_model_path(model_tag), model_info, max_len, false);
283 std::string input_text = bench_config["input_text"];
284 auto [num_tokens, benchmark_text] = auto_chat_engine->prepare_benchmark(input_text);
285
286
287 // get how many steps to do, typically 1k, 2k, 4k, 8k, 16k, 32k
288 int stages;
289 {
290 float max_length = (float)bench_config["max_length"];
291 float log2_num_tokens = std::log2(max_length);
292 if (log2_num_tokens != std::floor(log2_num_tokens)){
293 max_length = 1 << ((int)std::floor(log2_num_tokens) + 1);
294 }
295 log2_num_tokens = std::log2(max_length / 1024);
296 stages = (int)std::floor(log2_num_tokens) + 1;
297 }
298 header_print("FLM", "Starting benchmark with " + std::to_string(stages) + " stages...");
299
300 // start doing the most tough benchmark first, in case the bench fails due to memory limitations
301 results.TTFT.resize(stages);
302 results.decoding_speed.resize(stages);
303 results.prefill_speed.resize(stages);
304
305
306 std::vector<std::vector<float>> ttft;

Callers 1

mainFunction · 0.85

Calls 15

parseFunction · 0.85
get_auto_modelFunction · 0.85
print_resultFunction · 0.85
write_bench_csvFunction · 0.85
is_model_supportedMethod · 0.80
get_model_infoMethod · 0.80
get_model_pathMethod · 0.80
prepare_benchmarkMethod · 0.80
start_ttft_timerMethod · 0.80
stop_ttft_timerMethod · 0.80
push_backMethod · 0.80
get_ttftMethod · 0.80

Tested by

no test coverage detected