Repository: huggingface/transformers
Pull request: Fix deprecated PT functions

These functions are deprecated in PT 2.0

Changed files:
filename: tests/generation/test_utils.py
patch: @@ -2724,7 +2724,7 @@ def test_cache_dependant_input_preparation_exporting(self):
         # Case 1
         input_ids = torch.randint(0, 16, (2, 8), dtype=torch.int64)[:, :0]
         inputs_embeds = torch.rand((2, 8), dtype=torch.float32)
-        cache_position = torch.range(0, 7, dtype=torch.int64)
+        cache_position = torch.arange(0, 8, dtype=torch.int64)
         eager1, eager2 = GenerationMixin()._cache_dependant_input_preparation(input_ids, inputs_embeds, cache_position)
         export1, export2 = GenerationMixin()._cache_dependant_input_preparation_exporting(
             input_ids, inputs_embeds, cache_position
@@ -2735,7 +2735,7 @@ def test_cache_dependant_input_preparation_exporting(self):
         # Case 2
         input_ids = torch.randint(0, 16, (2, 8), dtype=torch.int64)
         inputs_embeds = torch.rand((2, 8), dtype=torch.float32)
-        cache_position = torch.range(0, 7, dtype=torch.int64)
+        cache_position = torch.arange(0, 8, dtype=torch.int64)
         eager1, eager2 = GenerationMixin()._cache_dependant_input_preparation(input_ids, inputs_embeds, cache_position)
         export1, export2 = GenerationMixin()._cache_dependant_input_preparation_exporting(
             input_ids, inputs_embeds, cache_position
@@ -2746,7 +2746,7 @@ def test_cache_dependant_input_preparation_exporting(self):
         # Case 3
         input_ids = torch.randint(0, 16, (2, 12), dtype=torch.int64)
         inputs_embeds = None
-        cache_position = torch.range(0, 7, dtype=torch.int64)
+        cache_position = torch.arange(0, 8, dtype=torch.int64)
         eager1, eager2 = GenerationMixin()._cache_dependant_input_preparation(input_ids, inputs_embeds, cache_position)
         export1, export2 = GenerationMixin()._cache_dependant_input_preparation_exporting(
             input_ids, inputs_embeds, cache_position
@@ -2757,7 +2757,7 @@ def test_cache_dependant_input_preparation_exporting(self):
         # Case 4
         input_ids = torch.randint(0, 16, (2, 8), dtype=torch.int64)
         inputs_embeds = None
-        cache_position = torch.range(0, 7, dtype=torch.int64)
+        cache_position = torch.arange(0, 8, dtype=torch.int64)
         eager1, eager2 = GenerationMixin()._cache_dependant_input_preparation(input_ids, inputs_embeds, cache_position)
         export1, export2 = GenerationMixin()._cache_dependant_input_preparation_exporting(
             input_ids, inputs_embeds, cache_position

filename: tests/models/falcon_mamba/test_modeling_falcon_mamba.py
patch: @@ -231,7 +231,7 @@ def create_and_check_falcon_mamba_cached_slow_forward_and_backwards(
             token_emb, cache, cache_position=torch.arange(0, config.conv_kernel, device=input_ids.device)
         )
 
-        loss = torch.log(1 + torch.abs(outputs.sum()))
+        loss = torch.log1p(torch.abs(outputs.sum()))
         self.parent.assertEqual(loss.shape, ())
         self.parent.assertEqual(outputs.shape, (self.batch_size, self.seq_length, self.hidden_size))
         loss.backward()

filename: tests/models/mamba/test_modeling_mamba.py
patch: @@ -205,7 +205,7 @@ def create_and_check_mamba_cached_slow_forward_and_backwards(
             token_emb, cache, cache_position=torch.arange(0, config.conv_kernel, device=input_ids.device)
         )
 
-        loss = torch.log(1 + torch.abs(outputs.sum()))
+        loss = torch.log1p(torch.abs(outputs.sum()))
         self.parent.assertEqual(loss.shape, ())
         self.parent.assertEqual(outputs.shape, (self.batch_size, self.seq_length, self.hidden_size))
         loss.backward()