docstr: Creates a nmtmodel with a custom opt function.
  Forwards a testbatch and checks output size.
  
  Args:
      opt: Namespace with options
      source_l: length of input sequence
      bsize: batchsize
docstr_tok: ["Creates","a","nmtmodel","with","a","custom","opt","function",".","Forwards","a","testbatch","and","checks","output","size",".","Args",":","opt",":","Namespace","with","options","source_l",":","length","of","input","sequence","bsize",":","batchsize"]
code: def nmtmodel_forward(self, opt, source_l=3, bsize=1):
      """
      Creates a nmtmodel with a custom opt function.
      Forwards a testbatch and checks output size.
  
      Args:
          opt: Namespace with options
          source_l: length of input sequence
          bsize: batchsize
      """
      if opt.hidden_size > 0:
          opt.enc_hid_size = opt.hidden_size
          opt.dec_hid_size = opt.hidden_size
      vocabs = self.get_vocabs()
  
      embeddings = build_embeddings(opt, vocabs)
      enc = build_encoder(opt, embeddings)
  
      embeddings = build_embeddings(opt, vocabs, for_encoder=False)
      dec = build_decoder(opt, embeddings)
  
      model = onmt.models.model.NMTModel(enc, dec)
  
      test_src, test_tgt, test_length = self.get_batch(
          source_l=source_l, bsize=bsize
      )
      output, attn = model(test_src, test_tgt, test_length)
      outputsize = torch.zeros(bsize, source_l - 1, opt.dec_hid_size)
      # Make sure that output has the correct size and type
      self.assertEqual(output.size(), outputsize.size())
      self.assertEqual(type(output), torch.Tensor)
  
imports: import copy
  import unittest
  import torch
  import pyonmttok
  from onmt.constants import DefaultTokens
  from collections import Counter
  import onmt
  import onmt.inputters
  import onmt.opts
  from onmt.model_builder import build_embeddings, build_encoder, build_decoder
  from onmt.utils.parse import ArgumentParser
label_desc: Use image node_id 6 for calling the TestModel obj's underlying member method code with example usage: obj.nmtmodel_forward(opt, source_l, bsize) without return types