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

Joint mechanisms #105

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

Conversation

jonnyascott
Copy link

Implementing a privacy mechanism that takes in multiple existing mechanisms and applies them to disjoint portions of user statistics. This can be used in the situation that you want to make a multiple queries to a user simultaneously and each query should be noised differently e.g. because the queries have differing sensitivities or different noise distributions should be used.

Copy link
Member

@grananqvist grananqvist left a comment

Choose a reason for hiding this comment

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

nice! some comments

pfl/privacy/joint_mechanism.py Outdated Show resolved Hide resolved
pfl/privacy/joint_mechanism.py Outdated Show resolved Hide resolved
@@ -484,3 +485,228 @@ def test_norm_clipping_only(self, order, clipping_bound, expected_arrays,
is_local_privacy=True)
assert get_overall_value(
metrics[name]) == pytest.approx(expected_clip_fraction)

@pytest.mark.parametrize('ops_module', framework_fixtures)
Copy link
Member

Choose a reason for hiding this comment

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

Since the mechanisms themselves are tested in other unittests, you can simplify this a lot by just using MagicMock as mechanisms input to JointMechanism.
and the test will be much faster, as i recall these statistical tests are not super fast.

Copy link
Author

Choose a reason for hiding this comment

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

I've rewritten the test as suggested

statistics keys. As such JointMechanism can only be applied to client
statistics of type MappedVectorStatistics.

:param mechanisms_and_keys:
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to add a feature to also allow specify keys by sub path. e.g. if i have an LLM (which produce many keys) and then some other stats algo/value1, algo/value2, ... etc i want to put through a mechanism, it would be great if you can achieve this by:

mechanisms_and_keys = {
  'algo_mechanism': (m0, ['algo/']),
  'model_mechanism': (m1, [])
}

algo_mechanism takes all keys which start with algo/ and model_mechanism take all the rest of the keys.

Copy link
Author

Choose a reason for hiding this comment

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

Nice, thanks for the suggestion. I've added the feature that allows keys to be matched by subpathing.

I felt like it was safer not to implement the: [] matches all remaining keys, since this could make it easier to accidentally pass the wrong key to model_mechanism e.g. if I just forget to add a particular key to another mechanism. The way it is currently implemented this would be caught by the check that all keys have been noised. I think this particular model example should be easy to handle in the current implementation by providing list(model.get_parameters().keys()) to mechanisms_and_keys?

pfl/privacy/joint_mechanism.py Outdated Show resolved Hide resolved
@jonnyascott
Copy link
Author

Thanks for the feedback :)

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.

2 participants