Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move get experiment info in separate function #136

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions openfl/transport/grpc/director_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from openfl.protocols.utils import construct_model_proto
from openfl.protocols.utils import deconstruct_model_proto


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -191,31 +190,35 @@ def set_new_experiment(self, name, col_names, arch_path,
initial_tensor_dict=None):
"""Send the new experiment to director to launch."""
logger.info('SetNewExperiment')
model_proto = None
if initial_tensor_dict:
igor-davidyuk marked this conversation as resolved.
Show resolved Hide resolved
model_proto = construct_model_proto(initial_tensor_dict, 0, NoCompressionPipeline())
experiment_info_gen = self._get_experiment_info(
arch_path=arch_path,
name=name,
col_names=col_names,
model_proto=model_proto,
)
resp = self.stub.SetNewExperiment(experiment_info_gen)
return resp

def _get_experiment_info(self, arch_path, name, col_names, model_proto):
with open(arch_path, 'rb') as arch:
def st():
max_buffer_size = (2 * 1024 * 1024)
max_buffer_size = 2 * 1024 * 1024
chunk = arch.read(max_buffer_size)
while chunk != b'':
if not chunk:
raise StopIteration
# TODO: add hash or/and size to check
experiment_info = director_pb2.ExperimentInfo(
header=self.header,
name=name,
collaborator_names=col_names,
model_proto=model_proto
)
experiment_info.experiment_data.size = len(chunk)
experiment_info.experiment_data.npbytes = chunk
yield experiment_info
chunk = arch.read(max_buffer_size)
while chunk != b'':
if not chunk:
raise StopIteration
# TODO: add hash or/and size to check
experiment_info = director_pb2.ExperimentInfo(
header=self.header,
name=name,
collaborator_names=col_names,
model_proto=model_proto
)
experiment_info.experiment_data.size = len(chunk)
experiment_info.experiment_data.npbytes = chunk
yield experiment_info
chunk = arch.read(max_buffer_size)

resp = self.stub.SetNewExperiment(st())
return resp

def get_dataset_info(self):
"""Request the dataset info from the director."""
Expand Down Expand Up @@ -256,7 +259,8 @@ def stream_metrics(self, experiment_name):
'task_name': metric_message.task_name,
'metric_name': metric_message.metric_name,
'metric_value': metric_message.metric_value,
'round': metric_message.round}
'round': metric_message.round
}

def remove_experiment_data(self, name):
"""Remove experiment data RPC."""
Expand Down