metrale_model_engine/model/trait_impl/
impl_ep.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-26: `impl ModelEp for TransformerModel`, mostly delegating to `<method>_dispatch`
4//! helpers in the sibling modules.
5//!
6//! Owner: model-engine.
7//! Invariants: the ones in `trait_impl/mod.rs`.
8
9use anyhow::Result;
10
11use crate::model::types::TransformerModel;
12use crate::traits::{ModelEp, SequenceState};
13
14impl ModelEp for TransformerModel {
15    fn ep_worker_step(&self, slots: &mut [Option<SequenceState>]) -> Result<bool> {
16        self.gdn_carry_flush_pending()?;
17        self.ep_worker_step_dispatch(slots)
18    }
19
20    fn is_ep(&self) -> bool {
21        self.is_ep_dispatch()
22    }
23
24    fn ep_broadcast_cmd(&self, cmd: u32) -> Result<()> {
25        self.ep_broadcast_cmd_dispatch(cmd)
26    }
27
28    fn ep_broadcast_cmd_for_seq(&self, seq_id: u32, cmd: u32) -> Result<()> {
29        // 2026-09-25: `ep_protocol_v2` is set at construction from
30        // `METRALE_EP_PROTOCOL=v2`.
31        self.ep_broadcast_seq_and_cmd(seq_id, cmd, self.ep_protocol_v2)
32    }
33
34    fn ep_protocol_v2(&self) -> bool {
35        self.ep_protocol_v2
36    }
37
38    fn ep_broadcast_tokens(&self, tokens: &[u32]) -> Result<Vec<u32>> {
39        self.ep_broadcast_tokens_dispatch(tokens)
40    }
41}