pub struct QwenExpert { /* private fields */ }Expand description
A safety expert logit source for contrastive steering (ADR-013): a second
Qwen engine — in production base + a safety LoRA; here any same-tokenizer Qwen
GGUF — loaded through the ADR-006 provenance gate and primed with the turn’s
prompt so its logits align with the base engine’s. The session feeds it the
committed tokens via ExpertLogits::logits.
The weights are loaded once and kept resident like the base model
(ADR-018 expert persistence): the provider holds it across turns and calls
reprime per turn (reset_cache + prefill, no disk reload).
State lives behind a Mutex (not RefCell/Cell) so the resident expert is
Send + Sync and can sit in the Send + Sync provider.
Steering is bounded to the early-token window (ADR-013), so the expert runs
only for the first steer_window tokens. When the base engine rolls back
(committed output shrinks), the expert re-primes to the prompt and
re-feeds the retained prefix, so its contrastive context stays aligned with
the base rather than serving logits from the abandoned branch. Pointing this
at the chat model itself yields ~zero contrast (a no-op); a safety-tuned Qwen
GGUF gives real steering.
Implementations§
Source§impl QwenExpert
impl QwenExpert
Sourcepub fn from_path_primed(
path: impl AsRef<Path>,
eos: Token,
prompt: &[Token],
permit: LoadPermit,
) -> Result<Self>
pub fn from_path_primed( path: impl AsRef<Path>, eos: Token, prompt: &[Token], permit: LoadPermit, ) -> Result<Self>
Load the expert GGUF, gate it (ADR-006 — permit is required, not
optional), and prime it with prompt so its KV state matches the base
engine’s post-prefill state.
Sourcepub fn reprime(&self, prompt: &[Token]) -> Result<()>
pub fn reprime(&self, prompt: &[Token]) -> Result<()>
Re-prime the resident expert to a new turn’s prompt without reloading
the GGUF (ADR-018 expert persistence): discard the prior turn’s KV and
prefill the new prompt on the same loaded weights. The expensive part —
reading + parsing the GGUF — happens once in from_path_primed; this only
re-runs the (cheap, bounded) prompt prefill.
Trait Implementations§
Source§impl ExpertLogits for QwenExpert
impl ExpertLogits for QwenExpert
Auto Trait Implementations§
impl !Freeze for QwenExpert
impl RefUnwindSafe for QwenExpert
impl Send for QwenExpert
impl Sync for QwenExpert
impl Unpin for QwenExpert
impl UnsafeUnpin for QwenExpert
impl UnwindSafe for QwenExpert
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more