556. Now, for the fun part, let's perturb the network during inference, and see what happens! We'll use PyTorchFI to perform an injection on a single neuron.
[3, 224, 224], which is the typical size of an image from the ImageNet dataset. So while it is optional in this tutorial, it is important to ensure the input to your model is specified if it is not ImageNet.
torch.nn.Conv2d. However, you can include any set of layers to perform injections on. Under the hood, PyTorchFI will only append
hooksto the layers specified. If you want to include all layers, you can simple use
"all"in the list of layer types. For example, the following are some various ways to initialize PyTorchFI
layer_types = [torch.nn.Conv2d]
layer_types = [torch.nn.Conv2d, torch.nn.Linear]
layer_types = [torch.nn.Linear]
layer_types = ["all"]
fault_injection(...), PyTorchFI will setup a few internal data structures and profile your network to assist with bounds checking during error injections. To print out what PyTorchFI "sees" after the initialization, you can run
[1, 64, 55, 55], which corresponds to the
[batch, C, H, W]size.
layer_typesprovided. In other words, the Layer # specified by the
print_pytorch_fi_summary()is the number that will be used to ID the layer in PyTorchFI.
declare_weight_fi(...)). We then need to pass in the location of the error, which are specified by the args:
value, if it is independent
function, if it is dependent
10000in batch element
0, in layer
2at the tensor location
[4, 2, 4](corresponding to CHW).
mul_neg_onethat multiplies everything by -1:
fault_injectionclass to provide our own method. The new method has a very specific signature: it must be similar to the
hooksignature defined by PyTorch. Specifically, it requires the arguments
outputhowever you wish. In the example above, we multiplied the entire tensor by -1. For a more nuanced example, take a look at the
core. In particular, the first half of the method deals with extracting the location of an error using the same methodology as a Value-based error injection. In other words, it allows you to specify the CHW location, while performing its own perturbation inside the function.
updateLayer(...). We use this to internally keep track of which layer the model is in during inference for error injections.
zero_func_random_weightin weight_error_models.py. Note that for custom weight functions, you do not need to extend
updateLayer()function - weight injections are much simpler.