MCPcopy Create free account
hub / github.com/OpenMined/SyMPC / test_reconstruct_shared_model

Function test_reconstruct_shared_model

tests/sympc/module/module_test.py:111–144  ·  view source on GitHub ↗
(
    is_remote: bool, model_type: Type[sy.Module], get_clients: Callable[[int], Any]
)

Source from the content-addressed store, hash-verified

109@pytest.mark.parametrize("is_remote", [False, True])
110@pytest.mark.parametrize("model_type", [LinearNet, ConvNet])
111def test_reconstruct_shared_model(
112 is_remote: bool, model_type: Type[sy.Module], get_clients: Callable[[int], Any]
113):
114 net = model_type(torch)
115
116 clients = get_clients(2)
117
118 session = Session(parties=clients)
119 SessionManager.setup_mpc(session)
120
121 if is_remote:
122 model = net.send(clients[0])
123 else:
124 model = net
125
126 mpc_model = model.share(session=session)
127 res = mpc_model.reconstruct()
128
129 assert isinstance(res, sy.Module)
130
131 if is_remote:
132 # If the model is remote fetch it such that we could compare it
133 model = model.get()
134
135 for name_res, name_expected in zip(res.modules, model.modules):
136 assert name_res == name_expected
137
138 module_expected = model.modules[name_expected]
139 module_res = res.modules[name_res]
140
141 name_module = type(module_expected).__name__
142 assert MAP_TORCH_TO_SYMPC[name_module].eq_close(
143 module_expected, module_res, atol=1e-4
144 )
145
146
147def test_additional_attributes(get_clients):

Callers

nothing calls this directly

Calls 5

SessionClass · 0.90
setup_mpcMethod · 0.80
eq_closeMethod · 0.80
get_clientsFunction · 0.50
reconstructMethod · 0.45

Tested by

no test coverage detected