//  [python]
def test_model_rope_scaling(self):
        config, _ = self.model_tester.prepare_config_and_inputs_for_common()
        hidden_size = config.hidden_size
        num_heads = config.num_attention_heads
        head_dim = hidden_size // num_heads
        scaling_factor = 10
        short_input_length = 10
        long_input_length = int(config.max_position_embeddings * 1.5)

        # Inputs
        x = torch.randn(1, dtype=torch.float32, device=torch_device)  # used exlusively to get the dtype and the device

        # Sanity check original RoPE
        original_rope = PhiRotaryEmbedding(
            head_dim,
            max_position_embeddings=config.max_position_embeddings,
            base=config.rope_theta,
        ).to(torch_device)
        original_cos_short, original_sin_short = original_rope(x, short_input_length)
        original_cos_long, original_sin_long = original_rope(x, long_input_length)
        torch.testing.assert_allclose(original_cos_short, original_cos_long[:short_input_length, :])
        torch.testing.assert_allclose(original_sin_short, original_sin_long[:short_input_length, :])

        # Sanity check linear RoPE scaling
        # New position "x" should match original position with index "x/scaling_factor"
        linear_scaling_rope = PhiLinearScalingRotaryEmbedding(
            head_dim,
            max_position_embeddings=config.max_position_embeddings,
            base=config.rope_theta,
            scaling_factor=scaling_factor,
        ).to(torch_device)
        linear_cos_short, linear_sin_short = linear_scaling_rope(x, short_input_length)
        linear_cos_long, linear_sin_long = linear_scaling_rope(x, long_input_length)
        torch.testing.assert_allclose(linear_cos_short, linear_cos_long[:short_input_length, :])
        torch.testing.assert_allclose(linear_sin_short, linear_sin_long[:short_input_length, :])
        for new_position in range(0, long_input_length, scaling_factor):
            original_position = int(new_position // scaling_factor)
            torch.testing.assert_allclose(linear_cos_long[new_position, :], original_cos_long[original_position, :])
            torch.testing.assert_allclose(linear_sin_long[new_position, :], original_sin_long[original_position, :])

        # Sanity check Dynamic NTK RoPE scaling
        # Scaling should only be observed after a long input is fed. We can observe that the frequencies increase
        # with scaling_factor (or that `inv_freq` decreases)
        ntk_scaling_rope = PhiDynamicNTKScalingRotaryEmbedding(
            head_dim,
            max_position_embeddings=config.max_position_embeddings,
            base=config.rope_theta,
            scaling_factor=scaling_factor,
        ).to(torch_device)
        ntk_cos_short, ntk_sin_short = ntk_scaling_rope(x, short_input_length)
        ntk_cos_long, ntk_sin_long = ntk_scaling_rope(x, long_input_length)
        torch.testing.assert_allclose(ntk_cos_short, original_cos_short)
        torch.testing.assert_allclose(ntk_sin_short, original_sin_short)
        with self.assertRaises(AssertionError):
            torch.testing.assert_allclose(ntk_cos_long, original_cos_long)
        with self.assertRaises(AssertionError):
            torch.testing.assert_allclose(ntk_sin_long, original_sin_long)
        self.assertTrue((ntk_scaling_rope.inv_freq <= original_rope.inv_freq).all())