pub struct T5Runner { /* private fields */ }Expand description
A T5 encoder wrapped for PlmRunner.
§Why the model sits behind a Mutex
T5EncoderModel::forward takes &mut self, because the same T5Attention
code serves the decoder, where it maintains a KV cache. PlmRunner::embed
takes &self, and widening the trait to &mut self would make every
runner harder to share across threads for the sake of one model.
The encoder does not actually cache. T5Attention::load sets
use_cache: cfg.use_cache && decoder, and T5EncoderModel::load builds its
stack with decoder = false, so the cache branch is dead on this path
whatever config.json says. load_config also forces use_cache: false
so the guarantee does not depend on a detail of candle’s internals, and
test_repeated_embed_is_deterministic fails if a future candle version
starts carrying state across calls.
So the Mutex buys the &mut the signature demands while keeping the
runner Send + Sync, and it is uncontended in the sense that matters: there
is no state to protect. It does serialise concurrent embed calls on one
runner, which is a real cost — clone the runner per thread if that bites.
Implementations§
Source§impl T5Runner
impl T5Runner
Sourcepub fn from_pretrained(model: T5Models, device: Device) -> Result<Self>
pub fn from_pretrained(model: T5Models, device: Device) -> Result<Self>
Load from the hub at the checkpoint’s own published precision.
See T5Models::published_dtype: F16 for ProtT5, F32 for Ankh. Use
from_pretrained_with to override.
Sourcepub fn from_pretrained_with(model: T5Models, opts: &LoadOptions) -> Result<Self>
pub fn from_pretrained_with(model: T5Models, opts: &LoadOptions) -> Result<Self>
Load with an explicit device and dtype.
Trait Implementations§
Source§impl PlmRunner for T5Runner
impl PlmRunner for T5Runner
Source§fn embed(&self, sequence: &str) -> Result<Tensor>
fn embed(&self, sequence: &str) -> Result<Tensor>
Run the T5 encoder and return per-token hidden states.
Shape: (1, L + 1, d_model) — the trailing </s> row is included, and
there is no BOS row.
Source§fn special_tokens(&self) -> SpecialTokenLayout
fn special_tokens(&self) -> SpecialTokenLayout
ProtT5 appends </s> and prepends nothing: T5’s
build_inputs_with_special_tokens is ids + [eos], and the vocabulary
has no BOS piece at all.
Every other runner in the crate is BOS_EOS, which is exactly why the
layout is declared rather than assumed — reading a ProtT5 embedding as
if row 0 were a BOS token shifts every residue by one.
Source§fn residue_count(&self, sequence: &str) -> usize
fn residue_count(&self, sequence: &str) -> usize
Whitespace is not a residue: "M K T" is three residues, not five.
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Source§fn metadata(&self) -> ModelMetadata
fn metadata(&self) -> ModelMetadata
Source§fn embed_residues(&self, sequence: &str) -> Result<Tensor>
fn embed_residues(&self, sequence: &str) -> Result<Tensor>
Source§fn logits(&self, _sequence: &str) -> Result<Tensor>
fn logits(&self, _sequence: &str) -> Result<Tensor>
Auto Trait Implementations§
impl !Freeze for T5Runner
impl RefUnwindSafe for T5Runner
impl Send for T5Runner
impl Sync for T5Runner
impl Unpin for T5Runner
impl UnsafeUnpin for T5Runner
impl UnwindSafe for T5Runner
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,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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