(padding, padding_mode)
| 141 | ], |
| 142 | ) |
| 143 | def test_qat_conv(padding, padding_mode): |
| 144 | |
| 145 | in_channels = 32 |
| 146 | out_channels = 64 |
| 147 | kernel_size = 3 |
| 148 | |
| 149 | class TestNet(Module): |
| 150 | def __init__(self, groups, bias): |
| 151 | super().__init__() |
| 152 | self.quant = QuantStub() |
| 153 | self.dequant = DequantStub() |
| 154 | self.conv = Conv2d( |
| 155 | in_channels, |
| 156 | out_channels, |
| 157 | kernel_size, |
| 158 | groups=groups, |
| 159 | bias=bias, |
| 160 | padding=padding, |
| 161 | padding_mode=padding_mode, |
| 162 | ) |
| 163 | self.conv_relu = ConvRelu2d( |
| 164 | out_channels, in_channels, kernel_size, groups=groups, bias=bias |
| 165 | ) |
| 166 | |
| 167 | def forward(self, inp): |
| 168 | out = self.quant(inp) |
| 169 | out = self.conv(out) |
| 170 | out = self.conv_relu(out) |
| 171 | out = self.dequant(out) |
| 172 | return out |
| 173 | |
| 174 | inputs = tensor(np.random.randn(4, in_channels, 32, 32).astype(np.float32)) |
| 175 | for groups, bias in product([1, 4], [True, False]): |
| 176 | net = TestNet(groups, bias) |
| 177 | net.train() |
| 178 | qat_net = quantize_qat(net, inplace=False) |
| 179 | disable_fake_quant(qat_net) |
| 180 | normal_outputs = net(inputs) |
| 181 | qat_outputs = qat_net(inputs) |
| 182 | np.testing.assert_allclose(normal_outputs.numpy(), qat_outputs.numpy()) |
| 183 | |
| 184 | net.eval() |
| 185 | normal_outputs = net(inputs) |
| 186 | qat_net.eval() |
| 187 | qat_outputs = qat_net(inputs) |
| 188 | np.testing.assert_allclose(normal_outputs.numpy(), qat_outputs.numpy()) |
| 189 | |
| 190 | |
| 191 | @pytest.mark.skipif(get_device_count("gpu") > 0, reason="no int8 algorithm on cuda") |
nothing calls this directly
no test coverage detected