openfl.federated.task.task_runner.CoreTaskRunner#

class openfl.federated.task.task_runner.CoreTaskRunner(**kwargs)[source]#

Bases: object

Federated Learning Task Runner Class.

kwargs#

Additional parameters passed to the function.

Type:

dict

TASK_REGISTRY#

Registry of tasks.

Type:

dict

training_round_completed#

Flag indicating if a training round has been completed.

Type:

bool

tensor_dict_split_fn_kwargs#

Key word arguments for determining which parameters to hold out from aggregation.

Type:

dict

required_tensorkeys_for_function#

Required tensorkeys for all public functions in CoreTaskRunner.

Type:

dict

logger#

Logger object for logging events.

Type:

logging.Logger

opt_treatment#

Treatment of current instance optimizer.

Type:

str

__init__(**kwargs)[source]#

Initializes the Task Runner object.

This class is a part of the Interactive python API release. It is no longer a user interface entity that should be subclassed but a part of OpenFL kernel.

Parameters:

**kwargs – Additional parameters to pass to the function.

Methods

__init__(**kwargs)

Initializes the Task Runner object.

adapt_tasks()

Prepare tasks for the collaborator.

get_required_tensorkeys_for_function(...)

Get the required tensors for specified function that could be called as part of a task.

get_tensor_dict([with_opt_vars])

Return the tensor dictionary.

get_train_data_size()

Get the number of training examples.

get_valid_data_size()

Get the number of examples.

initialize_tensorkeys_for_functions([...])

Set the required tensors for all publicly accessible task methods.

rebuild_model(input_tensor_dict[, ...])

Parse tensor names and update weights of model.

reset_opt_vars()

Reset optimizer variables.

set_data_loader(data_loader)

Register a data loader initialized with local data path.

set_framework_adapter(framework_adapter)

Set framework adapter.

set_logger()

Set up the log object.

set_model_provider(model_provider)

Retrieve a model and an optimizer from the interface object.

set_optimizer_treatment(opt_treatment)

Change the treatment of current instance optimizer.

set_task_provider(task_provider)

Set task registry.

set_tensor_dict(tensor_dict[, ...])

Set the tensor dictionary.

adapt_tasks()[source]#

Prepare tasks for the collaborator.

Using functions from a task provider (deserialized interface object) and registered task contracts prepares callable tasks to be invoked by the collaborator.

Preparing includes conditional model rebuilding and filling output dicts with tensors for aggregation and storing in local DB.

There is an assumption that any training task accepts optimizer as one of the arguments, thus the model should be aggregated after such tasks.

Returns:

None

get_required_tensorkeys_for_function(func_name, **kwargs)[source]#

Get the required tensors for specified function that could be called as part of a task.

By default, this is just all of the layers and optimizer of the model.

Parameters:
  • func_name (str) – The function name.

  • **kwargs – Additional parameters to pass to the function.

Returns:

List of required TensorKey.

Return type:

list

get_tensor_dict(with_opt_vars=False)[source]#

Return the tensor dictionary.

Parameters:

with_opt_vars (bool) – Return the tensor dictionary including the optimizer tensors (Default=False).

Returns:

Tensor dictionary {**dict, **optimizer_dict}.

Return type:

dict

get_train_data_size()[source]#

Get the number of training examples.

It will be used for weighted averaging in aggregation.

Returns:

The number of training examples.

Return type:

int

get_valid_data_size()[source]#

Get the number of examples.

It will be used for weighted averaging in aggregation.

Returns:

The number of validation examples.

Return type:

int

initialize_tensorkeys_for_functions(with_opt_vars=False)[source]#

Set the required tensors for all publicly accessible task methods.

By default, this is just all of the layers and optimizer of the model. Custom tensors should be added to this function.

Parameters:

with_opt_vars (bool) – Specify if we also want to set the variables of the optimizer. Default is False.

Returns:

None

rebuild_model(input_tensor_dict, validation=False, device='cpu')[source]#

Parse tensor names and update weights of model. Handles the optimizer treatment.

Parameters:
  • input_tensor_dict (dict) – The input tensor dictionary.

  • validation (bool) – If True, perform validation. Default is False.

  • device (str) – The device to use. Default is ‘cpu’.

Returns:

None

reset_opt_vars()[source]#

Reset optimizer variables.

Returns:

None

set_data_loader(data_loader)[source]#

Register a data loader initialized with local data path.

Parameters:

data_loader – Data loader object.

Returns:

None

set_framework_adapter(framework_adapter)[source]#

Set framework adapter.

Setting a framework adapter allows first extraction of the weigths of the model with the purpose to make a list of parameters to be aggregated.

Parameters:

framework_adapter – Framework adapter object.

Returns:

None

set_logger()[source]#

Set up the log object.

Returns:

None

set_model_provider(model_provider)[source]#

Retrieve a model and an optimizer from the interface object.

Parameters:

model_provider – Model provider object.

Returns:

None

set_optimizer_treatment(opt_treatment)[source]#

Change the treatment of current instance optimizer.

Parameters:

opt_treatment (str) – The optimizer treatment.

Returns:

None

set_task_provider(task_provider)[source]#

Set task registry.

This method recieves Task Interface object as an argument and uses provided callables and information to prepare tasks that may be called by the collaborator component.

Parameters:

task_provider – Task provider object.

Returns:

None

set_tensor_dict(tensor_dict, with_opt_vars=False, device='cpu')[source]#

Set the tensor dictionary.

Parameters:
  • tensor_dict – The tensor dictionary

  • with_opt_vars (bool) – Return the tensor dictionary including the optimizer tensors (Default=False).