tensorflow / tensorflow/privacy
Optimizers.dp_optimizer_keras is not working under PlaidML-keras
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 477
- Avg merge
- 22h 12m
- Merged PRs (30d)
- 1
Description
Set-up:
tensorflow==2.4.0
tensorflow-privacy == 0.5.1
plaidml == 0.7.0
plaidml-keras == 0.7.0
Mac OS 10.15.7 (19H114) 16"
AMD Radeon Pro 5300M 4 GB
Problem:
Hello everyone.
I have been playing with some privacy-preserving mechanisms, and I got an error.
raise ValueError('Could not interpret optimizer identifier: ' +
ValueError: Could not interpret optimizer identifier: <tensorflow_privacy.privacy.optimizers.dp_optimizer_keras.make_keras_optimizer_class.<locals>.DPOptimizerClass object at 0x10e9047f0>
That appears when I add the
optimizer = DPKerasSGDOptimizer(
l2_norm_clip=l2_norm_clip,
noise_multiplier=noise_multiplier,
num_microbatches=num_microbatches,
learning_rate=learning_rate)
from here: from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasSGDOptimizer
Since in venv/lib/python3.8/site-packages/keras/optimizers.py line 788 if K.backend() == 'tensorflow': and in my case is: plaidml.keras.backend the exit on this function is the last one.
If I just return the identifier changing the if block in optimizers.py I got this:
ValueError Traceback (most recent call last)
<ipython-input-5-428b9b0ace60> in <module>
35 optimizer=optimizer,
36 metrics=['accuracy'])
---> 37 model.fit(x_train, y_train,
38 batch_size=batch_size,
39 epochs=epochs,
~venv/lib/python3.8/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
1008 else:
1009 ins = x + y + sample_weights
-> 1010 self._make_train_function()
1011 f = self.train_function
1012
~venv/lib/python3.8/site-packages/keras/engine/training.py in _make_train_function(self)
505 with K.name_scope('training'):
506 with K.name_scope(self.optimizer.__class__.__name__):
--> 507 training_updates = self.optimizer.get_updates(
508 params=self._collected_trainable_weights,
509 loss=self.total_loss)
~venv/lib/python3.8/site-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py in get_updates(self, loss, params)
725
726 def get_updates(self, loss, params):
--> 727 grads = self.get_gradients(loss, params)
728 grads_and_vars = list(zip(grads, params))
729 self._assert_valid_dtypes([
~venv/lib/python3.8/site-packages/tensorflow_privacy/privacy/optimizers/dp_optimizer_keras.py in get_gradients(self, loss, params)
127 # in dp_optimizer.py, except that this returns only the gradients,
128 # not the gradients and variables.
--> 129 microbatch_losses = tf.reshape(loss, [self._num_microbatches, -1])
130 sample_params = (
131 self._dp_sum_query.derive_sample_params(self._global_state))
~venv/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~venv/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in reshape(tensor, shape, name)
193 A `Tensor`. Has the same type as `tensor`.
194 """
--> 195 result = gen_array_ops.reshape(tensor, shape, name)
196 tensor_util.maybe_set_static_shape(result, shape)
197 return result
~env/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py in reshape(tensor, shape, name)
8370 pass
8371 try:
-> 8372 return reshape_eager_fallback(
8373 tensor, shape, name=name, ctx=_ctx)
8374 except _core._SymbolicException:
~venv/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py in reshape_eager_fallback(tensor, shape, name, ctx)
8391
8392 def reshape_eager_fallback(tensor, shape, name, ctx):
-> 8393 _attr_T, (tensor,) = _execute.args_to_matching_eager([tensor], ctx, [])
8394 _attr_Tshape, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ], _dtypes.int32)
8395 _inputs_flat = [tensor, shape]
~venv/lib/python3.8/site-packages/tensorflow/python/eager/execute.py in args_to_matching_eager(l, ctx, allowed_dtypes, default_dtype)
271
272 if tensor is None:
--> 273 tensor = ops.convert_to_tensor(
274 t, dtype, preferred_dtype=default_dtype, ctx=ctx)
275
~venv/lib/python3.8/site-packages/tensorflow/python/profiler/trace.py in wrapped(*args, **kwargs)
161 with Trace(trace_name, **trace_kwargs):
162 return func(*args, **kwargs)
--> 163 return func(*args, **kwargs)
164
165 return wrapped
~venv/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, dtype_hint, ctx, accepted_result_types)
1538
1539 if ret is None:
-> 1540 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
1541
1542 if ret is NotImplemented:
~venv/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref)
337 as_ref=False):
338 _ = as_ref
--> 339 return constant(v, dtype=dtype, name=name)
340
341
~venv/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name)
262 ValueError: if called on a symbolic tensor.
263 """
--> 264 return _constant_impl(value, dtype, shape, name, verify_shape=False,
265 allow_broadcast=True)
266
~venv/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast)
274 with trace.Trace("tf.constant"):
275 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
--> 276 return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
277
278 g = ops.get_default_graph()
~venv/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py in _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
299 def _constant_eager_impl(ctx, value, dtype, shape, verify_shape):
300 """Implementation of eager constant."""
--> 301 t = convert_to_eager_tensor(value, ctx, dtype)
302 if shape is None:
303 return t
~venv/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
96 dtype = dtypes.as_dtype(dtype).as_datatype_enum
97 ctx.ensure_initialized()
---> 98 return ops.EagerTensor(value, ctx.device_name, dtype)
99
100
ValueError: TypeError: object of type 'Value' has no len()
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported setup with tensorflow_privacy.privacy.optimizers.dp_optimizer_keras and the PlaidML Keras backend, then inspect the optimizer integration shown in dp_optimizer_keras.py and the reported Keras optimizer handling. Done means establishing whether this combination can work and covering the supported behavior or limitation with an appropriate test or documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100