MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_write_logits_dump

Function dist_write_logits_dump

ds4_distributed.c:2865–2909  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2863}
2864
2865static int dist_write_logits_dump(
2866 ds4_dist_coordinator_state *state,
2867 const ds4_dist_generation_options *gen,
2868 const ds4_tokens *prompt,
2869 const ds4_dist_route_plan *plan,
2870 const float *logits) {
2871 FILE *fp = fopen(gen->dump_logits_path, "wb");
2872 if (!fp) {
2873 fprintf(stderr, "ds4: failed to open distributed --dump-logits file: %s\n",
2874 gen->dump_logits_path);
2875 return 1;
2876 }
2877
2878 const int vocab = ds4_engine_vocab_size(state->engine);
2879 const int argmax = dist_logits_argmax(logits, vocab);
2880 fprintf(fp,
2881 "{\n"
2882 " \"source\":\"ds4-distributed\",\n"
2883 " \"quant_bits\":%d,\n"
2884 " \"prompt_tokens\":%d,\n"
2885 " \"ctx\":%d,\n"
2886 " \"vocab\":%d,\n"
2887 " \"route_count\":%u,\n"
2888 " \"argmax_token\":",
2889 ds4_engine_routed_quant_bits(state->engine),
2890 prompt->len,
2891 gen->ctx_size,
2892 vocab,
2893 plan->count);
2894 dist_json_write_token(fp, state->engine, argmax);
2895 fprintf(fp, ",\n \"argmax_logit\":%.9g,\n \"logits\":[", logits[argmax]);
2896 for (int i = 0; i < vocab; i++) {
2897 if (i) fputc(',', fp);
2898 if ((i % 8) == 0) fputs("\n ", fp);
2899 if (isfinite(logits[i])) fprintf(fp, "%.9g", logits[i]);
2900 else fputs("null", fp);
2901 }
2902 fputs("\n ]\n}\n", fp);
2903 if (fclose(fp) != 0) {
2904 fprintf(stderr, "ds4: failed to close distributed --dump-logits file: %s\n",
2905 gen->dump_logits_path);
2906 return 1;
2907 }
2908 return 0;
2909}
2910
2911static int dist_logits_top_logprobs(const float *logits, int vocab, ds4_dist_logprob *scores, int k) {
2912 if (k <= 0) return 0;

Callers 1

Calls 4

ds4_engine_vocab_sizeFunction · 0.85
dist_logits_argmaxFunction · 0.85
dist_json_write_tokenFunction · 0.85

Tested by

no test coverage detected