Skip to main content

qualia_core_db/inference/runtime/prepared/
decode_plan.rs

1use super::PreparedPlanState;
2use crate::inference::runtime::receipt::ExecutionCounters;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum PreparedBackend {
6    Wgpu,
7    Cuda,
8    Metal,
9    Cpu,
10}
11
12#[derive(Debug)]
13pub enum DecodeStepError {
14    NotReady(PreparedPlanState),
15    InvalidInput,
16    BackendFailure,
17}
18
19#[derive(Debug)]
20pub struct DecodeStepInput<'a> {
21    pub token_position: u32,
22    pub token_id: u32,
23    pub hidden: &'a mut [f32],
24    pub kv_page_table: &'a [u32],
25}
26
27#[derive(Debug, Clone, Copy, Default, PartialEq)]
28pub struct DecodeStepOutput {
29    pub token_id: u32,
30    pub score: f32,
31}
32
33/// Tier-1 execution contract for an already prepared model/backend pair.
34pub trait PreparedDecodePlan {
35    /// Prepared backend.
36    fn backend(&self) -> PreparedBackend;
37    /// Plan state.
38    fn state(&self) -> PreparedPlanState;
39    /// Execution counters.
40    fn counters(&self) -> ExecutionCounters;
41
42    /// Execute one autoregressive step.
43    ///
44    /// Implementations must not allocate, compile, discover tensors, upload immutable data, or
45    /// select another backend. A failure is returned to the owner, which records any explicit
46    /// fallback outside this call.
47    fn run_decode_step(
48        &mut self,
49        input: DecodeStepInput<'_>,
50        output: &mut DecodeStepOutput,
51    ) -> Result<(), DecodeStepError>;
52}