Skip to main content

ContrastiveSteerer

Struct ContrastiveSteerer 

Source
pub struct ContrastiveSteerer<E>
where E: ExpertLogits,
{ /* private fields */ }
Expand description

SafetyMode::SecDecoding (or model-backed Lightweight) steerer (ADR-013): a hard-ban layer applied every step plus contrastive soft steering from an ExpertLogits source applied only when the runtime supplies base logits (i.e. inside the early-token window). With no expert divergence it reduces to the hard-ban behaviour of LightweightFilter; with no bans and a flat expert it is a no-op.

Implementations§

Source§

impl<E> ContrastiveSteerer<E>
where E: ExpertLogits,

Source

pub fn new( expert: E, banned: Vec<u32>, alpha_milli: i32, top_k: usize, mode: SafetyMode, ) -> ContrastiveSteerer<E>

mode is the tier label reported to telemetry (Lightweight for a LoRA expert, SecDecoding for a contrastive base+expert pair).

Trait Implementations§

Source§

impl<E> SafetySteerer for ContrastiveSteerer<E>
where E: ExpertLogits,

Source§

fn adjust(&self, _recent: &[u32]) -> LogitAdjustment

Out-of-window / token-only path: hard bans only (no expert forward).

Source§

fn adjust_with_logits( &self, recent: &[u32], base_logits: &[i32], ) -> LogitAdjustment

In-window path: hard bans plus contrastive soft steering. Bans are listed first, so a token that is both banned and steered keeps the hard ban (delta_for returns the first match).

Source§

fn mode(&self) -> SafetyMode

Auto Trait Implementations§

§

impl<E> Freeze for ContrastiveSteerer<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for ContrastiveSteerer<E>
where E: RefUnwindSafe,

§

impl<E> Send for ContrastiveSteerer<E>
where E: Send,

§

impl<E> Sync for ContrastiveSteerer<E>
where E: Sync,

§

impl<E> Unpin for ContrastiveSteerer<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for ContrastiveSteerer<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for ContrastiveSteerer<E>
where E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.