| 3862 | } |
| 3863 | |
| 3864 | static int dist_run_coordinator_generation( |
| 3865 | ds4_dist_coordinator_state *state, |
| 3866 | const ds4_dist_generation_options *gen) { |
| 3867 | char err[256]; |
| 3868 | ds4_dist_route_plan plan; |
| 3869 | uint64_t plan_generation = 0; |
| 3870 | if (!dist_coordinator_ensure_route(state, &plan, &plan_generation, err, sizeof(err))) { |
| 3871 | fprintf(stderr, "ds4: distributed coordinator: %s\n", err); |
| 3872 | return 1; |
| 3873 | } |
| 3874 | |
| 3875 | ds4_session *session = NULL; |
| 3876 | if (ds4_session_create(&session, state->engine, gen->ctx_size) != 0) { |
| 3877 | fprintf(stderr, "ds4: distributed coordinator: failed to create local session\n"); |
| 3878 | dist_route_plan_free(&plan); |
| 3879 | return 1; |
| 3880 | } |
| 3881 | |
| 3882 | ds4_tokens prompt = {0}; |
| 3883 | if (dist_prompt_is_rendered_chat(gen->prompt)) { |
| 3884 | ds4_tokenize_rendered_chat(state->engine, gen->prompt, &prompt); |
| 3885 | } else { |
| 3886 | ds4_encode_chat_prompt(state->engine, gen->system, gen->prompt, gen->think_mode, &prompt); |
| 3887 | } |
| 3888 | if (prompt.len <= 0) { |
| 3889 | fprintf(stderr, "ds4: distributed coordinator: empty prompt\n"); |
| 3890 | ds4_session_free(session); |
| 3891 | dist_route_plan_free(&plan); |
| 3892 | return 1; |
| 3893 | } |
| 3894 | |
| 3895 | const uint64_t session_id = ((uint64_t)(uint32_t)time(NULL) << 32) ^ (uint64_t)getpid(); |
| 3896 | uint64_t request_id = 1; |
| 3897 | float *logits = malloc((size_t)ds4_engine_vocab_size(state->engine) * sizeof(float)); |
| 3898 | if (!logits) { |
| 3899 | fprintf(stderr, "ds4: distributed coordinator: out of memory allocating logits\n"); |
| 3900 | ds4_tokens_free(&prompt); |
| 3901 | ds4_session_free(session); |
| 3902 | dist_route_plan_free(&plan); |
| 3903 | return 1; |
| 3904 | } |
| 3905 | |
| 3906 | int prefill_rc = dist_coordinator_prefill_prompt(state, |
| 3907 | session, |
| 3908 | &plan, |
| 3909 | &prompt, |
| 3910 | session_id, |
| 3911 | &request_id, |
| 3912 | logits, |
| 3913 | err, |
| 3914 | sizeof(err)); |
| 3915 | if (prefill_rc != 0) { |
| 3916 | fprintf(stderr, |
| 3917 | "ds4: distributed prompt processing failed: %s\n", |
| 3918 | err); |
| 3919 | if (dist_coordinator_rebuild_from_transcript(state, |
| 3920 | session, |
| 3921 | &plan, |
no test coverage detected