Skip to content

Latest commit

 

History

History
43 lines (28 loc) · 1.88 KB

ConvertingToInference.md

File metadata and controls

43 lines (28 loc) · 1.88 KB

Converting to Inference

When training a model with Perforated Backpropagationtm proprietary software and a license is required. However, when a final model is trained and ready to be used, either internaly or in delivery elsewhere, it is not. All saved networks with a _pai.pt suffix are saved in a format where they can be run with only the open source files provided in this API repo. This file is provided to explain how to switch from a training script to an inference script.

What to Keep

All additional network changes from the customization README must be kept. The network does a similar conversion but without the training scaffolding in place. This means it but be notified about everything that should be wrapped in a similar way. This includes the following:

modulesToConvert
ModulesWithProcessing and ModulesProcessingClasses
modulesToReplace

What to Remove

Once the Dendrite training is coplete you will no longer need:

AddValidationScore
AddExtraScore
AddTestScore
PBU.initializePB
custom optimizer and scheduler setup

What to Change

Rather than convertNetwork, you instead will load your pretrained model like so:

model = yourModel()
model = PN.loadPAIModel(model, 'path-to-model_pai.pt')

Optimizer and scheduler should go back to normal

optimArgs = {'params':model.parameters(),'lr':args.lr}
optimizer = optim.Adadelta(**optimArgs)
schedArgs = {'optimizer': optimizer, 'step_size':1, 'gamma': args.gamma}
scheduler = StepLR(**schedArgs)

and add scheduler.step() where it was originally

All imports have copies within this repo. All may be imported, or only the ones you need. pb_network is new, that is required.

from perforatedai import pb_network as PN
from perforatedai import pb_globals as PBG
from perforatedai import pb_models as PBM