code: def test_topk_func(batch_size, beam_size, target_vocab_size):
      # Random model scores. Shape: (batch_size * beam_size, target_vocab_size)
      scores = onp.random.uniform(
          0, 1, (batch_size * beam_size, target_vocab_size)
      )
      # offset for batch sizes > 1
      offset = onp.repeat(
          onp.arange(
              0, batch_size * beam_size, beam_size, dtype="int32"
          ),
          beam_size,
      )
  
      np_hyp, np_word, np_values = numpy_topk(
          scores, k=beam_size, offset=offset
      )
  
      topk = sockeye.beam_search.TopK(k=beam_size)
      pt_hyp, pt_word, pt_values = topk(pt.tensor(scores))
      if batch_size > 1:
          # Offsetting the indices to match the shape of the scores matrix
          pt_hyp += pt.tensor(offset)
      assert onp.allclose(pt_hyp.detach().numpy(), np_hyp)
      assert onp.allclose(pt_word.detach().numpy(), np_word)
      assert onp.allclose(pt_values.detach().numpy(), np_values)
  
imports: from typing import List, Optional
  from typing import Tuple
  import numpy
  import pytest
  import torch
  import numpy
  import sockeye.beam_search
  import sockeye.constants
  import sockeye.lexicon
  import sockeye.utils
label_desc: Use image node_id 9 for calling a global function with example usage: test_topk_func(batch_size, beam_size, target_vocab_size) without return types