Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change opt treatment and device policy to enum values #374

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

mansishr
Copy link
Collaborator

Fixes #194

@mansishr mansishr marked this pull request as draft March 11, 2022 02:30
@mansishr mansishr marked this pull request as ready for review March 16, 2022 04:12
@@ -103,7 +105,7 @@ def collaborator_adapted_task(col_name, round_num, input_tensor_dict, **kwargs):
validation_flag = True if task_contract['optimizer'] is None else False
task_settings = self.task_provider.task_settings[task_name]

device = kwargs.get('device', 'cpu')
device = kwargs.get('device', DevicePolicy.CPU_ONLY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not a device policy but a device identifier

@@ -214,18 +216,18 @@ def set_optimizer_treatment(self, opt_treatment):
"""Change the treatment of current instance optimizer."""
self.opt_treatment = opt_treatment

def rebuild_model(self, input_tensor_dict, validation=False, device='cpu'):
def rebuild_model(self, input_tensor_dict, validation=False, device=DevicePolicy.CPU_ONLY):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also should be reverted

@@ -358,7 +360,7 @@ def get_tensor_dict(self, with_opt_vars=False):

return self.framework_adapter.get_tensor_dict(*args)

def set_tensor_dict(self, tensor_dict, with_opt_vars=False, device='cpu'):
def set_tensor_dict(self, tensor_dict, with_opt_vars=False, device=DevicePolicy.CPU_ONLY):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a policy but a device

@@ -104,7 +106,8 @@ def _rebuild_model(self, tensor_dict, upcoming_model_status=ModelStatus.BEST):
self.logger.warning(warning_msg)

else:
self.task_runner_stub.rebuild_model(tensor_dict, validation=True, device='cpu')
self.task_runner_stub.rebuild_model(
tensor_dict, validation=True, device=DevicePolicy.CPU_ONLY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same issue

Comment on lines 205 to 206
delta_updates=delta_updates, opt_treatment=opt_treatment.name,
device_assignment_policy=device_assignment_policy.name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may convert those later, before saving to plan or sending through gRPC

Suggested change
delta_updates=delta_updates, opt_treatment=opt_treatment.name,
device_assignment_policy=device_assignment_policy.name,
delta_updates=delta_updates, opt_treatment=opt_treatment,
device_assignment_policy=device_assignment_policy,

@mansishr mansishr requested a review from igor-davidyuk March 17, 2022 05:06
@mansishr
Copy link
Collaborator Author

Jenkins please retry a build

if isinstance(opt_treatment, str) and hasattr(OptTreatment, opt_treatment):
defaults[SETTINGS]['opt_treatment'] = OptTreatment[opt_treatment].value
elif isinstance(opt_treatment, int) and OptTreatment(opt_treatment):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we parse integer value here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if opt_treatment is already an integer (from lime 463), then it's already parsed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this check then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So both integer and string values are appropriate here if there are multiple collaborators. In both of these conditions, it shouldn't raise an exception but for all other cases it should.

@@ -166,8 +170,8 @@ def start(self, *, model_provider, task_keeper, data_loader,
rounds_to_train: int,
task_assigner=None,
delta_updates: bool = False,
opt_treatment: str = 'RESET',
device_assignment_policy: str = 'CPU_ONLY',
opt_treatment: Enum = OptTreatment.RESET,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
opt_treatment: Enum = OptTreatment.RESET,
opt_treatment: OptTreatment = OptTreatment.RESET,

opt_treatment: str = 'RESET',
device_assignment_policy: str = 'CPU_ONLY',
opt_treatment: Enum = OptTreatment.RESET,
device_assignment_policy: Enum = DevicePolicy.CPU_ONLY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
device_assignment_policy: Enum = DevicePolicy.CPU_ONLY,
device_assignment_policy: DevicePolicy = DevicePolicy.CPU_ONLY,

@@ -368,7 +369,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.9"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clear the notebook metadata

@@ -484,12 +484,14 @@
"# If I use autoreload I got a pickling error\n",
"\n",
"# The following command zips the workspace and python requirements to be transfered to collaborator nodes\n",
"from openfl.utilities.enum_types import DevicePolicy, OptTreatment\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this import into separate lines

@mansishr mansishr requested a review from itrushkin March 29, 2022 17:54

opt_treatment = defaults[SETTINGS]['opt_treatment']
if isinstance(opt_treatment, str) and hasattr(OptTreatment, opt_treatment):
defaults[SETTINGS]['opt_treatment'] = OptTreatment[opt_treatment].value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to save string here to easeir review plan.yaml.
In experiment it is using plan.config['collaborator']['settings']['opt_treatment'] = opt_treatment.name.
We should save values in plan in the same format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I and @igor-davidyuk discussed about it and thought of using value instead of name

@mansishr
Copy link
Collaborator Author

Jenkins please retry a build

@theakshaypant
Copy link
Collaborator

@mansishr can you please resolve the conflicts and request for review again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change Enum utilisation in Collaborator component and Frontend API
5 participants