class_docstr: The network wrapper contains multiple copies of the same network, each one with a different set of weights which is
  updating in a different time scale. The network wrapper will always contain an online network.
  It will contain an additional slow updating target network if it was requested by the user,
  and it will contain a global network shared between different workers, if Coach is run in a single-node
  multi-process distributed mode. The network wrapper contains functionality for managing these networks and syncing
  between them.
class_docstr_tok: ["The","network","wrapper","contains","multiple","copies","of","the","same","network",",","each","one","with","a","different","set","of","weights","which","is","updating","in","a","different","time","scale",".","The","network","wrapper","will","always","contain","an","online","network",".","It","will","contain","an","additional","slow","updating","target","network","if","it","was","requested","by","the","user",",","and","it","will","contain","a","global","network","shared","between","different","workers",",","if","Coach","is","run","in","a","single-node","multi-process","distributed","mode",".","The","network","wrapper","contains","functionality","for","managing","these","networks","and","syncing","between","them","."]
docstr: A generic training function that enables multi-threading training using a global network if necessary.
  
  :param inputs: The inputs for the network.
  :param targets: The targets corresponding to the given inputs
  :param additional_fetches: Any additional tensor the user wants to fetch
  :param importance_weights: A coefficient for each sample in the batch, which will be used to rescale the loss
                             error of this sample. If it is not given, the samples losses won't be scaled
  :param use_inputs_for_apply_gradients: Add the inputs also for when applying gradients
                                        (e.g. for incorporating batchnorm update ops)
  :return: The loss of the training iteration
docstr_tok: ["A","generic","training","function","that","enables","multi-threading","training","using","a","global","network","if","necessary",".",":","param","inputs",":","The","inputs","for","the","network",".",":","param","targets",":","The","targets","corresponding","to","the","given","inputs",":","param","additional_fetches",":","Any","additional","tensor","the","user","wants","to","fetch",":","param","importance_weights",":","A","coefficient","for","each","sample","in","the","batch",",","which","will","be","used","to","rescale","the","loss","error","of","this","sample",".","If","it","is","not","given",",","the","samples","losses","wo","n't","be","scaled",":","param","use_inputs_for_apply_gradients",":","Add","the","inputs","also","for","when","applying","gradients","(","e.g",".","for","incorporating","batchnorm","update","ops",")",":","return",":","The","loss","of","the","training","iteration"]
code: def train_and_sync_networks(
      self,
      inputs,
      targets,
      additional_fetches=[],
      importance_weights=None,
      use_inputs_for_apply_gradients=False,
  ):
      """
      A generic training function that enables multi-threading training using a global network if necessary.
  
      :param inputs: The inputs for the network.
      :param targets: The targets corresponding to the given inputs
      :param additional_fetches: Any additional tensor the user wants to fetch
      :param importance_weights: A coefficient for each sample in the batch, which will be used to rescale the loss
                                 error of this sample. If it is not given, the samples losses won't be scaled
      :param use_inputs_for_apply_gradients: Add the inputs also for when applying gradients
                                            (e.g. for incorporating batchnorm update ops)
      :return: The loss of the training iteration
      """
      result = self.online_network.accumulate_gradients(
          inputs,
          targets,
          additional_fetches=additional_fetches,
          importance_weights=importance_weights,
          no_accumulation=True,
      )
      if use_inputs_for_apply_gradients:
          self.apply_gradients_and_sync_networks(
              reset_gradients=False, additional_inputs=inputs
          )
      else:
          self.apply_gradients_and_sync_networks(reset_gradients=False)
  
      return result
  
imports: from typing import List, Tuple
  from rl_coach.base_parameters import Frameworks, AgentParameters
  from rl_coach.logger import failed_imports
  from rl_coach.saver import SaverCollection
  from rl_coach.spaces import SpacesDefinition
  from rl_coach.utils import force_list
label_desc: Use image node_id 7 for calling the NetworkWrapper obj's underlying member method code with example usage: obj.train_and_sync_networks(inputs, targets, additional_fetches, importance_weights, use_inputs_for_apply_gradients) and returns: result