Exemple #1
0
def test_concat_layer_wrapper(inputs, concat_stats, mode, clip_acts,
                              expected_output):
    with pytest.raises(ValueError):
        # Check exception on wrong layer type
        RangeLinearQuantConcatWrapper(torch.nn.Module(), 8, mode, clip_acts,
                                      concat_stats)

    layer = distiller.modules.Concat(dim=1)

    with pytest.raises(NotImplementedError):
        # Check exception on no stats
        RangeLinearQuantConcatWrapper(layer,
                                      8,
                                      mode,
                                      clip_acts,
                                      activation_stats=None)

    for idx in range(len(inputs)):
        inputs[idx] = attach_quant_metadata(inputs[idx],
                                            8,
                                            mode,
                                            stats=concat_stats['inputs'][idx],
                                            clip_mode=clip_acts,
                                            per_channel=False,
                                            num_stds=None,
                                            scale_approx_mult_bits=None)

    model = RangeLinearQuantConcatWrapper(layer, 8, mode, clip_acts,
                                          concat_stats)
    model.eval()
    output = model(*inputs)

    torch.testing.assert_allclose(output, expected_output)
Exemple #2
0
def test_concat_layer_wrapper(inputs, concat_stats, mode, clip_acts, expected_output):
    with pytest.raises(ValueError):
        # Check exception on wrong layer type
        RangeLinearQuantConcatWrapper(torch.nn.Module(), 8, mode, clip_acts, concat_stats)

    layer = distiller.modules.Concat(dim=1)

    with pytest.raises(ValueError):
        # Check exception on no stats
        RangeLinearQuantConcatWrapper(layer, 8, mode, clip_acts, activation_stats=None)

    model = RangeLinearQuantConcatWrapper(layer, 8, mode, clip_acts, concat_stats)
    model.eval()
    output = model(*inputs)

    torch.testing.assert_allclose(output, expected_output)