fuse
BNFuser (Protocol)
¶
Type signature of the handers used in fuse_bn.
__call__(self, layer, bn)
special
¶
Fuse batch norm into the previous layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer |
nn.Module |
layers like Conv2d, Linear, etc. |
required |
bn |
nn.Module |
batch norm layer, could be BatchNorm2d, BatchNorm1d, etc. |
required |
Returns:
Type | Description |
---|---|
nn.Module |
fused layer |
Source code in qsparse/fuse.py
14 15 16 17 18 19 20 21 22 23 |
|
conv2d_bn_fuser(conv, bn)
¶
BNFuser for Conv2d
Source code in qsparse/fuse.py
26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
deconv2d_bn_fuser(deconv, bn)
¶
BNFuser for ConvTranspose2d
Source code in qsparse/fuse.py
56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
fuse_bn(model, layers=['Conv2d', 'Linear', 'ConvTranspose2d'], handlers=None, log=True, inplace=True)
¶
Fuse the batch norm layers back to the previous conv/deconv/linear layers in a newtwork.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
nn.Module |
network |
required |
layers |
Iterable[str] |
[description]. Defaults to ["Conv2d", "Linear", "ConvTranspose2d"]. |
['Conv2d', 'Linear', 'ConvTranspose2d'] |
handlers |
Optional[Mapping[str, BNFuser]] |
Mapping from layer type to BNFuser. Defaults to None, will use { Linear: linear_bn_fuser, Conv2d: conv2d_bn_fuser, ConvTranspose2d: deconv2d_bn_fuser }. |
None |
log |
bool |
whether print the fuse log. Defaults to True. |
True |
inplace |
bool |
whether mutates the original module. Defaults to False. |
True |
Returns:
Type | Description |
---|---|
nn.Module |
network with bn fused |
Source code in qsparse/fuse.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
linear_bn_fuser(linear, bn)
¶
BNFuser for Linear
Source code in qsparse/fuse.py
41 42 43 44 45 46 47 48 49 50 51 52 53 |
|