flip.nvflare.components
FLIP Components module containing reusable FL components.
Components include event handlers, model locators, JSON generators, and persistence utilities.
- Exports:
ClientEventHandler: Client-side event handler
ServerEventHandler: Server-side event handler
PTModelLocator: PyTorch model locator
InitialPTModelLocator: PyTorch model locator for initial models with safehouse fallback
EvaluationPTModelLocator: PyTorch model locator for evaluation workflows
ValidationJsonGenerator: Validation results JSON generator
EvaluationJsonGenerator: Evaluation results JSON generator
PersistToS3AndCleanup: S3 persistence and cleanup component
PercentilePrivacy: Percentile-based privacy filter
StagePercentilePrivacy: Stage-aware percentile-based privacy filter
CleanupImages: Image cleanup executor
Submodules
- flip.nvflare.components.cleanup
- flip.nvflare.components.custom_percentile_privacy
- flip.nvflare.components.evaluation_json_generator
- flip.nvflare.components.flip_client_event_handler
- flip.nvflare.components.flip_server_event_handler
- flip.nvflare.components.persist_and_cleanup
- flip.nvflare.components.pt_model_locator
- flip.nvflare.components.stage_percentile_privacy
- flip.nvflare.components.validation_json_generator
Classes
CleanupImages takes place at the start and end of the run. |
|
Implementation of "largest percentile to share" privacy preserving policy. |
|
Handles EVALUATION_RESULT_RECEIVED event and generates a results.json containing accuracy of each |
|
ClientEventHandler is a generic component that handles system events triggered by nvflare |
|
ServerEventHandler is a generic component that handles system events triggered by nvflare |
|
The component that is executed post training and is a part of the FLIP training model |
|
Implementation of "largest percentile to share" privacy preserving policy. |
|
Handles VALIDATION_RESULT_RECEIVED event and generates a results.json containing accuracy of each |
Package Contents
- class flip.nvflare.components.CleanupImages[source]
Bases:
nvflare.apis.executor.ExecutorCleanupImages takes place at the start and end of the run. All the images used for the training are deleted to prevent the build-up of unnecessary files on the storage space. Executing at the start of a run ensures that any training code is executed with a clean slate.
Args:
Raises:
- class flip.nvflare.components.PercentilePrivacy(percentile=10, gamma=0.01, data_kinds: List[str] | None = None, off: bool = False)[source]
Bases:
nvflare.apis.dxo_filter.DXOFilterImplementation of “largest percentile to share” privacy preserving policy.
Shokri and Shmatikov, Privacy-preserving deep learning, CCS ‘15
- Parameters:
percentile (int, optional) – Only abs diff greater than this percentile is updated. Allowed range 0..100. Defaults to 10.
gamma (float, optional) – The upper limit to truncate abs values of weight diff. Defaults to 0.01.
0. (Any weight diff with abs<gamma will become)
data_kinds – kinds of DXO to filter
off (bool, optional) – If True, the filter is turned off. Defaults to False.
- percentile = 10
- gamma = 0.01
- off = False
- process_dxo(dxo: nvflare.apis.dxo.DXO, shareable: nvflare.apis.shareable.Shareable, fl_ctx: nvflare.apis.fl_context.FLContext) None | nvflare.apis.dxo.DXO[source]
Compute the percentile on the abs delta_W.
Only share the params where absolute delta_W greater than the percentile value
- Parameters:
dxo – information from client
shareable – that the dxo belongs to
fl_ctx – context provided by workflow
Returns: filtered dxo
- class flip.nvflare.components.EvaluationJsonGenerator(results_dir=PTConstants.EvalDir, json_file_name=PTConstants.EvalResultsFilename)[source]
Bases:
nvflare.apis.fl_component.FLComponentHandles EVALUATION_RESULT_RECEIVED event and generates a results.json containing accuracy of each validated model.
- Parameters:
- class flip.nvflare.components.ClientEventHandler[source]
Bases:
nvflare.apis.fl_component.FLComponentClientEventHandler is a generic component that handles system events triggered by nvflare or custom flip events. It executes logic inside its own event handler but may also call other component’s event handlers directly to help overcome the non-deterministic order in which nvflare handles events.
Args:
Raises:
- class flip.nvflare.components.ServerEventHandler(model_id: str = '', validation_json_generator_id: str = 'json_generator', persist_and_cleanup_id: str = 'persist_and_cleanup', flip: flip.FLIP = FLIP())[source]
Bases:
nvflare.apis.fl_component.FLComponentServerEventHandler is a generic component that handles system events triggered by nvflare or custom flip events. It executes logic inside its own event handler but may also call other component’s event handlers directly to overcome the non-deterministic order in which nvflare handles events i.e handling ValidationJsonGenerator component events.
- Parameters:
model_id (string, not required)
validation_json_generator_id (string, not required)
persist_and_cleanup_id (string, not required)
flip (object, not required)
- Raises:
ValueError – when model ID is not a valid UUID
- model_id = ''
- validation_json_generator_id = 'json_generator'
- validation_json_generator = None
- persist_and_cleanup_id = 'persist_and_cleanup'
- persist_and_cleanup = None
- flip
- fatal_error = False
- final_status = None
- class flip.nvflare.components.PersistToS3AndCleanup(model_id: str, persistor_id: str = AppConstants.DEFAULT_PERSISTOR_ID, flip: flip.FLIP = FLIP())[source]
Bases:
nvflare.apis.fl_component.FLComponentThe component that is executed post training and is a part of the FLIP training model
The PersistToS3AndCleanup workflow saves the aggregated model (once training has finished) to an S3 bucket, and then deletes files created as part of the run
- Parameters:
- Raises:
when the model ID is not a valid UUID.
FileNotFoundError: boto3 error for when the zip file does not exist.
- model_id
- flip
- class flip.nvflare.components.EvaluationPTModelLocator(exclude_vars=None)[source]
Bases:
nvflare.app_common.abstract.model_locator.ModelLocator- models = None
- exclude_vars = None
- class flip.nvflare.components.InitialPTModelLocator(exclude_vars=None, model=None)[source]
Bases:
nvflare.app_common.abstract.model_locator.ModelLocator- model = None
- exclude_vars = None
- class flip.nvflare.components.PTModelLocator(exclude_vars=None, model=None)[source]
Bases:
nvflare.app_common.abstract.model_locator.ModelLocator- model = None
- exclude_vars = None
- class flip.nvflare.components.StagePercentilePrivacy(percentile=10, gamma=0.01, data_kinds: List[str] = None, off: bool = False)[source]
Bases:
nvflare.apis.dxo_filter.DXOFilterImplementation of “largest percentile to share” privacy preserving policy.
Shokri and Shmatikov, Privacy-preserving deep learning, CCS ‘15
- Parameters:
percentile (int, optional) – Only abs diff greater than this percentile is updated. Allowed range 0..100. Defaults to 10.
gamma (float, optional) – The upper limit to truncate abs values of weight diff. Defaults to 0.01.
0. (Any weight diff with abs<gamma will become)
data_kinds – kinds of DXO to filter
off (bool, optional) – If True, the filter is turned off. Defaults to False.
- percentile = 10
- gamma = 0.01
- off = False
- process_dxo(dxo: nvflare.apis.dxo.DXO, shareable: nvflare.apis.shareable.Shareable, fl_ctx: nvflare.apis.fl_context.FLContext) None | nvflare.apis.dxo.DXO[source]
Compute the percentile on the abs delta_W.
Only share the params where absolute delta_W greater than the percentile value
- Parameters:
dxo – information from client
shareable – that the dxo belongs to
fl_ctx – context provided by workflow
Returns: filtered dxo
- class flip.nvflare.components.ValidationJsonGenerator(results_dir=AppConstants.CROSS_VAL_DIR, json_file_name=PTConstants.CrossValResultsJsonFilename)[source]
Bases:
nvflare.apis.fl_component.FLComponentHandles VALIDATION_RESULT_RECEIVED event and generates a results.json containing accuracy of each validated model.
- Parameters: