openfl.component.collaborator.collaborator.Collaborator
- class openfl.component.collaborator.collaborator.Collaborator(collaborator_name, aggregator_uuid, federation_uuid, client, task_runner, task_config, opt_treatment='RESET', device_assignment_policy='CPU_ONLY', delta_updates=False, compression_pipeline=None, db_store_rounds=1, **kwargs)
Bases:
objectThe Collaborator object class.
- Class Attributes:
collaborator_name (str) – The common name for the collaborator.
aggregator_uuid (str) – The unique id for the client.
federation_uuid (str) – The unique id for the federation.
client (object) – The client object.
task_runner (object) – The task runner object.
task_config (dict) – The task configuration.
opt_treatment (str) – The optimizer state treatment.
device_assignment_policy (str) – The device assignment policy.
delta_updates (bool) – If True, only model delta gets sent. If False, whole model gets sent to collaborator.
compression_pipeline (object) – The compression pipeline.
db_store_rounds (int) – The number of rounds to store in the database.
single_col_cert_common_name (str) – The common name for the single column certificate.
Note
* - Plan setting.
Methods
Perform the specified task.
Return the decompressed tensor associated with the requested tensor key.
Resolve the tensor corresponding to the requested tensorkey.
Get tensor dictionary for specified tensorkey set.
Get tasks from the aggregator.
Convert named tensor to a numpy array.
Construct the NamedTensor Protobuf.
Run the collaborator.
Specific function for the simulation.
Send task results to the aggregator.
Set available CUDA devices.
- do_task(task, round_number)
Perform the specified task.
- Parameters:
task (list_of_str) – List of tasks.
round_number (int) – Actual round number.
- get_aggregated_tensor_from_aggregator(tensor_key, require_lossless=False)
Return the decompressed tensor associated with the requested tensor key.
If the key requests a compressed tensor (in the tag), the tensor will be decompressed before returning. If the key specifies an uncompressed tensor (or just omits a compressed tag), the decompression operation will be skipped.
- Parameters:
tensor_key (namedtuple) – The requested tensor.
require_lossless (bool) – Should compression of the tensor be allowed in flight? For the initial model, it may affect convergence to apply lossy compression. And metrics shouldn’t be compressed either.
- Returns:
nparray – The decompressed tensor associated with the requested tensor key.
- get_data_for_tensorkey(tensor_key)
Resolve the tensor corresponding to the requested tensorkey.
- Parameters:
tensor_key (namedtuple) – Tensorkey that will be resolved locally or
tensors. (remotely. May be the product of other)
- Returns:
nparray – The decompressed tensor associated with the requested tensor key.
- get_numpy_dict_for_tensorkeys(tensor_keys)
Get tensor dictionary for specified tensorkey set.
- Parameters:
tensor_keys (namedtuple) – Tensorkeys that will be resolved locally or remotely. May be the product of other tensors.
- get_tasks()
Get tasks from the aggregator.
- Returns:
tasks (list_of_str) – List of tasks.
round_number (int) – Actual round number.
sleep_time (int) – Sleep time.
time_to_quit (bool) – bool value for quit.
- named_tensor_to_nparray(named_tensor)
Convert named tensor to a numpy array.
- Parameters:
named_tensor (protobuf) – The tensor to convert to nparray.
- Returns:
decompressed_nparray (nparray) – The nparray converted.
- nparray_to_named_tensor(tensor_key, nparray)
Construct the NamedTensor Protobuf.
Includes logic to create delta, compress tensors with the TensorCodec, etc.
- Parameters:
tensor_key (namedtuple) – Tensorkey that will be resolved locally or remotely. May be the product of other tensors.
nparray – The decompressed tensor associated with the requested tensor key.
- Returns:
named_tensor (protobuf) – The tensor constructed from the nparray.
- run()
Run the collaborator.
- run_simulation()
Specific function for the simulation.
After the tasks have been performed for a roundquit, and then the collaborator object will be reinitialized after the next round.
- send_task_results(tensor_dict, round_number, task_name)
Send task results to the aggregator.
- Parameters:
tensor_dict (dict) – Tensor dictionary.
round_number (int) – Actual round number.
task_name (string) – Task name.
- set_available_devices(cuda: Tuple[str] = ())
Set available CUDA devices.
- Parameters:
cuda (Tuple[str]) – Tuple containing string indices of available CUDA devices, (‘1’, ‘3’).