PopTorch optimizes performance by embedding constant attributes directly in the program.
For poptorch.optim optimizers:
- Attributes passed to the constructor are treated as variables by default.
- Other attributes are treated as constants.
- You can override this using
poptorch.optim.VariableAttributes.markAsConstant or poptorch.optim.VariableAttributes.markAsVariable before model compilation. - Warning: Modifying a constant attribute after compilation results in an error.
For native torch.optim optimizers:
- Attributes left at their default values are treated as constants. There is no way to override this behavior, so it is recommended to use
poptorch.optim instead.
# Constant and variable attributes for PopTorch optimizers
optimizer = poptorch.optim.Adam(model.parameters(), lr=0.01)
optimizer.markAsConstant('lr') # This would make lr a constant