initialize_pai
perforatedai.initialize_pai(model, doing_pai=True, save_name="PAI", making_graphs=True, maximizing_score=True, num_classes=10000000000, values_per_train_epoch=-1, values_per_val_epoch=-1, zooming_graph=True)
Main function to initialize the network to add dendrites.
This kicks off the entire Perforated AI process by adding the scaffolding to the network that enables dendrite addition during training.
Parameters
model (nn.Module) – The neural network model to initialize.
doing_pai (bool, optional) – Whether to actually add dendrites during training. (default: True)
save_name (str, optional) – The name to save the model under. (default: "PAI")
making_graphs (bool, optional) – Whether to create graphs during training. (default: True)
maximizing_score (bool, optional) – Whether to maximize the validation metric. Set to False when the score is a loss to be minimized. (default: True)
Returns
nn.Module – The modified model with dendrite scaffolding added if doing_pai is True.
Examples
>>> import torch.nn as nn
>>> import perforatedai as pai
>>>
>>> # Define your model
>>> model = MyNeuralNetwork()
>>>
>>> # Initialize for PAI training
>>> model = pai.initialize_pai(
>>> model,
>>> doing_pai=True,
>>> save_name="my_experiment",
>>> maximizing_score=True
>>> )
System Management
save_system
perforatedai.save_system(net, folder, name)
Save the entire PAI system. Saves both the network itself and all tracker information for resuming training.
>>> pai.save_system(model, "my_experiment", "checkpoint_epoch_50")
load_system
perforatedai.load_system(net, folder, name, load_from_restart=False, switch_call=False, load_from_manual_save=False)
Load the entire PAI system. Loads a saved system and restarts training from the saved checkpoint.
>>> model = pai.load_system(model, "my_experiment", "best_model")
Utility Functions
convert_network()
Convert network modules to PAI-compatible wrappers according to global configuration.
count_params()
Count the number of parameters in the network, excluding scaffolding parameters.
deep_copy_pai()
Create a deep copy of a PAI network with proper processor clearing.
change_learning_modes()
Switch between neuron and dendrite learning modes for the entire system.
Notes
These utility functions handle the core PAI system operations including network conversion, saving/loading, and mode switching. Most users will primarily interact with initialize_pai(), save_system(), and load_system().