pub struct Kime { /* private fields */ }Expand description
A loaded model on a device. Clones share it, and it can be used from any thread.
Implementations§
Source§impl Kime
impl Kime
Sourcepub fn model_id(&self) -> &str
pub fn model_id(&self) -> &str
The model’s name, laya or laya-multilingual for the published checkpoints.
Sourcepub fn max_row_tokens(&self) -> usize
pub fn max_row_tokens(&self) -> usize
The most tokens one question’s row can hold: the state, the question and its options. Longer states are cut to fit.
Sourcepub fn memory(&self) -> Memory
pub fn memory(&self) -> Memory
The bytes the model holds on its device, as of the last forward pass.
Sourcepub fn count_tokens(&self, req: &Request) -> usize
pub fn count_tokens(&self, req: &Request) -> usize
The tokens a request holds before anything is cut: its state once plus every question with its options. The server refuses a request over its limit with this count, before it is queued.
Sourcepub fn decide(&self, req: &Request) -> Result<Response, Error>
pub fn decide(&self, req: &Request) -> Result<Response, Error>
Answers one request.
§Errors
Error::Invalid for a request that does not validate, Error::TooLong for a question
whose options do not fit, and device errors.
Sourcepub fn decide_batch(&self, reqs: &[Request]) -> Result<Vec<Response>, Error>
pub fn decide_batch(&self, reqs: &[Request]) -> Result<Vec<Response>, Error>
Answers many requests, packing all their questions into as few device batches as fit. Each answer is the same bits it would be alone, whatever else is in the batch.
§Errors
As Kime::decide. One bad request fails the whole call.
Sourcepub fn decide_batch_timed(
&self,
reqs: &[Request],
) -> Result<(Vec<Response>, Timing), Error>
pub fn decide_batch_timed( &self, reqs: &[Request], ) -> Result<(Vec<Response>, Timing), Error>
Sourcepub fn decide_async(&self, req: &Request) -> Decision ⓘ
pub fn decide_async(&self, req: &Request) -> Decision ⓘ
Kime::decide on a thread of its own, for async callers. It works with any executor,
since it needs nothing from one but a waker.