MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / write_logfile

Function write_logfile

examples/perplexity/perplexity.cpp:30–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28};
29
30static void write_logfile(
31 const llama_context * ctx, const gpt_params & params, const llama_model * model,
32 const struct results_perplexity & results
33) {
34 if (params.logdir.empty()) {
35 return;
36 }
37
38 if (params.hellaswag) {
39 fprintf(stderr, "%s: warning: logging results is not implemented for HellaSwag. No files will be written.\n", __func__);
40 return;
41 }
42
43 const std::string timestamp = get_sortable_timestamp();
44
45 const bool success = create_directory_with_parents(params.logdir);
46 if (!success) {
47 fprintf(stderr, "%s: warning: failed to create logdir %s, cannot write logfile\n",
48 __func__, params.logdir.c_str());
49 return;
50 }
51
52 const std::string logfile_path = params.logdir + timestamp + ".yml";
53 FILE * logfile = fopen(logfile_path.c_str(), "w");
54
55 if (logfile == NULL) {
56 fprintf(stderr, "%s: failed to open logfile %s\n", __func__, logfile_path.c_str());
57 return;
58 }
59
60 fprintf(logfile, "binary: main\n");
61 char model_desc[128];
62 llama_model_desc(model, model_desc, sizeof(model_desc));
63 dump_non_result_info_yaml(logfile, params, ctx, timestamp, results.tokens, model_desc);
64
65 fprintf(logfile, "\n");
66 fprintf(logfile, "######################\n");
67 fprintf(logfile, "# Perplexity Results #\n");
68 fprintf(logfile, "######################\n");
69 fprintf(logfile, "\n");
70
71 dump_vector_float_yaml(logfile, "logits", results.logits);
72 fprintf(logfile, "ppl_value: %f\n", results.ppl_value);
73 dump_vector_float_yaml(logfile, "probs", results.probs);
74
75 llama_dump_timing_info_yaml(logfile, ctx);
76 fclose(logfile);
77}
78
79static std::vector<float> softmax(const std::vector<float>& logits) {
80 std::vector<float> probs(logits.size());

Callers 1

mainFunction · 0.70

Calls 9

fprintfFunction · 0.85
get_sortable_timestampFunction · 0.85
dump_vector_float_yamlFunction · 0.85
llama_model_descFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected