pub trait Model: Send + Sync {
type Config: ModelConfig;
// Required methods
fn new(config: Self::Config) -> Result<Self>
where Self: Sized;
fn from_weights(config: Self::Config, weights: ModelWeights) -> Result<Self>
where Self: Sized;
fn forward(&self, inputs: &ModelInputs) -> Result<ModelOutputs>;
fn generate(
&self,
prompt: &str,
config: &GenerationConfig,
) -> Result<String>;
fn config(&self) -> &Self::Config;
fn memory_requirements(&self) -> MemoryRequirements;
fn to_device(&mut self, device: &Device) -> Result<()>;
}Expand description
Core model trait - the single interface all models implement
Required Associated Types§
Sourcetype Config: ModelConfig
type Config: ModelConfig
Model configuration type
Required Methods§
Sourcefn from_weights(config: Self::Config, weights: ModelWeights) -> Result<Self>where
Self: Sized,
fn from_weights(config: Self::Config, weights: ModelWeights) -> Result<Self>where
Self: Sized,
Load model with weights
Sourcefn forward(&self, inputs: &ModelInputs) -> Result<ModelOutputs>
fn forward(&self, inputs: &ModelInputs) -> Result<ModelOutputs>
Forward pass - core inference method
Sourcefn generate(&self, prompt: &str, config: &GenerationConfig) -> Result<String>
fn generate(&self, prompt: &str, config: &GenerationConfig) -> Result<String>
Generate text (high-level interface)
Sourcefn memory_requirements(&self) -> MemoryRequirements
fn memory_requirements(&self) -> MemoryRequirements
Get model memory requirements
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".