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
impl ModelConfig
Sourcepub fn default_qwen() -> Self
pub fn default_qwen() -> Self
Create a minimal default Qwen ModelConfig (no components). Useful for tests and fallbacks.
Sourcepub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load configuration from a JSON file
Sourcepub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn save_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
Save configuration to a JSON file
Sourcepub fn get_tensor_shape(
&self,
component: &str,
tensor_name: &str,
is_input: bool,
) -> Option<&Vec<usize>>
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
Sourcepub fn embeddings_input_shape(&self) -> Option<&Vec<usize>>
pub fn embeddings_input_shape(&self) -> Option<&Vec<usize>>
Get the expected input shape for embeddings
Sourcepub fn embeddings_output_shape(&self) -> Option<&Vec<usize>>
pub fn embeddings_output_shape(&self) -> Option<&Vec<usize>>
Get the expected output shape for embeddings
Sourcepub fn ffn_prefill_input_shape(&self) -> Option<&Vec<usize>>
pub fn ffn_prefill_input_shape(&self) -> Option<&Vec<usize>>
Get the expected input shape for FFN prefill
Sourcepub fn lm_head_input_shape(&self) -> Option<&Vec<usize>>
pub fn lm_head_input_shape(&self) -> Option<&Vec<usize>>
Get the expected input shape for LM head
Sourcepub fn has_multipart_logits(&self) -> bool
pub fn has_multipart_logits(&self) -> bool
Check if this model supports multi-part logits output
Sourcepub fn logits_part_count(&self) -> usize
pub fn logits_part_count(&self) -> usize
Get the number of logits parts for multi-part output
Sourcepub fn lm_head_primary_output_name(&self) -> Option<String>
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.
Sourcepub fn validate_internal_wiring(&self) -> Result<()>
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)
Sourcepub fn ffn_is_split(&self) -> bool
pub fn ffn_is_split(&self) -> bool
Determine if FFN execution should be treated as split (separate infer component)
Sourcepub fn prefill_is_single_token(&self) -> bool
pub fn prefill_is_single_token(&self) -> bool
Detect if prefill should run in single-token sequential mode based on configured shapes
Sourcepub fn expects_full_sequence_prefill(&self) -> bool
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]
Sourcepub fn create_embeddings_input_tensor(
&self,
tokens: &[i64],
device: &Device,
) -> Result<Tensor, CandleError>
pub fn create_embeddings_input_tensor( &self, tokens: &[i64], device: &Device, ) -> Result<Tensor, CandleError>
Create embeddings input tensor with proper shape from configuration
Sourcepub fn create_ffn_position_ids_tensor(
&self,
positions: &[i64],
device: &Device,
) -> Result<Tensor, CandleError>
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
Sourcepub fn create_ffn_causal_mask_tensor(
&self,
_batch_size: usize,
_context_length: usize,
device: &Device,
) -> Result<Tensor, CandleError>
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
Create single token hidden states tensor for LM head
Sourcepub fn create_infer_position_ids_tensor(
&self,
position: i64,
device: &Device,
) -> Result<Tensor, CandleError>
pub fn create_infer_position_ids_tensor( &self, position: i64, device: &Device, ) -> Result<Tensor, CandleError>
Create position IDs tensor for inference (single position)
Sourcepub fn create_current_pos_tensor(
&self,
position: i64,
device: &Device,
) -> Result<Tensor, CandleError>
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
impl Clone for ModelConfig
Source§fn clone(&self) -> ModelConfig
fn clone(&self) -> ModelConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ModelConfig
impl Debug for ModelConfig
Source§impl<'de> Deserialize<'de> for ModelConfig
impl<'de> Deserialize<'de> for ModelConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ModelConfig
impl RefUnwindSafe for ModelConfig
impl Send for ModelConfig
impl Sync for ModelConfig
impl Unpin for ModelConfig
impl UnsafeUnpin for ModelConfig
impl UnwindSafe for ModelConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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