code: def test_encoder_cache(normalize_before):
      adim = 4
      idim = 5
      encoder = Encoder(
          idim=idim,
          attention_dim=adim,
          linear_units=3,
          num_blocks=2,
          normalize_before=normalize_before,
          dropout_rate=0.0,
          input_layer="embed",
      )
      elayer = encoder.encoders[0]
      x = torch.randn(2, 5, adim)
      mask = subsequent_mask(x.shape[1]).unsqueeze(0)
      prev_mask = mask[:, :-1, :-1]
      encoder.eval()
      with torch.no_grad():
          # layer-level test
          y = elayer(x, mask, None)[0]
          cache = elayer(x[:, :-1], prev_mask, None)[0]
          y_fast = elayer(x, mask, cache=cache)[0]
          numpy.testing.assert_allclose(
              y.numpy(), y_fast.numpy(), rtol=RTOL
          )
  
          # encoder-level test
          x = torch.randint(0, idim, x.shape[:2])
          y = encoder.forward_one_step(x, mask)[0]
          y_, _, cache = encoder.forward_one_step(x[:, :-1], prev_mask)
          y_fast, _, _ = encoder.forward_one_step(x, mask, cache=cache)
          numpy.testing.assert_allclose(
              y.numpy(), y_fast.numpy(), rtol=RTOL
          )
  
file_path: espnet/test/test_transformer_decode.py
imports: import numpy
  import pytest
  import torch
  from espnet.nets.pytorch_backend.transformer.decoder import Decoder
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
label_desc: Use image node_id 2 for calling a global function with example usage: test_encoder_cache(normalize_before) without return types