code: def run_backward(ds_config, seq_len, atol=1e-2, verbose=False):
      set_seed(123)
      bert_encoder, ds_encoder = create_models(ds_config)
  
      # prepare test data
      kwargs = kwargs_fp16 if ds_config.fp16 else kwargs_fp32
      hidden_states = torch.randn(
          ds_config.batch_size, seq_len, ds_config.hidden_size, **kwargs
      )
      input_mask = torch.randn(
          ds_config.batch_size, 1, 1, seq_len, **kwargs
      )
      Y = torch.randn(
          ds_config.batch_size, seq_len, ds_config.hidden_size, **kwargs
      )
  
      # run baseline
      base_results = bert_encoder(
          hidden_states,
          input_mask,
          output_all_encoded_layers=False,
          checkpoint_activations=False,
      )
  
      loss = (Y - base_results[0]).pow(2).sum() / 64
      loss.backward()
      base_grads = bert_encoder.get_grads()
  
      # run ds
      ds_results = ds_encoder(
          hidden_states,
          input_mask,
          output_all_encoded_layers=False,
          checkpoint_activations=False,
      )
  
      loss = (Y - ds_results[0]).pow(2).sum() / 64
      loss.backward()
      ds_grads = ds_encoder.get_grads()
  
      # check grads
      check_equal(base_grads, ds_grads, atol=atol, verbose=verbose)
  
imports: import numpy
  import torch
  import pytest
  import random
  import copy
  import os
  from torch import nn
  from deepspeed import DeepSpeedTransformerLayer, DeepSpeedTransformerConfig
  from deepspeed.accelerator import get_accelerator
  from unit.modeling import BertConfig, BertLayerNorm, BertEncoder
  from unit.modelingpreln import BertEncoder
  from unit.common import DistributedTest, is_rocm_pytorch
label_desc: Use image node_id 5 for calling a global function with example usage: run_backward(ds_config, seq_len, atol, verbose) without return types