interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-scheduler / tests / prefill_gate_test.rs

78 lines · 2882 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! PREFILL-GATE: allocated != computed.
17//!
18//! Uses only APIs that already exist on main (cfd9982), so this file also runs
19//! against main, where it must FAIL (see scripts/prefill-gate/fails-on-main.sh).
20//! On main the admission rule (crates/aien-scheduler/src/lib.rs:475-492 at
21//! cfd9982) treats any existing block table as prefilled and decodes it.
22
23use aien_inference_abi::{SamplingParams, SequenceRequest};
24use aien_kv_cache::create_shared_kv_manager;
25use aien_scheduler::{AienScheduler, SchedulerConfig, SequenceId};
26
27#[test]
28fn prefill_gate_allocated_but_unprefilled_table_is_prefilled_not_decoded() {
29 let kv_manager = create_shared_kv_manager(64, 16);
30 let config = SchedulerConfig {
31 max_batch_size: 16,
32 max_batch_tokens: 1024,
33 max_prefill_tokens: 512,
34 prefill_chunk_size: 64,
35 chunk_prefill: true,
36 watermark_blocks: 2,
37 };
38 let mut scheduler = AienScheduler::new(config, kv_manager.clone());
39
40 // A swarm-style branch id (slot > 0) whose blocks were allocated and
41 // zeroed by allocate_sequence, but never run through the model.
42 let branch = SequenceId::new(3, 1).unwrap().to_u64();
43 let prompt: Vec<u32> = (10..50).collect();
44 kv_manager
45 .write()
46 .allocate_sequence(branch, &prompt)
47 .expect("allocate");
48
49 scheduler.submit_request(SequenceRequest {
50 request_id: branch,
51 prompt_tokens: prompt.clone(),
52 sampling_params: SamplingParams {
53 temperature: 0.0,
54 top_p: 1.0,
55 max_tokens: 4,
56 stop_token_ids: vec![],
57 },
58 arrival_time_ns: 0,
59 priority: 1,
60 });
61
62 let batch = scheduler
63 .build_scheduled_batch()
64 .expect("schedule")
65 .expect("non-empty batch");
66
67 assert!(
68 !batch.decode_requests.contains(&branch),
69 "PREFILL_GATE_VIOLATION: sequence with allocated-but-uncomputed KV blocks was scheduled for decode"
70 );
71 assert!(
72 batch
73 .prefill_requests
74 .iter()
75 .any(|r| r.request_id == branch && r.prompt_tokens == prompt),
76 "PREFILL_GATE_VIOLATION: sequence with uncomputed KV blocks was not scheduled for prompt prefill"
77 );
78}