def upload_request_generator(mdl): i = 1 while True: b = mdl.read(CHUNK_SIZE) if b: result = fedn.ModelRequest(data=b, id=id, status=fedn.ModelStatus.IN_PROGRESS) else: result = fedn.ModelRequest(id=id, status=fedn.ModelStatus.OK) yield result if not b: break
def get_model(self, id): """Fetch a model from the assigned combiner. Downloads the model update object via a gRPC streaming channel, Dowload. Parameters ---------- id : str The id of the model update object. """ from io import BytesIO data = BytesIO() for part in self.models.Download(fedn.ModelRequest(id=id)): if part.status == fedn.ModelStatus.IN_PROGRESS: data.write(part.data) if part.status == fedn.ModelStatus.OK: return data if part.status == fedn.ModelStatus.FAILED: return None return data
def get_model(self, id): from io import BytesIO data = BytesIO() data.seek(0, 0) import time import random parts = self.Download(fedn.ModelRequest(id=id), self) for part in parts: if part.status == fedn.ModelStatus.IN_PROGRESS: data.write(part.data) if part.status == fedn.ModelStatus.OK: return data if part.status == fedn.ModelStatus.FAILED: return None
def get_model(self, id): """Fetch model from the Combiner. """ from io import BytesIO data = BytesIO() for part in self.models.Download(fedn.ModelRequest(id=id)): if part.status == fedn.ModelStatus.IN_PROGRESS: data.write(part.data) if part.status == fedn.ModelStatus.OK: return data if part.status == fedn.ModelStatus.FAILED: return None return data
def get_model(self, id=None): """ Retrive the model bundle from a combiner. """ channel = Channel(self.address, self.port, self.certificate).get_channel() modelservice = rpc.ModelServiceStub(channel) if not id: id = self.get_model_id() from io import BytesIO data = BytesIO() data.seek(0, 0) parts = modelservice.Download(fedn.ModelRequest(id=id)) for part in parts: if part.status == fedn.ModelStatus.IN_PROGRESS: data.write(part.data) if part.status == fedn.ModelStatus.OK: return data if part.status == fedn.ModelStatus.FAILED: return None
def get_model(self, id): from io import BytesIO data = BytesIO() # print("REACHED DOWNLOAD Trying now with id {}".format(id), flush=True) # print("TRYING DOWNLOAD 1.", flush=True) for part in self.models.Download(fedn.ModelRequest(id=id)): # print("TRYING DOWNLOAD 2.", flush=True) if part.status == fedn.ModelStatus.IN_PROGRESS: # print("WRITING PART FOR MODEL:{}".format(id), flush=True) data.write(part.data) if part.status == fedn.ModelStatus.OK: # print("DONE WRITING MODEL RETURNING {}".format(id), flush=True) return data if part.status == fedn.ModelStatus.FAILED: # print("FAILED TO DOWNLOAD MODEL::: bailing!",flush=True) return None # print("ERROR NO PARTS!",flush=True) return data