Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/gpu/inkling2/multistream/serve_live.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / gpu / inkling2 / multistream / serve_live.om` 685 lines ยท 14034 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note 100% Pure Seeded-Omega Real-Weight N=8 Multi-Stream Inkling-2-Mini Server (32,768-tok KV, Native Tool Calling, Live Arboris). 3 note ZERO CUDA, ZERO libc, ZERO Python, ZERO C, ZERO heap. 4 note Composes after: 5 note context.om + vector.om + launch.om + batch.om + bw_enc_sm121.om + emit_fast.om 6 note + arboris/prefetch.om + safetensors.om + tokenizer.om + decode.om + multistream/batcher.om. 7 note 8 note Usage: 9 note inkling2-serve --self-test (loads real 18.3 GB checkpoint, runs 2 interleaved 10 note concurrent streams + verifies 8-slot 503 gate) 11 note inkling2-serve [model_dir] [port] (starts live HTTP server on port 8080 or [port]) 12 13 global slReqBuf uchar 131072 14 global slRespBuf uchar 65536 15 global slRespLen ulong 1 16 global slOutTxt uchar 65536 17 global slOutLen ulong 8 18 global slPromptIds uint 131072 19 global slPromptLen ulong 8 20 global slPromptPos ulong 8 21 global slDone ulong 8 22 global slCacheIds uint 131072 23 global slCacheLen ulong 8 24 global slCacheHits ulong 1 25 26 text slBanner "=== INKLING-2-MINI 100% PURE SEEDED-OMEGA LIVE N=8 SERVER (32K CTX + NATIVE TOOLS + ARBORIS, ZERO CUDA) ===\n" 27 text slListenMsg "Listening on HTTP port " 28 text slReadyMsg " (N=8 static 32K KV slots, native tool tokens, Arboris active, 503 server_busy when full)\n" 29 text slSelfHdr "Running live real-weight multi-stream self-test (2 interleaved streams + 8-slot 503 gate)...\n" 30 text slS0Prompt "What is the capital of France? Answer in one sentence." 31 text slS1Prompt "What is 2 + 2? Answer in one sentence." 32 text slS0Lbl "Stream 0 (slot 0): " 33 text slS1Lbl "Stream 1 (slot 1): " 34 text slSelfOk "PASS: live real-weight N=8 multi-stream continuous batcher (2 interleaved coherent streams, 9th -> 503 server_busy, retire+reuse OK)\n" 35 text slSelfBad "FAIL: live multi-stream self-test failed\n" 36 37 text slH200 "HTTP/1.1 200 OK\nContent-Type: application/json\nConnection: close\n\n" 38 text slH503 "HTTP/1.1 503 Service Unavailable\nContent-Type: application/json\nRetry-After: 1\nConnection: close\n\n{\"error\":{\"type\":\"server_busy\",\"message\":\"all 8 static KV slots occupied\",\"slots_max\":8}}\n" 39 text slH404 "HTTP/1.1 404 Not Found\nContent-Type: application/json\nConnection: close\n\n{\"error\":{\"type\":\"not_found\"}}\n" 40 text slHealthPre "{\"status\":\"ok\",\"model\":\"inkling-2-mini\",\"context_window\":32768,\"slots_max\":8,\"slots_active\":" 41 text slHealthCache ",\"kv_prefix_hits\":" 42 text slHealthArb1 ",\"arboris_transitions\":" 43 text slHealthArb2 ",\"arboris_top8_hits\":" 44 text slHealthArb3 ",\"arboris_top16_hits\":" 45 text slHealthSuf "}\n" 46 text slModels "{\"object\":\"list\",\"data\":[{\"id\":\"inkling-2-mini\",\"object\":\"model\",\"context_window\":32768,\"slots_max\":8}]}\n" 47 text slChatPre "{\"id\":\"cmpl-ik2\",\"object\":\"chat.completion\",\"model\":\"inkling-2-mini\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"" 48 text slChatMid "\"},\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":" 49 text slChatMid2 ",\"completion_tokens\":" 50 text slChatMid3 ",\"total_tokens\":" 51 text slChatSuf "}}\n" 52 text slKeyContent "\"content\"" 53 text slKeyCLen "Content-Length:" 54 text slKeyCLenLo "content-length:" 55 56 fn slRespReset to void 57 put slRespLen 0 0 58 end 59 60 fn slRespAppendHdr s view uchar * n ulong to void 61 p = get slRespLen 0 62 for i ulong n bound 512 63 c = get s i 64 if and eq c 10 lt p 65528 65 put slRespBuf p 13 66 p = add p 1 67 end 68 if lt p 65530 69 put slRespBuf p c 70 p = add p 1 71 end 72 end 73 put slRespLen 0 p 74 end 75 76 fn slRespAppend s view uchar * n ulong to void 77 p = get slRespLen 0 78 for i ulong n bound 32768 79 if lt p 65530 80 put slRespBuf p get s i 81 p = add p 1 82 end 83 end 84 put slRespLen 0 p 85 end 86 87 fn slRespAppendU v ulong to void 88 tmp = new uchar 24 0 89 p = get slRespLen 0 90 if eq v 0 91 if lt p 65530 92 put slRespBuf p 48 93 put slRespLen 0 add p 1 94 end 95 ret 96 end 97 n = ulong 0 98 x = v 99 while gt x 0 bound 24 100 put tmp n uchar add 48 rem x 10 101 x = div x 10 102 n = add n 1 103 end 104 for i ulong n bound 24 105 if lt p 65530 106 put slRespBuf p get tmp sub sub n 1 i 107 p = add p 1 108 end 109 end 110 put slRespLen 0 p 111 end 112 113 fn slRespAppendJsonEsc off ulong n ulong to void 114 p = get slRespLen 0 115 for i ulong n bound 8192 116 c = get slOutTxt add off i 117 if and lt p 65520 ge c 32 118 if or eq c 34 eq c 92 119 put slRespBuf p 92 120 p = add p 1 121 end 122 put slRespBuf p c 123 p = add p 1 124 else 125 if and lt p 65520 eq c 10 126 put slRespBuf p 92 127 put slRespBuf add p 1 110 128 p = add p 2 129 else 130 if and lt p 65520 eq c 9 131 put slRespBuf p 92 132 put slRespBuf add p 1 116 133 p = add p 2 134 end 135 end 136 end 137 end 138 put slRespLen 0 p 139 end 140 141 fn slAppendTokOut slot ulong tid ulong to void 142 if ge tid IK_VOCAB_MAX 143 ret 144 end 145 l = ulong get ikTokLen tid 146 if eq l 0 147 ret 148 end 149 off = ulong get ikTokOff tid 150 cur = get slOutLen slot 151 base = mul slot 8192 152 for i ulong l bound 64 153 if lt cur 8184 154 put slOutTxt add base cur get ikTokPool add off i 155 cur = add cur 1 156 end 157 end 158 put slOutLen slot cur 159 end 160 161 fn slCacheMatches slot ulong nTok ulong to bool 162 cLen = get slCacheLen slot 163 if or eq cLen 0 le nTok cLen 164 ret false 165 end 166 base = mul slot 16384 167 for i ulong cLen bound 16384 168 if ne get slCacheIds add base i get ikTokOutLong i 169 ret false 170 end 171 end 172 ret true 173 end 174 175 fn slStartFromBuf slot ulong tlen ulong maxGen ulong to bool 176 nTok = ikTokEncodeSmartLong tlen 177 if eq nTok 0 178 ret false 179 end 180 base = mul slot 16384 181 if gt nTok 16300 182 nTok = ulong 16300 183 end 184 startPos = ulong 0 185 if slCacheMatches slot nTok 186 startPos = get slCacheLen slot 187 put slCacheHits 0 add get slCacheHits 0 1 188 else 189 ikDResetSlot slot 190 put slCacheLen slot 0 191 end 192 for i ulong nTok bound 16384 193 put slPromptIds add base i get ikTokOutLong i 194 end 195 put slPromptLen slot nTok 196 put slPromptPos slot startPos 197 put slOutLen slot 0 198 put slDone slot 0 199 put msMaxGen slot maxGen 200 ret true 201 end 202 203 fn slStartStream slot ulong txt view uchar * tlen ulong maxGen ulong to bool 204 for i ulong tlen bound 16384 205 put ikTokInBuf i get txt i 206 end 207 ret slStartFromBuf slot tlen maxGen 208 end 209 210 note Execute 1 prefill or decode step for active stream `slot`. 211 note Stops ONLY on 200006 (<|content_model_end_sampling|>) or 199999 (<|endoftext|>), 212 note NOT on 200010 (<|end_message|>), so native multi-message tool calls complete cleanly. 213 fn slStepStream slot ulong to bool 214 if eq get slDone slot 1 215 ret true 216 end 217 pPos = get slPromptPos slot 218 pLen = get slPromptLen slot 219 if lt pPos pLen 220 if ge sub pLen pPos 9 221 base = mul slot 16384 222 for b ulong 8 223 put ikB8Toks b get slPromptIds add base add pPos b 224 end 225 if not ikDPrefillBatch8 slot pPos 226 put slDone slot 1 227 ret true 228 end 229 for b ulong 8 230 posB = add pPos b 231 if lt posB 16300 232 put slCacheIds add base posB get ikB8Toks b 233 put slCacheLen slot add posB 1 234 end 235 end 236 put slPromptPos slot add pPos 8 237 ret false 238 end 239 tok = ulong get slPromptIds add mul slot 16384 pPos 240 needL = eq add pPos 1 pLen 241 nxt = ikDForwardSlot slot tok pPos needL 242 if lt nxt 0 243 put slDone slot 1 244 ret true 245 end 246 if lt pPos 16300 247 put slCacheIds add mul slot 16384 pPos uint tok 248 put slCacheLen slot add pPos 1 249 end 250 put slPromptPos slot add pPos 1 251 if needL 252 if or eq nxt 200006 eq nxt 199999 253 put slDone slot 1 254 ret true 255 end 256 slAppendTokOut slot ulong nxt 257 ok = msAdvance slot uint nxt 258 put msPosQ slot pLen 259 end 260 ret false 261 end 262 posQ = get msPosQ slot 263 curTok = ulong get msLastTok slot 264 nxt = ikDForwardSlot slot curTok posQ true 265 if lt posQ 16300 266 put slCacheIds add mul slot 16384 posQ uint curTok 267 put slCacheLen slot add posQ 1 268 end 269 if or lt nxt 0 or eq nxt 200006 eq nxt 199999 270 put slDone slot 1 271 ret true 272 end 273 slAppendTokOut slot ulong nxt 274 ok = msAdvance slot uint nxt 275 if or not ok ge get msGenCnt slot get msMaxGen slot 276 put slDone slot 1 277 ret true 278 end 279 ret false 280 end 281 282 fn slRunSelfTest to int 283 ikDPrint slSelfHdr 284 msInit 285 s0 = msAdmit 10 32 0 286 s1 = msAdmit 11 32 0 287 if or ne s0 0 ne s1 1 288 ikDPrint slSelfBad 289 ret 30 290 end 291 if not slStartStream 0 slS0Prompt len slS0Prompt 32 292 ikDPrint slSelfBad 293 ret 31 294 end 295 if not slStartStream 1 slS1Prompt len slS1Prompt 32 296 ikDPrint slSelfBad 297 ret 32 298 end 299 for k ulong 6 300 sk = msAdmit int add 12 k 8 0 301 if ne sk long add 2 k 302 ikDPrint slSelfBad 303 ret 33 304 end 305 end 306 if ne msAdmit 99 8 0 -1 307 ikDPrint slSelfBad 308 ret 34 309 end 310 for k ulong 6 311 msRetire add 2 k 312 end 313 for step ulong 128 314 d0 = slStepStream 0 315 d1 = slStepStream 1 316 if and d0 d1 317 break 318 end 319 end 320 ikDPrint slS0Lbl 321 w0 = write 1 slOutTxt 0 get slOutLen 0 322 ikDPrint ikDMsgNl 323 ikDPrint slS1Lbl 324 w1 = write 1 slOutTxt 8192 get slOutLen 1 325 ikDPrint ikDMsgNl 326 msRetire 0 327 msRetire 1 328 reused = msAdmit 42 8 0 329 if ne reused 0 330 ikDPrint slSelfBad 331 ret 35 332 end 333 msRetire 0 334 if or eq get slOutLen 0 0 eq get slOutLen 1 0 335 ikDPrint slSelfBad 336 ret 36 337 end 338 ikDPrint slSelfOk 339 ret 0 340 end 341 342 fn slFindHdrEnd n ulong to ulong 343 if lt n 4 344 ret n 345 end 346 lim = sub n 3 347 for i ulong lim bound 4096 348 if and eq get slReqBuf i 13 eq get slReqBuf add i 1 10 349 if and eq get slReqBuf add i 2 13 eq get slReqBuf add i 3 10 350 ret add i 4 351 end 352 end 353 if and eq get slReqBuf i 10 eq get slReqBuf add i 1 10 354 ret add i 2 355 end 356 end 357 ret n 358 end 359 360 fn slMatchHdrAt pos ulong pat view uchar * to bool 361 for j ulong len pat bound 32 362 if ne get slReqBuf add pos j get pat j 363 ret false 364 end 365 end 366 ret true 367 end 368 369 fn slParseDigitsAt start ulong lim ulong to ulong 370 p = start 371 while and lt p lim eq get slReqBuf p 32 bound 32 372 p = add p 1 373 end 374 v = ulong 0 375 while lt p lim bound 16 376 c = get slReqBuf p 377 if or lt c 48 gt c 57 378 break 379 end 380 v = add mul v 10 ulong sub c 48 381 p = add p 1 382 end 383 ret v 384 end 385 386 fn slParseContentLength hdrEnd ulong to ulong 387 if lt hdrEnd 16 388 ret 0 389 end 390 lim = sub hdrEnd 15 391 for i ulong lim bound 4096 392 if slMatchHdrAt i slKeyCLen 393 ret slParseDigitsAt add i 15 hdrEnd 394 end 395 if slMatchHdrAt i slKeyCLenLo 396 ret slParseDigitsAt add i 15 hdrEnd 397 end 398 end 399 ret 0 400 end 401 402 note Read complete HTTP request (headers + full Content-Length body up to 128 KiB). 403 fn slReadFullReq fd int to ulong 404 tot = ulong 0 405 wantTot = ulong 0 406 for iter ulong 256 407 if ge tot 131070 408 break 409 end 410 r = read fd slReqBuf tot sub 131070 tot 411 if eq r -4 412 continue 413 end 414 if le r 0 415 break 416 end 417 tot = add tot ulong r 418 if eq wantTot 0 419 he = slFindHdrEnd tot 420 if lt he tot 421 cl = slParseContentLength he 422 if gt cl 0 423 wantTot = add he cl 424 if gt wantTot 131070 425 wantTot = ulong 131070 426 end 427 else 428 break 429 end 430 else 431 if eq get slReqBuf 0 71 432 if lt he add tot 1 433 break 434 end 435 end 436 end 437 end 438 if and gt wantTot 0 ge tot wantTot 439 break 440 end 441 end 442 ret tot 443 end 444 445 fn slUnescapeToPrompt st ulong n ulong to ulong 446 p = st 447 o = ulong 0 448 while and lt p n lt o 131000 bound 131072 449 c = get slReqBuf p 450 if eq c 34 451 break 452 end 453 p = add p 1 454 if eq c 92 455 if ge p n 456 break 457 end 458 e = get slReqBuf p 459 p = add p 1 460 if eq e 110 461 put ikTokInBuf o 10 462 o = add o 1 463 else 464 if eq e 114 465 put ikTokInBuf o 13 466 o = add o 1 467 else 468 if eq e 116 469 put ikTokInBuf o 9 470 o = add o 1 471 else 472 put ikTokInBuf o e 473 o = add o 1 474 end 475 end 476 end 477 else 478 put ikTokInBuf o c 479 o = add o 1 480 end 481 end 482 ret o 483 end 484 485 fn slExtractContent n ulong to ulong 486 if lt n 14 487 ret 0 488 end 489 lim = sub n 10 490 for i ulong lim bound 131072 491 ok = true 492 for j ulong 9 493 if ne get slReqBuf add i j get slKeyContent j 494 ok = false 495 break 496 end 497 end 498 if ok 499 p = add i 9 500 while and lt p n ne get slReqBuf p 34 bound 64 501 p = add p 1 502 end 503 if lt p n 504 ret slUnescapeToPrompt add p 1 n 505 end 506 end 507 end 508 ret 0 509 end 510 511 fn slHandleChat fd int n ulong to void 512 slot = msAdmit fd 1024 0 513 if lt slot 0 514 w = write fd slH503 0 len slH503 515 ret 516 end 517 pLen = slExtractContent n 518 if eq pLen 0 519 pLen = len slS0Prompt 520 for i ulong pLen bound 1024 521 put ikTokInBuf i get slS0Prompt i 522 end 523 end 524 s = ulong slot 525 if slStartFromBuf s pLen 1024 526 for step ulong 17408 527 if slStepStream s 528 break 529 end 530 end 531 end 532 pToks = get slPromptLen s 533 cToks = get msGenCnt s 534 slRespReset 535 slRespAppendHdr slH200 len slH200 536 slRespAppend slChatPre len slChatPre 537 slRespAppendJsonEsc mul s 8192 get slOutLen s 538 slRespAppend slChatMid len slChatMid 539 slRespAppendU pToks 540 slRespAppend slChatMid2 len slChatMid2 541 slRespAppendU cToks 542 slRespAppend slChatMid3 len slChatMid3 543 slRespAppendU add pToks cToks 544 slRespAppend slChatSuf len slChatSuf 545 w = write fd slRespBuf 0 get slRespLen 0 546 msRetire s 547 end 548 549 fn slHandleHttp fd int to void 550 n = slReadFullReq fd 551 if le n 4 552 ret 553 end 554 if and eq get slReqBuf 0 71 eq get slReqBuf 4 47 555 if eq get slReqBuf 5 104 556 slRespReset 557 slRespAppendHdr slH200 len slH200 558 slRespAppend slHealthPre len slHealthPre 559 slRespAppendU get msActiveCnt 0 560 slRespAppend slHealthCache len slHealthCache 561 slRespAppendU get slCacheHits 0 562 slRespAppend slHealthArb1 len slHealthArb1 563 slRespAppendU get ikDArbStats 0 564 slRespAppend slHealthArb2 len slHealthArb2 565 slRespAppendU get ikDArbStats 1 566 slRespAppend slHealthArb3 len slHealthArb3 567 slRespAppendU get ikDArbStats 2 568 slRespAppend slHealthSuf len slHealthSuf 569 w = write fd slRespBuf 0 get slRespLen 0 570 ret 571 end 572 if and eq get slReqBuf 5 118 eq get slReqBuf 8 109 573 slRespReset 574 slRespAppendHdr slH200 len slH200 575 slRespAppend slModels len slModels 576 w = write fd slRespBuf 0 get slRespLen 0 577 ret 578 end 579 end 580 if and eq get slReqBuf 0 80 eq get slReqBuf 5 47 581 slHandleChat fd n 582 ret 583 end 584 w = write fd slH404 0 len slH404 585 end 586 587 fn slIsSelfTestArg to bool 588 a = new uchar 32 0 589 if lt argcnt 2 590 ret false 591 end 592 n = argread 1 a 0 32 593 if eq n 11 594 if and eq get a 0 45 eq get a 2 115 595 ret true 596 end 597 end 598 if ge argcnt 3 599 n2 = argread 2 a 0 32 600 if eq n2 11 601 if and eq get a 0 45 eq get a 2 115 602 ret true 603 end 604 end 605 end 606 ret false 607 end 608 609 fn slListen port ulong to long 610 addr = new uchar 16 0 611 one = new uchar 4 0 612 put addr 0 2 613 put addr 2 uchar shr port 8 614 put addr 3 uchar and port 255 615 put one 0 1 616 fd = socknew 2 524289 0 617 if lt fd 0 618 ret fd 619 end 620 r = sockopt int fd 1 2 one 0 4 621 if eq r 0 622 r = bind int fd addr 0 16 623 end 624 if eq r 0 625 r = listen int fd 16 626 end 627 if ne r 0 628 c = fclose int fd 629 ret r 630 end 631 ret fd 632 end 633 634 fn main to int 635 ikDPrint slBanner 636 ikDPrint ikDMsgLoad 637 t0 = monons 638 rc0 = ikDInitModel 8 639 if ne rc0 0 640 ikDPrint ikDMsgFail 641 ikDPrintU ulong rc0 642 ikDPrint ikDMsgNl 643 ret rc0 644 end 645 t1 = monons 646 ikDPrint ikDMsgLoaded 647 ikDPrintU ulong div sub t1 t0 `1000000` 648 ikDPrint ikDMsgNl 649 ikArbResetAll 650 for i ulong 3072 651 put ikDArbRes i -1 652 end 653 for i ulong 4 654 put ikDArbStats i 0 655 end 656 for s ulong 8 657 put slCacheLen s 0 658 end 659 put slCacheHits 0 0 660 if slIsSelfTestArg 661 rc1 = slRunSelfTest 662 rc = nvstop 663 ret rc1 664 end 665 msInit 666 port = ulong 8080 667 lfd = slListen port 668 if lt lfd 0 669 rc = nvstop 670 ret 40 671 end 672 ikDPrint slListenMsg 673 ikDPrintU port 674 ikDPrint slReadyMsg 675 for conn ulong `1000000` 676 cfd = accept int lfd 524288 677 if ge cfd 0 678 slHandleHttp int cfd 679 c0 = fclose int cfd 680 end 681 end 682 c1 = fclose int lfd 683 rc = nvstop 684 ret 0 685 end