TFF error:RuntimeError: The eager executor may only be used in eager mode.

created at 02-14-2022 views: 10

error

E:\Anaconda3\python.exe "D:/Program Files/PyCharm 2019.2/machinelearning/homework/test.py"
Traceback (most recent call last):
  File "D:/***/test.py", line 41, in <module>
    state = trainer.initialize()
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\utils\function_utils.py", line 521, in __call__
    return context.invoke(self, arg)
  File "E:\Anaconda3\lib\site-packages\retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "E:\Anaconda3\lib\site-packages\retrying.py", line 206, in call
    return attempt.get(self._wrap_exception)
  File "E:\Anaconda3\lib\site-packages\retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "E:\Anaconda3\lib\site-packages\six.py", line 703, in reraise
    raise value
  File "E:\Anaconda3\lib\site-packages\retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\execution_context.py", line 208, in invoke
    with executor_closer(self._executor_factory, cardinalities) as executor:
  File "E:\Anaconda3\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\execution_context.py", line 193, in executor_closer
    ex = ex_factory.create_executor(cardinalities)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\executor_stacks.py", line 97, in create_executor
    ex = self._executor_stack_fn(cardinalities)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\executor_stacks.py", line 504, in create_executor
    executors = self._flat_stack_fn(cardinalities)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\executor_stacks.py", line 456, in create_executor_list
    federated_stack_factory.create_executor(cardinalities=cardinalities)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\executor_stacks.py", line 409, in create_executor
    placement=placement_literals.SERVER),
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\executor_stacks.py", line 296, in create_executor
    eager_ex = eager_tf_executor.EagerTFExecutor(device=device)
  File "E:\Anaconda3\lib\site-packages\tensorflow_federated\python\core\impl\executors\eager_tf_executor.py", line 482, in __init__
    raise RuntimeError('The eager executor may only be used in eager mode.')
RuntimeError: The eager executor may only be used in eager mode.

analyze

eager executor can only be used in eager mode, there is a code in the original text:

tf.compat.v1.disable_eager_execution()

conflict with it.

solution

Comment out:

tf.compat.v1.disable_eager_execution()
created at:02-14-2022
edited at: 02-14-2022: