def setup_graph(self):
        """
        Creates our Graph and figures out, which shared/global model to hook up to.
        If we are in a global-model's setup procedure, we do not create
        a new graph (return None as the context). We will instead use the already existing local replica graph
        of the model.

        Returns: None or the graph's as_default()-context.
        """
        graph_default_context = None

        # Single (non-distributed) mode.
        if self.execution_type == "single":
            self.graph = tf.Graph()
            graph_default_context = self.graph.as_default()
            graph_default_context.__enter__()
            self.global_model = None

        # Distributed tf
        elif self.execution_type == "distributed":
            # Parameter-server -> Do not build any graph.
            if self.distributed_spec["job"] == "ps":
                return None

            # worker -> construct the global (main) model; the one hosted on the ps,
            elif self.distributed_spec["job"] == "worker":
                # The local replica model.
                if self.is_local_model:
                    graph = tf.Graph()
                    graph_default_context = graph.as_default()
                    graph_default_context.__enter__()

                    # Now that the graph is created and entered -> deepcopoy ourselves and setup global model first,
                    # then continue.
                    self.global_model = deepcopy(self)
                    # Switch on global construction/setup-mode for the pass to setup().
                    self.global_model.is_local_model = False
                    self.global_model.setup()

                    self.graph = graph
                    self.as_local_model()
                    self.scope += '-worker' + str(self.distributed_spec["task_index"])
                # The global_model (whose Variables are hosted by the ps).
                else:
                    self.graph = tf.get_default_graph()  # lives in the same graph as local model
                    self.global_model = None
                    self.device = tf.train.replica_device_setter(
                        # Place its Variables on the parameter server(s) (round robin).
                        #ps_device="/job:ps",  # default
                        # Train-ops for the global_model are hosted locally (on this worker's node).
                        worker_device=self.device,
                        cluster=self.distributed_spec["cluster_spec"]
                    )
            else:
                raise TensorForceError("Unsupported job type: {}!".format(self.distributed_spec["job"]))
        else:
            raise TensorForceError("Unsupported distributed type: {}!".format(self.distributed_spec["type"]))

        return graph_default_context
def setup_graph(self):
        """
        Creates our Graph and figures out, which shared/global model to hook up to.
        If we are in a global-model's setup procedure, we do not create
        a new graph (return None as the context). We will instead use the already existing local replica graph
        of the model.

        Returns: None or the graph's as_default()-context.
        """
        graph_default_context = None

        # Single (non-distributed) mode.
        if self.execution_type == "single":
            self.graph = tf.Graph()
            graph_default_context = self.graph.as_default()
            graph_default_context.__enter__()
            self.global_model = None

        # Distributed tf
        elif self.execution_type == "distributed":
            # Parameter-server -> Do not build any graph.
            if self.distributed_spec["job"] == "ps":
                return None

            # worker -> construct the global (main) model; the one hosted on the ps,
            elif self.distributed_spec["job"] == "worker":
                # The local replica model.
                if self.is_local_model:
                    graph = tf.Graph()
                    graph_default_context = graph.as_default()
                    graph_default_context.__enter__()

                    # Now that the graph is created and entered -> deepcopoy ourselves and setup global model first,
                    # then continue.
                    self.global_model = deepcopy(self)
                    # Switch on global construction/setup-mode for the pass to setup().
                    self.global_model.is_local_model = False
                    self.global_model.setup()

                    self.graph = graph
                    self.as_local_model()
                    self.scope += '-worker' + str(self.distributed_spec["task_index"])
                # The global_model (whose Variables are hosted by the ps).
                else:
                    self.graph = tf.get_default_graph()  # lives in the same graph as local model
                    self.global_model = None
                    self.device = tf.train.replica_device_setter(
                        # Place its Variables on the parameter server(s) (round robin).
                        #ps_device="/job:ps",  # default
                        # Train-ops for the global_model are hosted locally (on this worker's node).
                        worker_device=self.device,
                        cluster=self.distributed_spec["cluster_spec"]
                    )
            else:
                raise TensorForceError("Unsupported job type: {}!".format(self.distributed_spec["job"]))
        else:
            raise TensorForceError("Unsupported distributed type: {}!".format(self.distributed_spec["type"]))

        return graph_default_context
def setup_graph ( self ) : graph_default_context = None # Single (non-distributed) mode. if self . execution_type == "single" : self . graph = tf . Graph ( ) graph_default_context = self . graph . as_default ( ) graph_default_context . __enter__ ( ) self . global_model = None # Distributed tf elif self . execution_type == "distributed" : # Parameter-server -> Do not build any graph. if self . distributed_spec [ "job" ] == "ps" : return None # worker -> construct the global (main) model; the one hosted on the ps, elif self . distributed_spec [ "job" ] == "worker" : # The local replica model. if self . is_local_model : graph = tf . Graph ( ) graph_default_context = graph . as_default ( ) graph_default_context . __enter__ ( ) # Now that the graph is created and entered -> deepcopoy ourselves and setup global model first, # then continue. self . global_model = deepcopy ( self ) # Switch on global construction/setup-mode for the pass to setup(). self . global_model . is_local_model = False self . global_model . setup ( ) self . graph = graph self . as_local_model ( ) self . scope += '-worker' + str ( self . distributed_spec [ "task_index" ] ) # The global_model (whose Variables are hosted by the ps). else : self . graph = tf . get_default_graph ( ) # lives in the same graph as local model self . global_model = None self . device = tf . train . replica_device_setter ( # Place its Variables on the parameter server(s) (round robin). #ps_device="/job:ps",  # default # Train-ops for the global_model are hosted locally (on this worker's node). worker_device = self . device , cluster = self . distributed_spec [ "cluster_spec" ] ) else : raise TensorForceError ( "Unsupported job type: {}!" . format ( self . distributed_spec [ "job" ] ) ) else : raise TensorForceError ( "Unsupported distributed type: {}!" . format ( self . distributed_spec [ "type" ] ) ) return graph_default_context
Creates our Graph and figures out, which shared/global model to hook up to.
        If we are in a global-model's setup procedure, we do not create
        a new graph (return None as the context). We will instead use the already existing local replica graph
        of the model.

        Returns: None or the graph's as_default()-context.
Creates our Graph and figures out which shared / global model to hook up to . If we are in a global - model s setup procedure we do not create a new graph ( return None as the context ) . We will instead use the already existing local replica graph of the model .