Skip to main content

Model

Struct Model 

Source
pub struct Model {
    pub spec: LayaSpec,
    pub tensors: Tensors,
    pub graph: LayaGraph,
    pub index: Option<Index>,
    pub metadata: Option<Map<String, Value>>,
    /* private fields */
}
Expand description

A loaded compat model: its spec, its tensors and the graph bound to them.

Fields§

§spec: LayaSpec

Both configs.

§tensors: Tensors

The weights, mapped.

§graph: LayaGraph

The graph, with every weight bound and checked.

§index: Option<Index>

The .kime index, when loaded from one.

§metadata: Option<Map<String, Value>>

__metadata__ of the source safetensors, kept so unpacking gives the same file back.

Implementations§

Source§

impl Model

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Opens a Laya checkpoint directory or a .kime file. Tensor data is mapped, not read, and the .kime model hash is not checked here, see Model::verify.

§Errors

Error::Io for a missing file, Error::Format for a malformed one and Error::Mismatch when the tensors do not match the config.

Source

pub fn file(&self, name: &str) -> Option<&[u8]>

A carried file, such as tokenizer/tokenizer.json.

Source

pub fn file_names(&self) -> Vec<&str>

Names of the carried files.

Source

pub fn verify(&self) -> Result<(), Error>

Checks the .kime model hash against the data. A directory has no hash and always passes.

§Errors

Error::Format if the data has changed since it was packed.

Source

pub fn pack(&self, out: &mut impl Write) -> Result<String, Error>

Packs the model as .kime and returns the model hash.

§Errors

Any error from out.

§Panics

Never. Every name comes from the model’s own file list.

Source

pub fn unpack(&self, dir: &Path) -> Result<(), Error>

Writes the model back out as a Laya directory: model.safetensors plus the carried files. Refuses to write into a directory that already has a model.safetensors.

§Errors

Error::Io on any write failure or an existing checkpoint.

§Panics

Never. Every name comes from the model’s own file list.

Trait Implementations§

Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.