code: def test_layer_outputs(
      layer_list: List[Tuple[str, nn.Module]],
      layer_config: Dict[str, Any],
  ) -> None:
      """Layers in layer_list that share the same underlying module (either a
      torch.nn.Module or opacus.layers.DPModule) should produce the same output
      given the same random seed and different outputs given different random seeds.
  
      Args:
          layer_list: list of tuples of form (layer_name, module)
          layer_config: config for instantiating the layers in layer_list
      """
      random_seed_a = random.randint(0, 100000)
      random_seed_b = random.randint(100000, 200000)
      outputs: Dict[int, Dict[str, torch.Tensor]] = {
          random_seed_a: {},
          random_seed_b: {},
      }
  
      for layer_name, module, gsm_mode_blocklist in layer_list:
          for gsm_mode in GSM_MODES - set(gsm_mode_blocklist):
              for random_seed in (random_seed_a, random_seed_b):
                  logging.error(f"{gsm_mode}, {layer_name}")
                  layer = LayerFactory.create(
                      layer_name=layer_name,
                      batch_size=64,
                      random_seed=random_seed,
                      gsm_mode=gsm_mode,
                      **layer_config,
                  )
                  if layer is None:
                      continue
                  if str(module) not in outputs[random_seed]:
                      outputs[random_seed][
                          str(module)
                      ] = layer.forward_only()
  
                  # same module with same seed should result in same output
                  assert torch.equal(
                      outputs[random_seed][str(module)],
                      layer.forward_only(),
                  )
  
          # same module with different seed should result in different output
          for module_name in outputs[random_seed_a]:
              assert not torch.equal(
                  outputs[random_seed_a][module_name],
                  outputs[random_seed_b][module_name],
              )
  
file_path: opacus/benchmarks/tests/test_layers.py
imports: import copy
  import logging
  import random
  from typing import Any, Dict, List, Tuple, Type
  import pytest
  import torch
  import torch.nn
  from helpers import skipifnocuda
  from opacus.grad_sample import GradSampleModule
  from opacus.grad_sample.gsm_exp_weights import GradSampleModuleExpandedWeights
  from opacus.layers import DPGRU, DPLSTM, DPRNN, DPMultiheadAttention
  from benchmarks.layers import LayerFactory
  from benchmarks.utils import reset_peak_memory_stats
label_desc: Use image node_id 3 for calling a global function with example usage: test_layer_outputs(layer_list, layer_config) without return types