Restoring ability to run compute_dp_sgd_privacy.py as a standalone script.
At present, the script has no heavy dependencies except for the rdp_accountant, which is by itself pretty light-weight. However, importing rdp_accountant triggers __init__.py in third_party/py/tensorflow_privacy/privacy, which loads TF and all of tf.privacy. The CL adds a check to the __init__.py, which controls this behavior. PiperOrigin-RevId: 243172355
This commit is contained in:
parent
e8113a0365
commit
3c4409d6d6
2 changed files with 30 additions and 19 deletions
|
@ -13,23 +13,30 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""TensorFlow Privacy library."""
|
"""TensorFlow Privacy library."""
|
||||||
|
|
||||||
from privacy.analysis.privacy_ledger import DummyLedger
|
import sys
|
||||||
from privacy.analysis.privacy_ledger import GaussianSumQueryEntry
|
|
||||||
from privacy.analysis.privacy_ledger import PrivacyLedger
|
|
||||||
from privacy.analysis.privacy_ledger import QueryWithLedger
|
|
||||||
from privacy.analysis.privacy_ledger import SampleEntry
|
|
||||||
|
|
||||||
from privacy.dp_query.dp_query import DPQuery
|
# pylint: disable=g-import-not-at-top
|
||||||
from privacy.dp_query.gaussian_query import GaussianAverageQuery
|
|
||||||
from privacy.dp_query.gaussian_query import GaussianSumQuery
|
|
||||||
from privacy.dp_query.nested_query import NestedQuery
|
|
||||||
from privacy.dp_query.no_privacy_query import NoPrivacyAverageQuery
|
|
||||||
from privacy.dp_query.no_privacy_query import NoPrivacySumQuery
|
|
||||||
from privacy.dp_query.normalized_query import NormalizedQuery
|
|
||||||
|
|
||||||
from privacy.optimizers.dp_optimizer import DPAdagradGaussianOptimizer
|
if hasattr(sys, 'skip_tf_privacy_import'): # Useful for standalone scripts.
|
||||||
from privacy.optimizers.dp_optimizer import DPAdagradOptimizer
|
pass
|
||||||
from privacy.optimizers.dp_optimizer import DPAdamGaussianOptimizer
|
else:
|
||||||
from privacy.optimizers.dp_optimizer import DPAdamOptimizer
|
from tensorflow_privacy.privacy.analysis.privacy_ledger import DummyLedger
|
||||||
from privacy.optimizers.dp_optimizer import DPGradientDescentGaussianOptimizer
|
from tensorflow_privacy.privacy.analysis.privacy_ledger import GaussianSumQueryEntry
|
||||||
from privacy.optimizers.dp_optimizer import DPGradientDescentOptimizer
|
from tensorflow_privacy.privacy.analysis.privacy_ledger import PrivacyLedger
|
||||||
|
from tensorflow_privacy.privacy.analysis.privacy_ledger import QueryWithLedger
|
||||||
|
from tensorflow_privacy.privacy.analysis.privacy_ledger import SampleEntry
|
||||||
|
|
||||||
|
from tensorflow_privacy.privacy.dp_query.dp_query import DPQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.gaussian_query import GaussianAverageQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.gaussian_query import GaussianSumQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.nested_query import NestedQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.no_privacy_query import NoPrivacyAverageQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.no_privacy_query import NoPrivacySumQuery
|
||||||
|
from tensorflow_privacy.privacy.dp_query.normalized_query import NormalizedQuery
|
||||||
|
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradGaussianOptimizer
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdagradOptimizer
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamGaussianOptimizer
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPAdamOptimizer
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentGaussianOptimizer
|
||||||
|
from tensorflow_privacy.privacy.optimizers.dp_optimizer import DPGradientDescentOptimizer
|
||||||
|
|
|
@ -33,11 +33,15 @@ from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
import sys
|
||||||
|
|
||||||
from absl import app
|
from absl import app
|
||||||
from absl import flags
|
from absl import flags
|
||||||
|
|
||||||
from privacy.analysis.rdp_accountant import compute_rdp
|
# Opting out of loading all sibling packages and their dependencies.
|
||||||
|
sys.skip_tf_privacy_import = True
|
||||||
|
|
||||||
|
from privacy.analysis.rdp_accountant import compute_rdp # pylint: disable=g-import-not-at-top
|
||||||
from privacy.analysis.rdp_accountant import get_privacy_spent
|
from privacy.analysis.rdp_accountant import get_privacy_spent
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
Loading…
Reference in a new issue