# composer.algorithms.blurpool.blurpool#

composer.algorithms.blurpool.blurpool

Functions

 apply_blurpool Add anti-aliasing filters to the strided torch.nn.Conv2d and/or torch.nn.MaxPool2d modules within model.

Classes

 Algorithm Base class for algorithms. BlurConv2d This module is a drop-in replacement for PyTorch's Conv2d, but with an anti-aliasing filter applied. BlurMaxPool2d This module is a (nearly) drop-in replacement for PyTorch's MaxPool2d, but with an anti- aliasing filter applied. BlurPool BlurPool adds anti-aliasing filters to convolutional layers to increase accuracy and invariance to small shifts in the input. Event Enum to represent events in the training loop. Logger An interface to record training data. Optimizer Base class for all optimizers. State The state of the trainer.

Exceptions

 NoEffectWarning Warns when an algorithm did not have an effect.

Attributes

• Optional

• Sequence

• Union

• annotations

• log

class composer.algorithms.blurpool.blurpool.BlurPool(replace_convs=True, replace_maxpools=True, blur_first=True, min_channels=16)[source]#

BlurPool adds anti-aliasing filters to convolutional layers to increase accuracy and invariance to small shifts in the input.

Runs on INIT.

Parameters
• replace_convs (bool) – replace strided torch.nn.Conv2d modules with BlurConv2d modules. Default: True.

• replace_maxpools (bool) – replace eligible torch.nn.MaxPool2d modules with BlurMaxPool2d modules. Default: True.

• blur_first (bool) – when replace_convs is True, blur input before the associated convolution. When set to False, the convolution is applied with a stride of 1 before the blurring, resulting in significant overhead (though more closely matching the paper). See BlurConv2d for further discussion. Default: True.

• min_channels (int, optional) – Skip replacing layers with in_channels < min_channels. Commonly used to prevent the blurring of the first layer. Default: 16.

apply(event, state, logger)[source]#

Adds anti-aliasing filters to the maxpools and/or convolutions.

Parameters
• event (Event) – the current event

• state (State) – the current trainer state

• logger (Logger) – the training logger

match(event, state)[source]#

Runs on INIT.

Parameters
• event (Event) – The current event.

• state (State) – The current state.

Returns

bool – True if this algorithm should run now.

composer.algorithms.blurpool.blurpool.apply_blurpool(model, replace_convs=True, replace_maxpools=True, blur_first=True, min_channels=16, optimizers=None)[source]#

Add anti-aliasing filters to the strided torch.nn.Conv2d and/or torch.nn.MaxPool2d modules within model.

These filters increase invariance to small spatial shifts in the input (Zhang 2019).

Parameters
• model (torch.nn.Module) – the model to modify in-place

• replace_convs (bool, optional) – replace strided torch.nn.Conv2d modules with BlurConv2d modules. Default: True.

• replace_maxpools (bool, optional) – replace eligible torch.nn.MaxPool2d modules with BlurMaxPool2d modules. Default: True.

• blur_first (bool, optional) – for replace_convs, blur input before the associated convolution. When set to False, the convolution is applied with a stride of 1 before the blurring, resulting in significant overhead (though more closely matching the paper). See BlurConv2d for further discussion. Default: True.

• min_channels (int, optional) – Skip replacing layers with in_channels < min_channels. Commonly used to prevent the blurring of the first layer. Default: 16.

• optimizers (torch.optim.Optimizer | Sequence[torch.optim.Optimizer], optional) –

Existing optimizers bound to model.parameters(). All optimizers that have already been constructed with model.parameters() must be specified here so they will optimize the correct parameters.

If the optimizer(s) are constructed after calling this function, then it is safe to omit this parameter. These optimizers will see the correct model parameters.

Returns

The modified model

Example

import composer.functional as cf
from torchvision import models
model = models.resnet50()
cf.apply_blurpool(model)
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2394297569990158, "perplexity": 21783.54833785293}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-27/segments/1656103922377.50/warc/CC-MAIN-20220701064920-20220701094920-00323.warc.gz"}