def _ConstructDebuggerPluginWithGrpcPort(context):
    try:
        # pylint: disable=line-too-long,g-import-not-at-top
        from tensorboard.plugins.debugger import debugger_plugin as debugger_plugin_lib
        from tensorboard.plugins.debugger import interactive_debugger_plugin as interactive_debugger_plugin_lib
        # pylint: enable=line-too-long,g-import-not-at-top
    except ImportError as err:
        (unused_type, unused_value, traceback) = sys.exc_info()
        six.reraise(
            ImportError,
            ImportError(err.message +
                        '\n\nTo use the debugger plugin, you need to have '
                        'gRPC installed:\n  pip install grpcio'), traceback)

    if FLAGS.debugger_port > 0:
        interactive_plugin = (
            interactive_debugger_plugin_lib.InteractiveDebuggerPlugin(context))
        tf.logging.info('Starting Interactive Debugger Plugin at gRPC port %d',
                        FLAGS.debugger_data_server_grpc_port)
        interactive_plugin.listen(FLAGS.debugger_port)
        return interactive_plugin
    elif FLAGS.debugger_data_server_grpc_port > 0:
        noninteractive_plugin = debugger_plugin_lib.DebuggerPlugin(context)
        tf.logging.info(
            'Starting Non-interactive Debugger Plugin at gRPC port %d',
            FLAGS.debugger_data_server_grpc_port)
        noninteractive_plugin.listen(FLAGS.debugger_data_server_grpc_port)
        return noninteractive_plugin
    return None
Пример #2
0
def _ConstructDebuggerPluginWithGrpcPort(context):
    try:
        # pylint: disable=line-too-long,g-import-not-at-top
        from tensorboard.plugins.debugger import debugger_plugin as debugger_plugin_lib
        from tensorboard.plugins.debugger import interactive_debugger_plugin as interactive_debugger_plugin_lib
        # pylint: enable=line-too-long,g-import-not-at-top
    except ImportError as e:
        e_type, e_value, e_traceback = sys.exc_info()
        message = e.msg if hasattr(e,
                                   'msg') else e.message  # Handle py2 vs py3
        if 'grpc' in message:
            e_value = ImportError(
                message + '\n\nTo use the debugger plugin, you need to have '
                'gRPC installed:\n  pip install grpcio')
        six.reraise(e_type, e_value, e_traceback)

    if FLAGS.debugger_port > 0:
        interactive_plugin = (
            interactive_debugger_plugin_lib.InteractiveDebuggerPlugin(context))
        tf.logging.info('Starting Interactive Debugger Plugin at gRPC port %d',
                        FLAGS.debugger_data_server_grpc_port)
        interactive_plugin.listen(FLAGS.debugger_port)
        return interactive_plugin
    elif FLAGS.debugger_data_server_grpc_port > 0:
        noninteractive_plugin = debugger_plugin_lib.DebuggerPlugin(context)
        tf.logging.info(
            'Starting Non-interactive Debugger Plugin at gRPC port %d',
            FLAGS.debugger_data_server_grpc_port)
        noninteractive_plugin.listen(FLAGS.debugger_data_server_grpc_port)
        return noninteractive_plugin
    return None
    def load(self, context):
        """Returns the debugger plugin, if possible.

        Args:
          context: The TBContext flags including `add_arguments`.

        Returns:
          A DebuggerPlugin instance or None if it couldn't be loaded.
        """
        flags = context.flags
        if flags.debugger_data_server_grpc_port > 0 or flags.debugger_port > 0:
            # Verify that the required Python packages are installed.
            try:
                # pylint: disable=unused-import
                import tensorflow  # noqa: F401
            except ImportError:
                raise ImportError(
                    "To use the debugger plugin, you need to have TensorFlow installed:\n"
                    "  pip install tensorflow"
                )

        if flags.debugger_data_server_grpc_port > 0:
            from tensorboard.plugins.debugger import (
                debugger_plugin as debugger_plugin_lib,
            )

            # debugger_data_server_grpc opens the non-interactive Debugger Plugin,
            # which appears as health pills in the Graph Plugin.
            noninteractive_plugin = debugger_plugin_lib.DebuggerPlugin(context)
            logger.info(
                "Starting Non-interactive Debugger Plugin at gRPC port %d",
                flags.debugger_data_server_grpc_port,
            )
            noninteractive_plugin.listen(flags.debugger_data_server_grpc_port)
            return noninteractive_plugin
        elif flags.debugger_port > 0:
            from tensorboard.plugins.debugger import (
                interactive_debugger_plugin as interactive_debugger_plugin_lib,
            )

            interactive_plugin = interactive_debugger_plugin_lib.InteractiveDebuggerPlugin(
                context
            )
            logger.info(
                "Starting Interactive Debugger Plugin at gRPC port %d",
                flags.debugger_data_server_grpc_port,
            )
            interactive_plugin.listen(flags.debugger_port)
            return interactive_plugin
        else:
            # If neither the debugger_data_server_grpc_port flag or the grpc_port
            # flag is specified, we instantiate a dummy plugin as a placeholder for
            # the frontend. The dummy plugin will display a message indicating that
            # the plugin is not active. It'll also display a command snippet to
            # illustrate how to activate the interactive Debugger Plugin.
            return InactiveDebuggerPlugin()
    def setUp(self):
        super(InteractiveDebuggerPluginTest, self).setUp()

        self._dummy_logdir = tempfile.mkdtemp()
        dummy_multiplexer = event_multiplexer.EventMultiplexer({})
        self._debugger_port = portpicker.pick_unused_port()
        self._debugger_url = "grpc://localhost:%d" % self._debugger_port
        context = base_plugin.TBContext(logdir=self._dummy_logdir,
                                        multiplexer=dummy_multiplexer)
        self._debugger_plugin = interactive_debugger_plugin.InteractiveDebuggerPlugin(
            context)
        self._debugger_plugin.listen(self._debugger_port)

        wsgi_app = application.TensorBoardWSGI([self._debugger_plugin])
        self._server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse)
  def load(self, context):
    """Returns the debugger plugin, if possible.

    Args:
      context: The TBContext flags including `add_arguments`.

    Returns:
      A DebuggerPlugin instance or None if it couldn't be loaded.
    """
    if not (context.flags.debugger_data_server_grpc_port > 0 or
            context.flags.debugger_port > 0):
      return None
    flags = context.flags
    try:
      # pylint: disable=line-too-long,g-import-not-at-top
      from tensorboard.plugins.debugger import debugger_plugin as debugger_plugin_lib
      from tensorboard.plugins.debugger import interactive_debugger_plugin as interactive_debugger_plugin_lib
      # pylint: enable=line-too-long,g-import-not-at-top
    except ImportError as e:
      e_type, e_value, e_traceback = sys.exc_info()
      message = e.msg if hasattr(e, 'msg') else e.message  # Handle py2 vs py3
      if 'grpc' in message:
        e_value = ImportError(
            message +
            '\n\nTo use the debugger plugin, you need to have '
            'gRPC installed:\n  pip install grpcio')
      six.reraise(e_type, e_value, e_traceback)
    if flags.debugger_port > 0:
      interactive_plugin = (
          interactive_debugger_plugin_lib.InteractiveDebuggerPlugin(context))
      logger.info('Starting Interactive Debugger Plugin at gRPC port %d',
                   flags.debugger_data_server_grpc_port)
      interactive_plugin.listen(flags.debugger_port)
      return interactive_plugin
    elif flags.debugger_data_server_grpc_port > 0:
      noninteractive_plugin = debugger_plugin_lib.DebuggerPlugin(context)
      logger.info('Starting Non-interactive Debugger Plugin at gRPC port %d',
                   flags.debugger_data_server_grpc_port)
      noninteractive_plugin.listen(flags.debugger_data_server_grpc_port)
      return noninteractive_plugin
    raise AssertionError()