code: def test_embedding_vocab_extension_is_no_op_when_extension_should_not_happen(
      self,
  ):
      # Case1: When vocab is already in sync with embeddings it should be a no-op.
      vocab = Vocabulary({"tokens": {"word1": 1, "word2": 1}})
      embedding_params = Params(
          {"vocab_namespace": "tokens", "embedding_dim": 10}
      )
      embedder = Embedding.from_params(embedding_params, vocab=vocab)
      original_weight = embedder.weight
      embedder.extend_vocab(vocab, "tokens")
      assert torch.all(embedder.weight == original_weight)
  
      # Case2: Shouldn't wrongly assuming "tokens" namespace for extension if no
      # information on vocab_namespece is available. Rather log a warning and be a no-op.
      vocab = Vocabulary()
      vocab.add_token_to_namespace("word1", "tokens")
      vocab.add_token_to_namespace("word2", "tokens")
      embedding_params = Params(
          {"vocab_namespace": "tokens", "embedding_dim": 10}
      )
      embedder = Embedding.from_params(embedding_params, vocab=vocab)
      # Previous models won't have _vocab_namespace attribute. Force it to be None
      embedder._vocab_namespace = None
      embedder.weight = torch.nn.Parameter(embedder.weight[:1, :])
      assert embedder.weight.shape[0] == 1
      embedder.extend_vocab(vocab)  # Don't specify namespace
      assert embedder.weight.shape[0] == 1
  
imports: import gzip
  import warnings
  import numpy
  import pytest
  import torch
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Vocabulary
  from allennlp.modules.token_embedders.embedding import _read_pretrained_embeddings_file, Embedding, EmbeddingsTextFile, format_embeddings_file_uri, parse_embeddings_file_uri
label_desc: Use image node_id 15 for calling the TestEmbedding obj's underlying member method code with example usage: obj.test_embedding_vocab_extension_is_no_op_when_extension_should_not_happen() without return types