code: def test_bmm_attention():
      b, t, h = 3, 2, 5
      enc_h = torch.randn(b, t, h)
      w = torch.randn(b, t)
      naive = torch.sum(enc_h * w.view(b, t, 1), dim=1)
      # (b, 1, t) x (b, t, h) -> (b, 1, h)
      fast = torch.matmul(w.unsqueeze(1), enc_h).squeeze(1)
      import numpy
  
      numpy.testing.assert_allclose(
          naive.numpy(), fast.numpy(), 1e-6, 1e-6
      )
  
imports: import torch
  from espnet.nets.pytorch_backend.nets_utils import pad_list
label_desc: Use image node_id 2 for calling a global function with example usage: test_bmm_attention() without return types