Skip to content

Commit aa0ce51

Browse files
authored
add client settings to client v2 (#754)
1 parent 63c56f9 commit aa0ce51

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

fedn/network/clients/client_v2.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from fedn.common.log_config import logger
1111
from fedn.network.clients.fedn_client import ConnectToApiResult, FednClient, GrpcConnectionOptions
1212
from fedn.network.combiner.modelservice import get_tmp_path
13-
from fedn.utils.helpers.helpers import get_helper
13+
from fedn.utils.helpers.helpers import get_helper, save_metadata
1414

1515

1616
def get_url(api_url: str, api_port: int) -> str:
@@ -132,15 +132,15 @@ def set_helper(self, response: GrpcConnectionOptions = None):
132132
# Priority: helper_type from constructor > helper_type from response > default helper_type
133133
self.helper = get_helper(helper_type_to_use)
134134

135-
def on_train(self, in_model):
136-
out_model, meta = self._process_training_request(in_model)
135+
def on_train(self, in_model, client_settings):
136+
out_model, meta = self._process_training_request(in_model, client_settings)
137137
return out_model, meta
138138

139139
def on_validation(self, in_model):
140140
metrics = self._process_validation_request(in_model)
141141
return metrics
142142

143-
def _process_training_request(self, in_model: BytesIO) -> Tuple[BytesIO, dict]:
143+
def _process_training_request(self, in_model: BytesIO, client_settings: dict) -> Tuple[BytesIO, dict]:
144144
"""Process a training (model update) request.
145145
146146
:param in_model: The model to be updated.
@@ -156,6 +156,8 @@ def _process_training_request(self, in_model: BytesIO) -> Tuple[BytesIO, dict]:
156156
with open(inpath, "wb") as fh:
157157
fh.write(in_model.getbuffer())
158158

159+
save_metadata(metadata=client_settings, filename=inpath)
160+
159161
outpath = self.helper.get_tmp_path()
160162

161163
tic = time.time()

fedn/network/clients/fedn_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ def update_local_model(self, request):
225225
self.send_status(f"\t Starting processing of training request for model_id {model_id}", sesssion_id=request.session_id, sender_name=self.name)
226226

227227
logger.info(f"Running train callback with model ID: {model_id}")
228+
client_settings = json.loads(request.data).get("client_settings", {})
228229
tic = time.time()
229-
out_model, meta = self.train_callback(in_model)
230+
out_model, meta = self.train_callback(in_model, client_settings)
230231
meta["processing_time"] = time.time() - tic
231232

232233
tic = time.time()

0 commit comments

Comments
 (0)