nvflare.edge.mud module

class BaseState(model_version: int, model: DXO, device_selection_version: int, device_selection: Dict[str, int])[source]

Bases: object

BaseState is the Base for on-device training

The device_selection is a dict of device_id => selection_id.

Device selection is maintained by the Server. It records the device_id paired with a selection_id, which is a non-zero integer. A device can train only once with the same selection_id.

Our default way is to assign selection_id is that when a device is added to the selection, set its selection_id to the global model version assigned to it. This means that if the device is selected for training again, it must be assigned a different global model - it does not make much sense to select a device for training again with the same model, because it will lead to almost the same update twice (unless the data on the device is changed during the two selections, which is unlikely).

The devices in the current selection could have different selection_ids because they are selected at different time points.

Parameters:
  • model_version – version of model. 0 means no model available.

  • model – data of the model.

  • device_selection_version – version of device selection. 0 means no devices selected.

  • device_selection – selected devices.

static from_shareable(shareable: Shareable)[source]

Convert the specified Shareable object to BaseState object.

Parameters:

shareable – the Shareable object to be converted.

Returns: a BaseState object

get_converted_model(platform: str)[source]

Get the model that is converted for the platform.

Parameters:

platform – the platform of the model

Returns: converted model if available; None otherwise.

is_device_selected(device_id: str, selection_id: int) -> (<class 'bool'>, <class 'int'>)[source]

Determine whether the device should be selected for training.

Parameters:
  • device_id – the ID of the device

  • selection_id – current selection ID of the device

Returns: tuple of (whether the device is selected, new selection id)

set_converted_model(model, platform: str)[source]

Set the model that is converted from the original model for the specified platform.

Parameters:
  • model – the converted model

  • platform – the platform that the converted model will be used for

Returns: None

to_shareable() Shareable[source]

Convert to Shareable for communication.

Returns: a Shareable object

class Device(device_id: str, client_name: str, last_alive_time: float, props: Dict | None = None)[source]

Bases: object

Device object keeps device information to be communicated to the Server.

Parameters:
  • device_id – unique ID of the device.

  • client_name – name of the leaf client that the device belongs to.

  • last_alive_time – last time when the device interacted with the client.

  • props – additional properties of the device.

static from_dict(d: Dict)[source]

Convert the specified dict object to Device object

Parameters:

d – the dict object to be converted.

Returns: a Device object

to_dict() dict[source]

Convert to dict representation, mainly for communication.

Returns: a dict object

class ModelUpdate(model_version: int, update: Shareable, devices: Dict[str, float])[source]

Bases: object

ModelUpdate specifies information of a model update.

Parameters:
  • model_version – version of the model.

  • update – update to the model.

  • devices – devices that contributed to this update. It is a dict of device_id => update timestamp, which specifies at what time the device made the contribution.

static from_dict(d: Dict)[source]

Convert the specified dict object to ModelUpdate object

Parameters:

d – the dict to be converted.

Returns: a ModelUpdate object

to_dict() dict[source]

Convert to dict representation, mainly for communication.

Returns: a dict object

class PropKey[source]

Bases: object

CLIENT_NAME = 'client_name'
DEVICES = 'devices'
DEVICE_ID = 'device_id'
DEVICE_LAST_ALIVE_TIME = 'device_last_alive_time'
DEVICE_PROPS = 'device_props'
DEVICE_SELECTION = 'device_selection'
DEVICE_SELECTION_VERSION = 'device_selection_version'
MODEL = 'model'
MODEL_UPDATES = 'model_updates'
MODEL_VERSION = 'model_version'
SELECTION_ID = 'selection_id'
class StateUpdateReply(model_version: int, model: DXO, device_selection_version: int, device_selection: Dict[str, int] | None)[source]

Bases: object

StateUpdateReply is the reply to the child’s StateUpdateReport. The child processes StateUpdateReply to adjust its Base State.

Parameters:
  • model_version

  • model

  • device_selection_version

  • device_selection

static from_shareable(shareable: Shareable)[source]

Convert the specified Shareable object to StateUpdateReply object

Parameters:

shareable – the object to be converted

Returns: a StateUpdateReply object

to_shareable() Shareable[source]

Convert to Shareable object, mainly for communication.

Returns: a Shareable object

class StateUpdateReport(current_model_version: int, current_device_selection_version: int, model_updates: Dict[int, ModelUpdate] | None, available_devices: Dict[str, Device] | None)[source]

Bases: object

StateUpdateReport is sent from a client to its parent to report its state update.

Parameters:
  • current_model_version – version of the child’s current model.

  • current_device_selection_version – version of the child’s current device_selection.

  • model_updates – 0 or more model updates.

  • available_devices – 0 or more available devices.

Notes

Multiple versions of models could be in training.

static from_shareable(s: Shareable)[source]
to_shareable() Shareable[source]

Convert to Shareable object, mainly for communication.

Returns: a Shareable object