code wiki / (root) / nx_actor_role_llm_v2_autoreg_test.nx

nx_actor_role_llm_v2_autoreg_test.nx source

↩ module page · 101 lines · 4289 B

1// nx_actor_role_llm_v2_autoreg_test.nx -- reset state-machine smoke for 2// nx_lv_actor_reset_for_next_token. 3// 4// Honest scope: this tests the RESET state-machine logic in isolation 5// (does it correctly roll an actor from DONE back to INIT? does it 6// reject invalid inputs?). The full multi-token-through-real-transformer 7// loop hits an nxc2 preprocessor edge when combined with the GGUF 8// fixture code in one .nx file -- future work splits the fixture into 9// a sibling file or pre-builds it via a fixture primitive. For now the 10// single-token real-transformer path is verified in 11// nx_actor_role_llm_v2_real_test.nx; this smoke proves the reset 12// substrate handles all valid + invalid input paths. 13 14import "nx_syscalls.nx" 15import "nx_tier.nx" 16import "nx_model_spec.nx" 17import "nx_gguf.nx" 18import "nx_bpe.nx" 19import "nx_actor.nx" 20import "nx_message.nx" 21import "nx_actor_role_llm_v2.nx" 22 23func main() -> i64 { 24 let now: nx_size = 1000000 25 26 // Build a valid (but useless) ctx -- spec real, other args non-null 27 // sentinels; we never invoke RUN here, only exercise the reset 28 // state machine. 29 let spec: *NxModelSpec = nx_model_spec_gpt2_small() 30 let gguf_buf: *u8 = sys_mmap(64) 31 let hdr_ptr: *u8 = sys_mmap(NX_GGUF_HDR_BYTES) 32 let hdr: *NxGgufHeader = hdr_ptr as *NxGgufHeader 33 let bpe_ptr: *u8 = sys_mmap(NX_BPE_VOCAB_BYTES) 34 let bpe: *NxBpeVocab = bpe_ptr as *NxBpeVocab 35 let prompt: *u8 = sys_mmap(8) 36 prompt[0] = 65 as u8 37 let prng_buf: *u8 = sys_mmap(16) 38 let prng: *i64 = prng_buf as *i64 39 prng[0] = 42 40 41 let ctx: *NxLlmV2ActorCtx = nx_lv_actor_new( 42 spec, gguf_buf, hdr, bpe, prompt, 1, 43 1024, 4, prng, 10000, 724) 44 if (ctx as i64) == 0 { return 1 } 45 46 let sched: *NxActorScheduler = nx_ac_sched_new(2, 1000000, 4, now) 47 nx_ac_spawn(sched, 6001, 1, 80, 0, now) 48 49 // 1: reset refused when ctx is in INIT (not DONE) 50 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, prompt, 1) != NX_LV_V_INVALID { return 2 } 51 52 // 2: force ctx to DONE + try reset 53 ctx.current_phase = NX_LV_PHASE_DONE 54 ctx.runner_result = 2 55 ctx.runner_verdict = NX_LR2_OK 56 // Manually advance scheduler actor to COMPLETED so reset has the 57 // expected target state to roll back from 58 let a_pre: *NxActor = nx_ac_find(sched, 6001) 59 a_pre.state = NX_AC_STATE_COMPLETED 60 61 let new_prompt: *u8 = sys_mmap(2) 62 new_prompt[0] = 66 as u8 63 new_prompt[1] = 67 as u8 64 65 // 3: valid reset 66 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, new_prompt, 2) != NX_LV_V_STEPPED { return 3 } 67 if ctx.current_phase != NX_LV_PHASE_INIT { return 4 } 68 if ctx.prompt_len != 2 { return 5 } 69 if ctx.prompt_text != new_prompt { return 6 } 70 if ctx.runner_result != 0 { return 7 } 71 if ctx.runner_verdict != NX_LR2_OK { return 8 } 72 let a_post: *NxActor = nx_ac_find(sched, 6001) 73 if a_post.state != NX_AC_STATE_READY { return 9 } 74 75 // 4: reset refused on still-INIT ctx 76 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, new_prompt, 2) != NX_LV_V_INVALID { return 10 } 77 78 // 5: force to DONE again; refuse null prompt 79 ctx.current_phase = NX_LV_PHASE_DONE 80 let null_prompt: *u8 = (0 as i64) as *u8 81 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, null_prompt, 2) != NX_LV_V_INVALID { return 11 } 82 83 // 6: refuse non-positive prompt length 84 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, new_prompt, 0) != NX_LV_V_INVALID { return 12 } 85 if nx_lv_actor_reset_for_next_token(ctx, sched, 6001, new_prompt, -1) != NX_LV_V_INVALID { return 13 } 86 87 // 7: ctx still in DONE after rejected resets 88 if ctx.current_phase != NX_LV_PHASE_DONE { return 14 } 89 90 // 8: null ctx returns NULL verdict (no crash) 91 let null_ctx: *NxLlmV2ActorCtx = (0 as i64) as *NxLlmV2ActorCtx 92 if nx_lv_actor_reset_for_next_token(null_ctx, sched, 6001, new_prompt, 2) != NX_LV_V_NULL { return 15 } 93 94 // 9: reset without scheduler (null sched arg) still advances ctx 95 ctx.current_phase = NX_LV_PHASE_DONE 96 let null_sched: *NxActorScheduler = (0 as i64) as *NxActorScheduler 97 if nx_lv_actor_reset_for_next_token(ctx, null_sched, 6001, new_prompt, 2) != NX_LV_V_STEPPED { return 16 } 98 if ctx.current_phase != NX_LV_PHASE_INIT { return 17 } 99 100 return 0 101}