code: def test_loading_from_pretrained(pretrained_model_name):
      transformer_stack = TransformerStack.from_pretrained_module(
          pretrained_model_name
      ).eval()
      pretrained_module = cached_transformers.get(
          pretrained_model_name, True
      ).encoder.eval()
  
      batch_size = 2
      seq_length = 15
      hidden_size = transformer_stack.layers[0].get_output_dim()
  
      hidden_states = torch.randn(batch_size, seq_length, hidden_size)
      attention_mask = torch.randint(0, 2, (batch_size, seq_length))
      attention_mask_hf = attention_mask[:, None, None, :]
      attention_mask_hf = (1.0 - attention_mask_hf) * -10e5
  
      torch.manual_seed(SEED)
      output = transformer_stack(
          hidden_states, attention_mask=attention_mask
      )
  
      torch.manual_seed(SEED)
      hf_output = pretrained_module(
          hidden_states, attention_mask=attention_mask_hf
      )
  
      assert torch.allclose(output.final_hidden_states, hf_output[0])
  
file_path: allennlp/tests/modules/transformer/transformer_stack_test.py
imports: import copy
  import torch
  import pytest
  from allennlp.common import Params
  from allennlp.common import cached_transformers
  from allennlp.modules.transformer import TransformerStack, TransformerLayer
label_desc: Use image node_id 4 for calling a global function with example usage: test_loading_from_pretrained(pretrained_model_name) without return types