def test_batch_normalization_linear(seed, test, graph_ref, graph_act): from graph_converter_test_utils import structure_tester, value_tester, print_params # because linearized parameters (c0, c1) are to be shared among models nn.clear_parameters() # Random number np.random.seed(seed) rng = np.random.RandomState(seed) # Graph x_data = rng.randn(4, 3, 32, 32) x = nn.Variable.from_numpy_array(x_data) y_tgt = graph_act(x, test=test) # Convert name = "bn-linear-graph" converter = GC.BatchNormalizationLinearConverter(name=name) y_act = converter.convert(y_tgt, [x]) # Ref Graph name = "bn-linear-graph-ref" y_ref = graph_ref(x, name=name) # Test structure_tester(y_ref, y_act) value_tester(y_tgt, y_act)
def test_fixed_point_weight(seed, graph_ref, graph_act): # TODO: adaptive delta case (how to test it...) from graph_converter_test_utils import structure_tester, value_tester, print_params # Random number np.random.seed(seed) rng = np.random.RandomState(seed) # Graph x_data = rng.randn(4, 3, 32, 32) x = nn.Variable.from_numpy_array(x_data) y_tgt = graph_act(x) # Convert args_fpq = { "sign_w": True, "n_w": 8, "delta_w": 2e-4, "quantize_w": True, "sign_b": True, "n_b": 8, "delta_b": 2e-4, "quantize_b": True } name = "fixed-point-graph" converter = GC.FixedPointWeightConverter(args_fpq=args_fpq, name=name) y_act = converter.convert(y_tgt, [x]) # Ref Graph name = "fixed-point-weight-graph-ref" y_ref = graph_ref(x, name=name) # Test structure_tester(y_ref, y_act)
def test_identity(seed, graph_ref, graph_act): from graph_converter_test_utils import structure_tester, value_tester # Random number rng = np.random.RandomState(seed) # Graph x_data = rng.randn(4, 3, 32, 32) x = nn.Variable.from_numpy_array(x_data) y_tgt = graph_act(x) # Convert converter = GC.IdentityConverter() y_act = converter.convert(y_tgt, [x]) # Ref Graph y_ref = graph_ref(x) # Test structure_tester(y_ref, y_act) value_tester(y_tgt, y_act)
def test_fixed_point_activation(seed, graph_ref, graph_act): from graph_converter_test_utils import structure_tester, value_tester, print_params # Random number np.random.seed(seed) rng = np.random.RandomState(seed) # Graph x_data = rng.randn(4, 3, 32, 32) x = nn.Variable.from_numpy_array(x_data) y_tgt = graph_act(x) # Convert args_fpq = {"n": 8, "sign": False, "delta": 2e-4} name = "fixed-point-activation-graph" converter = GC.FixedPointActivationConverter(args_fpq=args_fpq, name=name) y_act = converter.convert(y_tgt, [x]) # Ref Graph name = "fixed-point-activation-graph-ref" y_ref = graph_ref(x, name=name) # Test structure_tester(y_ref, y_act)