| 5387 | free(logits); |
| 5388 | free(n_comp); |
| 5389 | free(n_index_comp); |
| 5390 | return rc; |
| 5391 | } |
| 5392 | |
| 5393 | /* ========================================================================= |
| 5394 | * Coordinator Session API |
| 5395 | * ========================================================================= |
| 5396 | * |
| 5397 | * These functions are the distributed backend for the normal ds4_session API. |
| 5398 | * Program frontends should keep using ds4_session_sync/eval/save/load; ds4.c |
| 5399 | * selects these calls when the owning session has a coordinator attached. |
| 5400 | */ |
| 5401 | |
| 5402 | int ds4_dist_session_create( |
| 5403 | ds4_dist_session **out, |
| 5404 | ds4_engine *engine, |
| 5405 | const ds4_dist_options *opt, |
| 5406 | ds4_session *owner, |
| 5407 | int ctx_size, |
| 5408 | char *err, |
| 5409 | size_t errlen) { |
| 5410 | (void)owner; |
| 5411 | if (!out || !engine || !opt) { |
| 5412 | if (errlen) snprintf(err, errlen, "missing distributed session parameters"); |
| 5413 | return 1; |
| 5414 | } |
| 5415 | *out = NULL; |
| 5416 | if (opt->role != DS4_DISTRIBUTED_COORDINATOR) { |
| 5417 | if (errlen) snprintf(err, errlen, "distributed session requires coordinator role"); |
| 5418 | return 1; |
| 5419 | } |
| 5420 | if (dist_validate_options(opt, err, errlen) != 0) return 1; |
| 5421 | |
| 5422 | int listen_fd = dist_open_listener(opt->listen_host, opt->listen_port, err, errlen); |
| 5423 | if (listen_fd < 0) return 1; |
| 5424 | |
| 5425 | ds4_dist_session *d = calloc(1, sizeof(*d)); |
| 5426 | if (!d) { |
| 5427 | close(listen_fd); |
| 5428 | if (errlen) snprintf(err, errlen, "out of memory creating distributed session"); |
| 5429 | return 1; |
| 5430 | } |
| 5431 | |
| 5432 | d->listen_fd = listen_fd; |
| 5433 | d->state.engine = engine; |
| 5434 | d->state.model_id = (uint32_t)ds4_engine_model_id(engine); |
| 5435 | d->state.n_layers = (uint32_t)ds4_engine_layer_count(engine); |
| 5436 | d->state.local_start = opt->layers.start; |
| 5437 | d->state.local_end = dist_resolved_layer_end(opt, d->state.n_layers); |
| 5438 | d->state.ctx_size = ctx_size > 0 ? (uint32_t)ctx_size : 0u; |
| 5439 | d->state.local_has_output = opt->layers.has_output; |
| 5440 | d->state.local_can_output_head = ds4_engine_has_output_head(engine); |
| 5441 | d->state.replay_check = opt->replay_check; |
| 5442 | d->state.debug = opt->debug; |
| 5443 | d->state.use_control_for_work = true; |
| 5444 | d->state.prefill_chunk = opt->prefill_chunk; |
| 5445 | d->state.prefill_window = opt->prefill_window; |
| 5446 | d->state.activation_bits = dist_activation_bits_or_default(opt->activation_bits); |
no test coverage detected