Beispiel #1
0
def test_serialization_deserialization_multidimensional_2D_array():
    num_clients = 10
    num_rows_params = 3
    num_cols_params = 9

    clients_params = []
    for i in range(num_clients):
        clients_params.append(np.random.rand(num_rows_params, num_cols_params))

    avgfa = NormClipAggregator(clip=100)

    serialized_params = np.array(
        [avgfa._serialize(client) for client in clients_params])
    deserialized_params = np.array(
        [avgfa._deserialize(client) for client in serialized_params])

    assert np.array_equal(deserialized_params, clients_params)
Beispiel #2
0
def test_serialization_deserialization_mixed_list():
    num_clients = 10

    clients_params = []
    for i_client in range(num_clients):
        clients_params.append(
            [np.random.rand(),
             np.random.rand(20, 30),
             np.random.rand(50, 40)])

    avgfa = NormClipAggregator(clip=100)

    serialized_params = np.array(
        [avgfa._serialize(client) for client in clients_params])
    for i, client in enumerate(serialized_params):
        deserialized = avgfa._deserialize(client)
        for j, arr in enumerate(deserialized):
            assert np.array_equal(arr, clients_params[i][j])
Beispiel #3
0
def test_serialization_deserialization():
    num_clients = 10
    num_layers = 5
    tams = [[128, 64], [64, 64], [64, 64], [64, 32], [32, 10]]

    weights = []
    for i in range(num_clients):
        weights.append([
            np.random.rand(tams[j][0], tams[j][1]) for j in range(num_layers)
        ])

    clients_params = weights

    avgfa = NormClipAggregator(clip=100)

    serialized_params = np.array(
        [avgfa._serialize(client) for client in clients_params])
    for i, client in enumerate(serialized_params):
        deserialized = avgfa._deserialize(client)
        for j, arr in enumerate(deserialized):
            assert np.array_equal(arr, clients_params[i][j])