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

Function dist_coordinator_eval_span

ds4_distributed.c:2670–2784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2668}
2669
2670static int dist_coordinator_eval_span(
2671 ds4_dist_coordinator_state *state,
2672 ds4_session *session,
2673 const ds4_dist_route_plan *plan,
2674 const int *tokens,
2675 uint32_t n_tokens,
2676 uint32_t pos0,
2677 uint64_t session_id,
2678 uint64_t request_id,
2679 bool reset_session,
2680 float *logits,
2681 char *err,
2682 size_t errlen) {
2683 const bool profile = dist_decode_profile_enabled() && n_tokens == 1;
2684 const double span_t0 = profile ? dist_now_sec() : 0.0;
2685 const uint64_t hc_values = ds4_engine_hidden_f32_values(state->engine);
2686 const uint64_t hidden_bytes64 = (uint64_t)n_tokens * hc_values * sizeof(float);
2687 if (hidden_bytes64 > UINT32_MAX) {
2688 if (errlen) snprintf(err, errlen, "distributed coordinator hidden-state chunk is too large");
2689 return 1;
2690 }
2691 uint64_t prefix_hash = DS4_DIST_TOKEN_HASH_INIT;
2692 if (reset_session) {
2693 if (pos0 != 0) {
2694 if (errlen) snprintf(err, errlen, "distributed reset span must start at position 0");
2695 return 1;
2696 }
2697 } else if (dist_session_token_hash_prefix(session,
2698 pos0,
2699 &prefix_hash,
2700 err,
2701 errlen) != 0) {
2702 return 1;
2703 }
2704 const uint64_t result_hash = dist_token_hash_update_span(prefix_hash, tokens, n_tokens);
2705 const uint32_t hidden_bytes = (uint32_t)hidden_bytes64;
2706 float *hidden = NULL;
2707 if (plan->count != 0) {
2708 hidden = malloc(hidden_bytes);
2709 if (!hidden) {
2710 if (errlen) snprintf(err, errlen, "out of memory allocating coordinator hidden-state");
2711 return 1;
2712 }
2713 }
2714 if (reset_session &&
2715 ds4_session_layer_slice_reset(session, err, errlen) != 0) {
2716 free(hidden);
2717 return 1;
2718 }
2719
2720 const bool local_logits = plan->count == 0;
2721 int remote_fd = -1;
2722 if (plan->count != 0) {
2723 const ds4_dist_route_entry *first = &plan->entry[0];
2724 remote_fd = first->fd;
2725 if (remote_fd < 0) {
2726 if (errlen) snprintf(err, errlen, "distributed route has no live first-hop connection");
2727 free(hidden);

Callers 5

dist_write_logprobs_dumpFunction · 0.85
ds4_dist_session_syncFunction · 0.85
ds4_dist_session_evalFunction · 0.85

Tested by

no test coverage detected