class 					snake_case__       :



   def __init__(				self   :   int			,	A__   :   Any   )							->     str:




         '''simple docstring'''




         snake_case_     :			Optional[Any]       =       data
         snake_case_     :			Union[str, Any]       =       None
         snake_case_     :			Any       =       None



   def __str__(				self   :   int   )							->     int:




         '''simple docstring'''




         return f"{self.data}"



class 					snake_case__       :



   def __init__(				self   :   Dict   )							->     int:




         '''simple docstring'''




         snake_case_     :			List[str]       =       None
         snake_case_     :			int       =       None



   def __iter__(				self   :   int   )							->     Optional[int]:




         '''simple docstring'''




         snake_case_     :			Union[str, Any]       =       self.head
         while node:
               yield node.data
               snake_case_     :			Any       =       node.next



   def __str__(				self   :   Tuple   )							->     str:




         '''simple docstring'''




         return "->".join([str(A__   ) for item in self]   )



   def __len__(				self   :   Union[str, Any]   )							->     Optional[int]:




         '''simple docstring'''




         return sum(1 for _ in self   )



   def 					UpperCAmelCase__       (				self   :   List[str]			,	A__   :   Any   )							->     Tuple:




         '''simple docstring'''




         self.insert_at_nth(0			,	A__   )



   def 					UpperCAmelCase__       (				self   :   Optional[int]			,	A__   :   str   )							->     Tuple:




         '''simple docstring'''




         self.insert_at_nth(len(self   )			,	A__   )



   def 					UpperCAmelCase__       (				self   :   Dict			,	A__   :   int			,	A__   :   str   )							->     Any:




         '''simple docstring'''




         snake_case_     :			Tuple       =       len(self   )

         if not 0 <= index <= length:
               raise IndexError("list index out of range"   )
         snake_case_     :			Dict       =       Node(A__   )
         if self.head is None:
               snake_case_     :			List[Any]       =       new_node
         elif index == 0:
               snake_case_     :			Tuple       =       new_node
               snake_case_     :			int       =       self.head
               snake_case_     :			Optional[Any]       =       new_node
         elif index == length:
               snake_case_     :			Optional[Any]       =       new_node
               snake_case_     :			Dict       =       self.tail
               snake_case_     :			int       =       new_node
         else:
               snake_case_     :			Union[str, Any]       =       self.head
               for _ in range(0			,	A__   ):
                     snake_case_     :			Optional[int]       =       temp.next
               snake_case_     :			Dict       =       new_node
               snake_case_     :			str       =       temp.previous
               snake_case_     :			Optional[int]       =       temp
               snake_case_     :			List[Any]       =       new_node



   def 					UpperCAmelCase__       (				self   :   Union[str, Any]   )							->     List[Any]:




         '''simple docstring'''




         return self.delete_at_nth(0   )



   def 					UpperCAmelCase__       (				self   :   List[str]   )							->     Any:




         '''simple docstring'''




         return self.delete_at_nth(len(self   ) - 1   )



   def 					UpperCAmelCase__       (				self   :   List[str]			,	A__   :   int   )							->     int:




         '''simple docstring'''




         snake_case_     :			Tuple       =       len(self   )

         if not 0 <= index <= length - 1:
               raise IndexError("list index out of range"   )
         snake_case_     :			Dict       =       self.head  # default first node
         if length == 1:
               snake_case_     :			Optional[int]       =       None
         elif index == 0:
               snake_case_     :			Any       =       self.head.next
               snake_case_     :			List[Any]       =       None
         elif index == length - 1:
               snake_case_     :			Optional[int]       =       self.tail
               snake_case_     :			Union[str, Any]       =       self.tail.previous
               snake_case_     :			Any       =       None
         else:
               snake_case_     :			Optional[int]       =       self.head
               for _ in range(0			,	A__   ):
                     snake_case_     :			Optional[Any]       =       temp.next
               snake_case_     :			str       =       temp
               snake_case_     :			Tuple       =       temp.previous
               snake_case_     :			Optional[Any]       =       temp.next
         return delete_node.data



   def 					UpperCAmelCase__       (				self   :   str			,	A__   :   Any   )							->     str:




         '''simple docstring'''




         snake_case_     :			List[str]       =       self.head

         while current.data != data:  # Find the position to delete
               if current.next:
                     snake_case_     :			str       =       current.next
               else:  # We have reached the end an no value matches
                     raise ValueError("No data matching given value"   )

         if current == self.head:
               self.delete_head()

         elif current == self.tail:
               self.delete_tail()

         else:  # Before: 1 <--> 2(current) <--> 3
               snake_case_     :			Optional[Any]       =       current.next  # 1 --> 3
               snake_case_     :			Tuple       =       current.previous  # 1 <--> 3
         return data



   def 					UpperCAmelCase__       (				self   :   Dict   )							->     Tuple:




         '''simple docstring'''




         return len(self   ) == 0






def 					SCREAMING_SNAKE_CASE_			(		):
      snake_case_     :			Dict       =       DoublyLinkedList()
      assert linked_list.is_empty() is True
      assert str(lowerCAmelCase_     ) == ""

      try:
            linked_list.delete_head()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      try:
            linked_list.delete_tail()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      for i in range(1_0     ):
            assert len(lowerCAmelCase_     ) == i
            linked_list.insert_at_nth(lowerCAmelCase_ ,	i + 1     )
      assert str(lowerCAmelCase_     ) == "->".join(str(lowerCAmelCase_     ) for i in range(1 ,	1_1     )     )

      linked_list.insert_at_head(0     )
      linked_list.insert_at_tail(1_1     )
      assert str(lowerCAmelCase_     ) == "->".join(str(lowerCAmelCase_     ) for i in range(0 ,	1_2     )     )

      assert linked_list.delete_head() == 0
      assert linked_list.delete_at_nth(9     ) == 1_0
      assert linked_list.delete_tail() == 1_1
      assert len(lowerCAmelCase_     ) == 9
      assert str(lowerCAmelCase_     ) == "->".join(str(lowerCAmelCase_     ) for i in range(1 ,	1_0     )     )


if __name__ == "__main__":
     from doctest import testmod

     testmod()




import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
     import torch

     from transformers import GPTaLMHeadModel



@require_torch
@require_sentencepiece
@require_tokenizers
class 					snake_case__       (				unittest.TestCase							):



   @slow
   @unittest.skip("Model is not available."   )
   def 					UpperCAmelCase__       (				self   :   Dict   )							->     Optional[Any]:




         '''simple docstring'''




         snake_case_     :			str       =       "nvidia/megatron-gpt2-345m/"
         if "MYDIR" in os.environ:
               snake_case_     :			int       =       os.path.join(os.environ["MYDIR"]			,	A__   )
         snake_case_     :			str       =       GPTaLMHeadModel.from_pretrained(A__   )
         model.to(A__   )
         model.half()

         snake_case_     :			Optional[int]       =       torch.tensor(
             [[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]			,	device=A__			,	dtype=torch.long			,	)

         with torch.no_grad():
               snake_case_     :			Union[str, Any]       =       model(A__   ).logits

         snake_case_     :			List[str]       =       torch.Size((1, 9, 5_02_57)   )
         self.assertEqual(output.shape			,	A__   )

         snake_case_     :			Dict       =       torch.tensor(
             [
                 4.9414,
                 -0.2920,
                 -1.2148,
                 -4.0273,
                 -0.5161,
                 -5.2109,
                 -1.2412,
                 -1.8301,
                 -1.7734,
                 -4.7148,
                 -0.2317,
                 -1.0811,
                 -2.1777,
                 0.4141,
                 -3.7969,
                 -4.0586,
                 -2.5332,
                 -3.3809,
                 4.3867,
             ]			,	device=A__			,	dtype=torch.half			,	)

         for i in range(19   ):
               snake_case_  ,snake_case_     :			Dict       =       8 * i // 17, 27_92 * i  # along the diagonal
               snake_case_  ,snake_case_     :			Any       =       output[0, r, c], expected_diag[i]
               snake_case_     :			Dict       =       f"row={r} col={c} computed={computed} expected={expected}"
               self.assertAlmostEqual(A__			,	A__			,	delta=1E-4			,	msg=A__   )



