| 203 | std::fprintf(stderr, "draft-ipc feature_slice failed status=%d\n", status); |
| 204 | } |
| 205 | return ok; |
| 206 | #endif |
| 207 | } |
| 208 | |
| 209 | bool DFlashDraftIpcClient::propose( |
| 210 | int committed, |
| 211 | int ctx_len, |
| 212 | const std::vector<float> & noise_embed, |
| 213 | std::vector<float> & hidden_out) { |
| 214 | #if defined(_WIN32) |
| 215 | (void)committed; (void)ctx_len; (void)noise_embed; (void)hidden_out; |
| 216 | return false; |
| 217 | #else |
| 218 | FILE * cmd = process_.command_stream(); |
| 219 | const int stream_fd = process_.stream_fd(); |
| 220 | const int payload_fd = process_.payload_fd(); |
| 221 | if (!active_ || !cmd || stream_fd < 0 || committed < 0 || |
| 222 | ctx_len <= 0 || ctx_len > ring_cap_) { |
| 223 | std::fprintf(stderr, |
| 224 | "draft-ipc propose rejected active=%d cmd=%p stream_fd=%d committed=%d ctx_len=%d ring_cap=%d\n", |
| 225 | (int)active_, (void *)cmd, stream_fd, committed, ctx_len, ring_cap_); |
| 226 | return false; |
| 227 | } |
| 228 | size_t noise_expected = 0; |
| 229 | if (!checked_mul_size( |
| 230 | (size_t)hidden_size_, (size_t)block_size_, noise_expected)) { |
| 231 | return false; |
| 232 | } |
| 233 | if (noise_embed.size() != noise_expected) { |
| 234 | std::fprintf(stderr, |
| 235 | "draft-ipc propose noise size mismatch got=%zu expected=%zu hidden=%d block=%d\n", |
| 236 | noise_embed.size(), noise_expected, hidden_size_, block_size_); |
| 237 | return false; |
| 238 | } |
| 239 | size_t bytes = 0; |
| 240 | if (!checked_mul_size(noise_embed.size(), sizeof(float), bytes)) return false; |
| 241 | if (process_.resolved_payload_transport() == BackendIpcPayloadTransport::Shared) { |
| 242 | uint64_t seq = 0; |
| 243 | if (!process_.write_shared_payload(noise_embed.data(), bytes, seq)) { |
| 244 | std::fprintf(stderr, |
| 245 | "draft-ipc propose shared payload too large bytes=%zu capacity=%zu\n", |
| 246 | bytes, process_.shared_payload_capacity()); |
| 247 | return false; |
| 248 | } |
| 249 | std::fprintf(cmd, "propose_shared %d %d %zu %" PRIu64 "\n", |
| 250 | committed, ctx_len, bytes, seq); |
| 251 | std::fflush(cmd); |
| 252 | int32_t status = -1; |
| 253 | bool ok = read_exact_fd(stream_fd, &status, sizeof(status)) && status == 0; |
| 254 | if (ok) { |
| 255 | hidden_out.assign(noise_expected, 0.0f); |
| 256 | ok = read_exact_fd(stream_fd, hidden_out.data(), |
| 257 | hidden_out.size() * sizeof(float)); |
| 258 | } |
| 259 | if (!ok) { |
| 260 | std::fprintf(stderr, "draft-ipc propose_shared failed status=%d\n", status); |
| 261 | } |
| 262 | return ok; |