nvflare.app_common.filters.convert_weights module

class ConvertWeights(direction: str)[source]

Bases: Filter

Convert WEIGHTS to WEIGHT_DIFF or vice versa.

Parameters

direction (str) – control conversion direction. Either weights_to_diff or diff_to_weights.

Raises

ValueError – when the direction string is neither weights_to_diff nor diff_to_weights

DIFF_TO_WEIGHTS = 'diff_to_weights'
WEIGHTS_TO_DIFF = 'weights_to_diff'
process(shareable: Shareable, fl_ctx: FLContext) Shareable[source]

Called by runners to perform weight conversion.

When the return code of shareable is not ReturnCode.OK, this function will not perform any process and returns the shareable back.

Parameters
  • shareable (Shareable) – shareable must conform to DXO format.

  • fl_ctx (FLContext) – this context must include TASK_DATA, which is another shareable containing base weights. If not, the input shareable will be returned.

Returns

a shareable with converted weights

Return type

Shareable