()
| 3 | |
| 4 | |
| 5 | def test_repr(): |
| 6 | class Net(M.Module): |
| 7 | def __init__(self): |
| 8 | super().__init__() |
| 9 | self.conv_bn = M.ConvBnRelu2d(3, 3, 3) |
| 10 | self.linear = M.Linear(3, 3) |
| 11 | |
| 12 | def forward(self, x): |
| 13 | return x |
| 14 | |
| 15 | net = Net() |
| 16 | ground_truth = ( |
| 17 | "Net(\n" |
| 18 | " (conv_bn): ConvBnRelu2d(\n" |
| 19 | " (conv): Conv2d(3, 3, kernel_size=(3, 3))\n" |
| 20 | " (bn): BatchNorm2d(3, eps=1e-05, momentum=0.9, affine=True, track_running_stats=True)\n" |
| 21 | " )\n" |
| 22 | " (linear): Linear(in_features=3, out_features=3, bias=True)\n" |
| 23 | ")" |
| 24 | ) |
| 25 | assert net.__repr__() == ground_truth |
| 26 | quantize_qat(net) |
| 27 | ground_truth = ( |
| 28 | "Net(\n" |
| 29 | " (conv_bn): QAT.ConvBnRelu2d(\n" |
| 30 | " (conv): Conv2d(3, 3, kernel_size=(3, 3))\n" |
| 31 | " (bn): BatchNorm2d(3, eps=1e-05, momentum=0.9, affine=True, track_running_stats=True)\n" |
| 32 | " (act_observer): ExponentialMovingAverageObserver()\n" |
| 33 | " (act_fake_quant): FakeQuantize()\n" |
| 34 | " (weight_observer): MinMaxObserver()\n" |
| 35 | " (weight_fake_quant): FakeQuantize()\n" |
| 36 | " )\n" |
| 37 | " (linear): QAT.Linear(\n" |
| 38 | " in_features=3, out_features=3, bias=True\n" |
| 39 | " (act_observer): ExponentialMovingAverageObserver()\n" |
| 40 | " (act_fake_quant): FakeQuantize()\n" |
| 41 | " (weight_observer): MinMaxObserver()\n" |
| 42 | " (weight_fake_quant): FakeQuantize()\n" |
| 43 | " )\n" |
| 44 | ")" |
| 45 | ) |
| 46 | assert net.__repr__() == ground_truth |
| 47 | quantize(net) |
| 48 | ground_truth = ( |
| 49 | "Net(\n" |
| 50 | " (conv_bn): Quantized.ConvBnRelu2d(3, 3, kernel_size=(3, 3))\n" |
| 51 | " (linear): Quantized.Linear()\n" |
| 52 | ")" |
| 53 | ) |
| 54 | assert net.__repr__() == ground_truth |
nothing calls this directly
no test coverage detected