Overview
The hardware simulation module allows you to test neural network models under realistic hardware constraints such as memory limits, compute speed factors, and reduced precision modes.HardwareSimulationConfig
Dataclass for configuring hardware simulation parameters.Fields
Whether hardware simulation is active.
Maximum memory available in megabytes.
Simulated compute slowdown factor. Values > 1.0 add artificial delays.
Precision mode for computation. Options:
float32, float16, int8.Maximum allowed batch size.
Example
Memory Estimation Functions
estimate_parameter_memory_mb
Estimates the memory required for model parameters. Parameters:model(object): Neural network model withlayersattributeprecision_mode(str): One offloat32,float16,int8
estimate_activation_memory_mb
Estimates the memory required for activations during forward pass. Parameters:model(object): Neural network model withlayer_sizesattributebatch_size(int): Batch size for estimationprecision_mode(str): One offloat32,float16,int8
estimate_total_memory_mb
Estimates total memory (parameters + activations). Parameters:model(object): Neural network modelbatch_size(int): Batch sizeprecision_mode(str): Precision mode
Constraint Functions
adjust_batch_size_to_memory
Automatically reduces batch size to fit within memory constraints. Parameters:model(object): Neural network modelrequested_batch_size(int): Desired batch sizemax_memory_mb(float): Memory limit in MBprecision_mode(str): Precision modebatch_size_limit(int): Maximum allowed batch size
apply_precision_constraint
Applies precision mode constraint to a model. Parameters:model(object): Neural network modelprecision_mode(str): Target precision mode
apply_compute_slowdown
Simulates slower hardware by adding artificial delays. Parameters:elapsed_seconds(float): Actual elapsed timecompute_speed_factor(float): Slowdown multiplier
Training with Constraints
prepare_hardware_constrained_run
Prepares a model for hardware-constrained execution. Parameters:model(object): Neural network modelrequested_batch_size(int): Desired batch sizesimulation_config(HardwareSimulationConfig): Simulation configuration
enabled: Whether simulation is activebatch_size: Adjusted batch sizeprecision_mode: Applied precision modeestimated_memory_mb: Projected memory usagewarnings: List of constraint warnings
run_training_with_hardware_constraints
Runs model training under hardware constraints. Parameters:model(object): Neural network modelX(array): Training featuresy(array): Training labelsepochs(int): Number of epochsalpha(float): Learning ratebatch_size(int): Requested batch sizeseed(int): Random seedsimulation_config(HardwareSimulationConfig): Hardware configuration
setup: Hardware setup detailstraining_time_s: Actual training timeartificial_delay_s: Added delay from slowdowneffective_time_s: Total simulated timefinal_accuracy: Final training accuracyfinal_loss: Final loss value
Utility Functions
config_from_precision_config
Creates a HardwareSimulationConfig from a precision config object. Parameters:precision_config(object): Config object with hardware attributes
save_hardware_log
Saves hardware simulation logs to JSON. Parameters:log_payload(dict): Log data withsimulation_configandresultsoutput_dir(str): Output directoryfilename(str): Output filename