pub struct ProstT5Translator { /* private fields */ }Expand description
ProstT5, wrapped for greedy translation.
§Why the model sits behind a Mutex, and why it matters more here
T5Runner also holds its model in a Mutex,
but there it guards nothing: T5Attention::load sets
use_cache: cfg.use_cache && decoder, and an encoder stack loads with
decoder = false, so the encoder never caches.
The decoder does. Every decode step appends to a per-layer KV cache,
which is what makes incremental generation fast — and what makes a stale
cache dangerous: the next translation would concatenate its keys onto the
previous one’s and produce a fluent, wrong answer with no error. So
translate clears the cache before it starts, and
test_repeated_translation_is_deterministic fails if that is ever removed.
Implementations§
Source§impl ProstT5Translator
impl ProstT5Translator
Sourcepub fn from_pretrained(model: ProstT5Models, device: Device) -> Result<Self>
pub fn from_pretrained(model: ProstT5Models, device: Device) -> Result<Self>
Load from the hub at the checkpoint’s published precision (F16).
Sourcepub fn from_pretrained_with(
model: ProstT5Models,
opts: &LoadOptions,
) -> Result<Self>
pub fn from_pretrained_with( model: ProstT5Models, opts: &LoadOptions, ) -> Result<Self>
Load with an explicit device and dtype.
Sourcepub fn translate(&self, sequence: &str, direction: Direction) -> Result<String>
pub fn translate(&self, sequence: &str, direction: Direction) -> Result<String>
Translate sequence between the amino-acid and 3Di alphabets.
Greedy decoding, which is what ProstT5’s own usage does: the mapping is close to deterministic and sampling would only add noise to a structural annotation.
ProstT5’s translation is length-preserving: one output token per
input residue. Length, not </s>, is therefore the stopping criterion,
and the EOS logit is suppressed at every step — which is exactly what
Rostlab’s own inference does by passing min_length == max_length to
generate, and what HuggingFace implements as MinLengthLogitsProcessor.
Breaking on </s> instead would silently return a truncated structure
for any sequence where the model wanted to stop early, and would
disagree with the reference on exactly those cases.
Sourcepub fn to_saprot_input(&self, sequence: &str) -> Result<String>
pub fn to_saprot_input(&self, sequence: &str) -> Result<String>
Translate sequence and weave the result back into SaProt’s input form
(ferritin-goh.13).
This is the pair that removes the Foldseek C++ dependency from the structure-aware path: ProstT5 predicts the 3Di states that SaProt would otherwise need Foldseek to compute from a real structure.
"MQIFVKTLTGK" -> 3Di "dvvvvcvvvvd" -> "MdQvIvFvVvKcTvLvTvGvKd"Note what this is and is not: the 3Di states are predicted from sequence, not measured from a structure. That is the point — it works without a structure at all — but a SaProt embedding built this way is not interchangeable with one built from an experimental backbone.
Residues outside SaProt’s 20 become #; see
interleave.
Auto Trait Implementations§
impl !Freeze for ProstT5Translator
impl RefUnwindSafe for ProstT5Translator
impl Send for ProstT5Translator
impl Sync for ProstT5Translator
impl Unpin for ProstT5Translator
impl UnsafeUnpin for ProstT5Translator
impl UnwindSafe for ProstT5Translator
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