pub struct Model { /* private fields */ }Expand description
A compiled, runnable model with by-name weight binding. Available with the
eval feature.
A compiled graph plus its parameter roster — a runnable model.
Bind weights with set / load by name (for an
rlx! graph that name is the param’s @ "…" key or, absent that, its
binding ident), then run. Weight sources that carry extra
tensors (a whole checkpoint) are fine — only the params this model declares
are bound, and unbound reports any it still needs.
let mut m = Model::on(graph, Device::Cpu);
m.load(weights.iter().map(|(k, v)| (k.as_str(), v.as_slice())));
assert!(m.unbound().is_empty(), "missing weights: {:?}", m.unbound());
let out = m.run(&[("input_ids", &ids)]);Implementations§
Source§impl Model
impl Model
Sourcepub fn new(graph: Graph) -> Self
pub fn new(graph: Graph) -> Self
Compile on the fastest backend this build can run the graph on.
Sourcepub fn param_names(&self) -> impl Iterator<Item = &str>
pub fn param_names(&self) -> impl Iterator<Item = &str>
Every parameter name the model expects.
Sourcepub fn unbound(&self) -> Vec<&str>
pub fn unbound(&self) -> Vec<&str>
Parameters not yet bound (in arbitrary order) — check this is empty after
load to catch a missing / misnamed weight loudly.
Sourcepub fn set(&mut self, name: &str, data: &[f32]) -> &mut Self
pub fn set(&mut self, name: &str, data: &[f32]) -> &mut Self
Bind one parameter by name. A name the model doesn’t declare is ignored (so binding straight from a superset checkpoint is safe).
Auto Trait Implementations§
impl !RefUnwindSafe for Model
impl !Sync for Model
impl !UnwindSafe for Model
impl Freeze for Model
impl Send for Model
impl Unpin for Model
impl UnsafeUnpin for Model
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
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