code: def test_decoder_cache(normalize_before):
      adim = 4
      odim = 5
      decoder = Decoder(
          odim=odim,
          attention_dim=adim,
          linear_units=3,
          num_blocks=2,
          normalize_before=normalize_before,
          dropout_rate=0.0,
      )
      dlayer = decoder.decoders[0]
      memory = torch.randn(2, 5, adim)
  
      x = torch.randn(2, 5, adim) * 100
      mask = subsequent_mask(x.shape[1]).unsqueeze(0)
      prev_mask = mask[:, :-1, :-1]
      decoder.eval()
      with torch.no_grad():
          # layer-level test
          y = dlayer(x, mask, memory, None)[0]
          cache = dlayer(x[:, :-1], prev_mask, memory, None)[0]
          y_fast = dlayer(x, mask, memory, None, cache=cache)[0]
          numpy.testing.assert_allclose(
              y.numpy(), y_fast.numpy(), rtol=RTOL
          )
  
          # decoder-level test
          x = torch.randint(0, odim, x.shape[:2])
          y, _ = decoder.forward_one_step(x, mask, memory)
          y_, cache = decoder.forward_one_step(
              x[:, :-1],
              prev_mask,
              memory,
              cache=decoder.init_state(None),
          )
          y_fast, _ = decoder.forward_one_step(
              x, mask, memory, 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 1 for calling a global function with example usage: test_decoder_cache(normalize_before) without return types