code: def test_positional_emb_weights_against_marian(self):
      desired_weights = torch.tensor(
          [
              [0, 0, 0, 0, 0],
              [
                  0.84147096,
                  0.82177866,
                  0.80180490,
                  0.78165019,
                  0.76140374,
              ],
              [
                  0.90929741,
                  0.93651021,
                  0.95829457,
                  0.97505713,
                  0.98720258,
              ],
          ]
      )
      emb1 = SinusoidalPositionalEmbedding(
          num_positions=512,
          embedding_dim=512,
          padding_idx=self.padding_idx,
      ).to(torch_device)
      weights = emb1.weights.data[:3, :5]
      # XXX: only the 1st and 3rd lines match - this is testing against
      # verbatim copy of SinusoidalPositionalEmbedding from fairseq
      self.assertTrue(
          torch.allclose(weights, desired_weights, atol=self.tolerance),
          msg=f"\nexp:\n{desired_weights}\ngot:\n{weights}\n",
      )
  
      # test that forward pass is just a lookup, there is no ignore padding logic
      input_ids = torch.tensor(
          [
              [
                  4,
                  10,
                  self.padding_idx,
                  self.padding_idx,
                  self.padding_idx,
              ]
          ],
          dtype=torch.long,
          device=torch_device,
      )
      no_cache_pad_zero = emb1(input_ids)[0]
      # XXX: only the 1st line matches the 3rd
      self.assertTrue(
          torch.allclose(
              torch.tensor(desired_weights, device=torch_device),
              no_cache_pad_zero[:3, :5],
              atol=1e-3,
          )
      )
  
imports: import tempfile
  import unittest
  import timeout_decorator
  from parameterized import parameterized
  from transformers import FSMTConfig, is_torch_available
  from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, require_torch_fp16, slow, torch_device
  from transformers.utils import cached_property
  from ...generation.test_utils import GenerationTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 3 for calling the TestSinusoidalPositionalEmbeddings obj's underlying member method code with example usage: obj.test_positional_emb_weights_against_marian() without return types