code: def test_reparametrize_tie_weights_strict(self, functional_call):
      module = MockTiedModule()
      weight = torch.tensor([[2.0]])
      bias = torch.tensor([5.0])
      buffer = torch.tensor([3.0])
      extra = torch.tensor([1.0])
  
      # Tie weights no error
      parameters = {
          "l1.weight": weight,
          "l1.bias": bias,
          "buffer": buffer,
      }
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a successful call",
      ):
          out = functional_call(
              module, parameters, x, tie_weights=True, strict=True
          )
          self.assertEqual(
              out, x * weight + bias + bias + buffer + buffer
          )
  
      # Tie weights without flag
      parameters = {
          "l1.weight": weight,
          "l1.bias": bias,
          "buffer": buffer,
      }
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a failed call",
      ):
          with self.assertRaisesRegex(
              RuntimeError,
              re.escape("Missing key(s): 'tied_bias', 'tied_buffer'."),
          ):
              out = functional_call(
                  module, parameters, x, tie_weights=False, strict=True
              )
  
      # Tie some weights
      parameters = {"l1.weight": weight, "buffer": buffer}
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a failed call",
      ):
          with self.assertRaisesRegex(
              RuntimeError,
              re.escape("Missing key(s): 'l1.bias', 'tied_bias'."),
          ):
              out = stateless.functional_call(
                  module, parameters, x, tie_weights=True, strict=True
              )
  
      # Tie weights with extra keys
      parameters = {
          "l1.weight": weight,
          "l1.bias": bias,
          "buffer": buffer,
          "extra": extra,
      }
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a failed call",
      ):
          with self.assertRaisesRegex(
              RuntimeError,
              re.escape("Unexpected key(s): 'extra'."),
          ):
              out = stateless.functional_call(
                  module, parameters, x, tie_weights=True, strict=True
              )
  
      # Tie weights with extra keys and without flag
      parameters = {
          "l1.weight": weight,
          "l1.bias": bias,
          "buffer": buffer,
          "extra": extra,
      }
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a failed call",
      ):
          with self.assertRaisesRegex(
              RuntimeError,
              re.escape("Unexpected key(s): 'extra'.")
              + r"\s+"
              + re.escape(
                  "Missing key(s): 'tied_bias', 'tied_buffer'."
              ),
          ):
              out = stateless.functional_call(
                  module, parameters, x, tie_weights=False, strict=True
              )
  
      # Tie some weights with extra keys
      parameters = {
          "l1.weight": weight,
          "buffer": buffer,
          "extra": extra,
      }
      x = torch.randn(1, 1)
      with self._ensure_module_unchanged(
          module,
          "the module should not have been modified by a failed call",
      ):
          with self.assertRaisesRegex(
              RuntimeError,
              re.escape("Unexpected key(s): 'extra'.")
              + r"\s+"
              + re.escape("Missing key(s): 'l1.bias', 'tied_bias'."),
          ):
              out = stateless.functional_call(
                  module, parameters, x, tie_weights=True, strict=True
              )
  
imports: import contextlib
  import os
  import re
  import subprocess
  import sys
  import unittest
  import torch
  import torch.nn.utils.stateless
  from torch.testing._internal.common_cuda import TEST_MULTIGPU
  from torch.testing._internal.common_utils import run_tests, TestCase, parametrize, instantiate_parametrized_tests, subtest
label_desc: Use image node_id 20 for calling the TestStatelessFunctionalAPI obj's underlying member method code with example usage: obj.test_reparametrize_tie_weights_strict(functional_call) without return types