Trait KnownModel

Source
pub trait KnownModel: Send + Sync {
    type Hyperparameters: Hyperparameters;

    // Required methods
    fn new<E: Error>(
        hyperparameters: Self::Hyperparameters,
        params: ModelParameters,
        vocabulary: Vocabulary,
        tensor_loader: impl TensorLoader<E>,
    ) -> Result<Self, E>
       where Self: Sized;
    fn start_session(&self, config: InferenceSessionConfig) -> InferenceSession;
    fn evaluate(
        &self,
        session: &mut InferenceSession,
        params: &InferenceParameters,
        input_tokens: &[TokenId],
        output_request: &mut OutputRequest,
    );
    fn vocabulary(&self) -> &Vocabulary;
    fn n_context_tokens(&self) -> usize;
    fn bot_token_id(&self) -> Option<TokenId>;
    fn eot_token_id(&self) -> TokenId;
    fn inference_parameters(&self) -> &InferenceParameters;
}
Expand description

Interfaces for creating and interacting with a large language model with a known type of hyperparameters.

Required Associated Types§

Source

type Hyperparameters: Hyperparameters

Hyperparameters for the model

Required Methods§

Source

fn new<E: Error>( hyperparameters: Self::Hyperparameters, params: ModelParameters, vocabulary: Vocabulary, tensor_loader: impl TensorLoader<E>, ) -> Result<Self, E>
where Self: Sized,

Creates a new model from the provided ModelParameters hyperparameters. This function is called by the load function.

Source

fn start_session(&self, config: InferenceSessionConfig) -> InferenceSession

Starts a new InferenceSession for this model.

Source

fn evaluate( &self, session: &mut InferenceSession, params: &InferenceParameters, input_tokens: &[TokenId], output_request: &mut OutputRequest, )

This function is called by the provided InferenceSession; it will use this model and the InferenceParameters to generate output by evaluating the input_tokens. The OutputRequest is used to specify additional data to fetch from the model.

Source

fn vocabulary(&self) -> &Vocabulary

Get the vocabulary (loaded from the GGML file) for this model.

Source

fn n_context_tokens(&self) -> usize

Get the context size (configured with ModelParameters::n_context_tokens) used by this model.

Source

fn bot_token_id(&self) -> Option<TokenId>

Get the beginning of text/beginning of string token ID, if available. This value is defined by model implementers.

Source

fn eot_token_id(&self) -> TokenId

Get the end of text/end of string token ID. This value is defined by model implementers.

Source

fn inference_parameters(&self) -> &InferenceParameters

Get the default InferenceParameters for this model (used by InferenceSession::infer). This value is configured through ModelParameters::inference_parameters.

Implementors§