code: def test_embeddings_trainable_params(self):
      for params, init_case in itertools.product(
          self.PARAMS, self.cases()
      ):
          emb = Embeddings(**init_case)
          trainable_params = {
              n: p for n, p in emb.named_parameters() if p.requires_grad
          }
          # first check there's nothing unexpectedly not trainable
          for key in emb.state_dict():
              if key not in trainable_params:
                  if (
                      key.endswith("emb_luts.0.weight")
                      and init_case["freeze_word_vecs"]
                  ):
                      # ok: word embeddings shouldn't be trainable
                      # if word vecs are freezed
                      continue
                  if key.endswith(".pe.pe"):
                      # ok: positional encodings shouldn't be trainable
                      assert init_case["position_encoding"]
                      continue
                  else:
                      self.fail(
                          "Param {:s} is unexpectedly not "
                          "trainable.".format(key)
                      )
          # then check nothing unexpectedly trainable
          if init_case["freeze_word_vecs"]:
              self.assertFalse(
                  any(
                      trainable_param.endswith("emb_luts.0.weight")
                      for trainable_param in trainable_params
                  ),
                  "Word embedding is trainable but word vecs are freezed.",
              )
          if init_case["position_encoding"]:
              self.assertFalse(
                  any(
                      trainable_p.endswith(".pe.pe")
                      for trainable_p in trainable_params
                  ),
                  "Positional encoding is trainable.",
              )
  
file_path: OpenNMT-py/onmt/tests/test_embeddings.py
imports: import unittest
  from onmt.modules.embeddings import Embeddings
  import itertools
  from copy import deepcopy
  import torch
  from torch.nn.init import xavier_uniform_
  from onmt.tests.utils_for_tests import product_dict
label_desc: Use image node_id 6 for calling the TestEmbeddings obj's underlying member method code with example usage: obj.test_embeddings_trainable_params() without return types