Skip to content
Snippets Groups Projects
Commit fa07a154 authored by Michael Reneer's avatar Michael Reneer Committed by tensorflow-copybara
Browse files

Remove the `tff.framework.set_default_executor` API.

* Removed the `tff.framework.set_default_executor` API.
* Updated the callers to use the higher-level convienent API `tff.backends.*` instead.

PiperOrigin-RevId: 321421612
parent d6027b4f
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,6 @@ py_library(
"//tensorflow_federated/python/core/impl/context_stack:get_context_stack",
"//tensorflow_federated/python/core/impl/context_stack:set_default_context",
"//tensorflow_federated/python/core/impl/executors:caching_executor",
"//tensorflow_federated/python/core/impl/executors:default_executor",
"//tensorflow_federated/python/core/impl/executors:eager_tf_executor",
"//tensorflow_federated/python/core/impl/executors:execution_context",
"//tensorflow_federated/python/core/impl/executors:executor_base",
......
......@@ -53,7 +53,6 @@ from tensorflow_federated.python.core.impl.context_stack.context_stack_base impo
from tensorflow_federated.python.core.impl.context_stack.get_context_stack import get_context_stack
from tensorflow_federated.python.core.impl.context_stack.set_default_context import set_default_context
from tensorflow_federated.python.core.impl.executors.caching_executor import CachingExecutor
from tensorflow_federated.python.core.impl.executors.default_executor import set_default_executor
from tensorflow_federated.python.core.impl.executors.eager_tf_executor import EagerTFExecutor
from tensorflow_federated.python.core.impl.executors.execution_context import ExecutionContext
from tensorflow_federated.python.core.impl.executors.executor_base import Executor
......
......@@ -13,38 +13,11 @@
# limitations under the License.
"""Utilities to interact with the default executor."""
from tensorflow_federated.python.core.impl import reference_executor
from tensorflow_federated.python.core.impl.context_stack import context_stack_impl
from tensorflow_federated.python.core.impl.executors import execution_context
from tensorflow_federated.python.core.impl.executors import executor_factory
from tensorflow_federated.python.core.impl.executors import executor_stacks
def set_default_executor(executor_factory_instance):
"""Places an `executor`-backed execution context at the top of the stack.
Note: This function is deprecated, please use
`tff.framework.set_default_context` instead.
Args:
executor_factory_instance: An instance of
`executor_factory.ExecutorFactory`.
"""
if isinstance(executor_factory_instance, executor_factory.ExecutorFactory):
context = execution_context.ExecutionContext(executor_factory_instance)
elif isinstance(executor_factory_instance,
reference_executor.ReferenceExecutor):
# TODO(b/148233458): ReferenceExecutor inherits from ExectionContext and is
# used as-is here. The plan is to migrate it to the new Executor base class
# and stand it up inside a factory like all other executors.
context = executor_factory_instance
else:
raise TypeError('Expected `executor_factory_instance` to be of type '
'`executor_factory.ExecutorFactory`, found {}.'.format(
type(executor_factory_instance)))
context_stack_impl.context_stack.set_default_context(context)
def initialize_default_execution_context():
factory = executor_stacks.local_executor_factory()
context = execution_context.ExecutionContext(factory)
......
......@@ -14,50 +14,10 @@
from absl.testing import absltest
from tensorflow_federated.python.core.impl import reference_executor
from tensorflow_federated.python.core.impl.context_stack import context_stack_impl
from tensorflow_federated.python.core.impl.context_stack import context_stack_test_utils
from tensorflow_federated.python.core.impl.executors import default_executor
from tensorflow_federated.python.core.impl.executors import execution_context
from tensorflow_federated.python.core.impl.executors import executor_factory
class TestSetDefaultExecutor(absltest.TestCase):
def setUp(self):
super().setUp()
context = context_stack_test_utils.TestContext()
context_stack_impl.context_stack.set_default_context(context)
def test_with_executor_factory(self):
context_stack = context_stack_impl.context_stack
executor_factory_impl = executor_factory.ExecutorFactoryImpl(lambda _: None)
self.assertNotIsInstance(context_stack.current,
execution_context.ExecutionContext)
default_executor.set_default_executor(executor_factory_impl)
self.assertIsInstance(context_stack.current,
execution_context.ExecutionContext)
self.assertIs(context_stack.current._executor_factory,
executor_factory_impl)
# TODO(b/148233458): ReferenceExecutor is special cased by the implementation
# of `set_default_executor.set_default_executor`. This test exists to ensure
# that this case is handled well, but can be removed when that special casing
# is removed.
def test_with_reference_executor(self):
context_stack = context_stack_impl.context_stack
executor = reference_executor.ReferenceExecutor()
self.assertIsNot(context_stack.current, executor)
default_executor.set_default_executor(executor)
self.assertIs(context_stack.current, executor)
def test_raises_type_error_with_none(self):
with self.assertRaises(TypeError):
default_executor.set_default_executor(None)
class TestInitializeDefaultExecutionContext(absltest.TestCase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment