ModelConfig

Struct ModelConfig 

Source
pub struct ModelConfig {
    pub model_info: ModelInfo,
    pub shapes: ShapeConfig,
    pub components: HashMap<String, ComponentConfig>,
    pub naming: NamingConfig,
    pub ffn_execution: Option<String>,
}
Expand description

Complete model configuration including shapes, components, and naming patterns

Fields§

§model_info: ModelInfo§shapes: ShapeConfig§components: HashMap<String, ComponentConfig>§naming: NamingConfig§ffn_execution: Option<String>

Execution mode for FFN: “unified” (single component/function) or “split” (separate prefill/infer components)

Implementations§

Source§

impl ModelConfig

Source

pub fn default_qwen() -> Self

Create a minimal default Qwen ModelConfig (no components). Useful for tests and fallbacks.

Source

pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>

Load configuration from a JSON file

Source

pub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>

Save configuration to a JSON file

Source

pub fn get_tensor_shape( &self, component: &str, tensor_name: &str, is_input: bool, ) -> Option<&Vec<usize>>

Get the shape configuration for a specific component and tensor

Source

pub fn embeddings_input_shape(&self) -> Option<&Vec<usize>>

Get the expected input shape for embeddings

Source

pub fn embeddings_output_shape(&self) -> Option<&Vec<usize>>

Get the expected output shape for embeddings

Source

pub fn ffn_prefill_input_shape(&self) -> Option<&Vec<usize>>

Get the expected input shape for FFN prefill

Source

pub fn lm_head_input_shape(&self) -> Option<&Vec<usize>>

Get the expected input shape for LM head

Source

pub fn has_multipart_logits(&self) -> bool

Check if this model supports multi-part logits output

Source

pub fn logits_part_count(&self) -> usize

Get the number of logits parts for multi-part output

Source

pub fn lm_head_primary_output_name(&self) -> Option<String>

Select the primary logits output name for the LM head. Preference order: “logits1” (multipart), then “logits”, otherwise the first available key.

Source

pub fn validate(&self) -> Result<()>

Validate the configuration for consistency

Source

pub fn validate_internal_wiring(&self) -> Result<()>

Validate internal wiring between components for basic shape compatibility. Examples:

  • embeddings.outputs.hidden_states == ffn_prefill.inputs.hidden_states
  • ffn_infer.outputs.output_hidden_states == lm_head.inputs.hidden_states (when ffn_infer exists)
Source

pub fn ffn_is_split(&self) -> bool

Determine if FFN execution should be treated as split (separate infer component)

Source

pub fn prefill_is_single_token(&self) -> bool

Detect if prefill should run in single-token sequential mode based on configured shapes

Source

pub fn expects_full_sequence_prefill(&self) -> bool

Check if the model expects full sequence prefill (as opposed to single-token processing) This is typically true for CoreML models with fixed-shape inputs like [1, 128, 1024]

Source

pub fn create_embeddings_input_tensor( &self, tokens: &[i64], device: &Device, ) -> Result<Tensor, CandleError>

Create embeddings input tensor with proper shape from configuration

Source

pub fn create_ffn_position_ids_tensor( &self, positions: &[i64], device: &Device, ) -> Result<Tensor, CandleError>

Create position IDs tensor for FFN prefill with proper shape

Source

pub fn create_ffn_causal_mask_tensor( &self, _batch_size: usize, _context_length: usize, device: &Device, ) -> Result<Tensor, CandleError>

Create causal mask tensor for FFN with proper shape

Source

pub fn create_single_token_hidden_states( &self, _tokens: &[i64], device: &Device, ) -> Result<Tensor, CandleError>

Create single token hidden states tensor for LM head

Source

pub fn create_infer_position_ids_tensor( &self, position: i64, device: &Device, ) -> Result<Tensor, CandleError>

Create position IDs tensor for inference (single position)

Source

pub fn create_current_pos_tensor( &self, position: i64, device: &Device, ) -> Result<Tensor, CandleError>

Create current position tensor for FFN

Trait Implementations§

Source§

impl Clone for ModelConfig

Source§

fn clone(&self) -> ModelConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ModelConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ModelConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> ErasedDestructor for T
where T: 'static,