scxpand.util.model_loading#
Unified model loading utilities for scXpand.
This module provides robust, consistent model loading functionality across all model types to prevent silent failures and ensure proper error handling.
Functions
|
Load state dict into model with validation. |
|
Load model parameters from JSON file. |
|
Load model state dictionary from training checkpoint. |
|
Validate that model directory contains required files. |
Exceptions
Custom exception for model loading failures. |
- exception scxpand.util.model_loading.ModelLoadingError#
Custom exception for model loading failures.
- scxpand.util.model_loading.load_and_validate_model(model, model_dir, device, model_name='model')#
Load state dict into model with validation.
- Parameters:
- Return type:
- Returns:
Model with loaded weights in eval mode
- Raises:
ModelLoadingError – If loading fails
RuntimeError – If state dict is incompatible with model
- scxpand.util.model_loading.load_model_parameters(model_dir, param_class, param_file='parameters.json')#
Load model parameters from JSON file.
- Parameters:
- Return type:
- Returns:
Instantiated parameter object
- Raises:
FileNotFoundError – If parameter file doesn’t exist
json.JSONDecodeError – If parameter file is invalid JSON
TypeError – If parameter instantiation fails
- scxpand.util.model_loading.load_model_state_dict(model_dir, device, model_name='model')#
Load model state dictionary from training checkpoint.
This function loads model state dictionary from best_ckpt.pt only. No fallback to legacy files - ensures consistent, reliable model loading.
- Parameters:
- Return type:
- Returns:
Model state dictionary
- Raises:
ModelLoadingError – If no valid model checkpoint is found
FileNotFoundError – If model directory doesn’t exist
RuntimeError – If model loading fails due to corruption or incompatibility
- scxpand.util.model_loading.validate_model_directory(model_dir, required_files)#
Validate that model directory contains required files.
- Parameters:
- Raises:
FileNotFoundError – If directory or required files don’t exist
ValueError – If path is not a directory
- Return type: