code: def complex_backpropagate(
      loss,
      optimizer,
      model,
      fp16,
      n_gpu,
      gradient_accumulation_steps,
      max_grad_norm,
  ):
      if n_gpu > 1:
          loss = loss.mean()  # mean() to average on multi-gpu.
      if gradient_accumulation_steps > 1:
          loss = loss / gradient_accumulation_steps
      if fp16:
          # noinspection PyUnresolvedReferences,PyPackageRequirements
          from apex import amp
  
          with amp.scale_loss(loss, optimizer) as scaled_loss:
              scaled_loss.backward()
          torch.nn.utils.clip_grad_norm_(
              amp.master_params(optimizer), max_grad_norm
          )
      else:
          loss.backward()
          torch.nn.utils.clip_grad_norm_(
              model.parameters(), max_grad_norm
          )
      return loss
  
file_path: jiant/jiant/shared/runner.py
imports: import os
  from typing import Union, Optional
  import torch
  import torch.nn
  import jiant.shared.caching
  import jiant.utils.python.io
  import jiant.utils.torch_utils
label_desc: Use image node_id 1 for calling a global function with example usage: complex_backpropagate(loss, optimizer, model, fp16, n_gpu, gradient_accumulation_steps, max_grad_norm) and returns: loss