class SCREAMING_SNAKE_CASE_		:







   def __init__(    self	:	Optional[int]      ,      lowerCamelCase_	:	Optional[Any]							):





    """simple docstring"""


    UpperCamelCase      =			data
    UpperCamelCase      =			None
    UpperCamelCase      =			None







   def __str__(    self	:	Optional[Any]							):





    """simple docstring"""


    return f"""{self.data}"""





class SCREAMING_SNAKE_CASE_		:







   def __init__(    self	:	str							):





    """simple docstring"""


    UpperCamelCase      =			None
    UpperCamelCase      =			None







   def __iter__(    self	:	int							):





    """simple docstring"""


    UpperCamelCase      =			self.head
    while node:
     yield node.data
     UpperCamelCase      =			node.next







   def __str__(    self	:	List[str]							):





    """simple docstring"""


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







   def __len__(    self	:	Tuple							):





    """simple docstring"""


    return sum(1 for _ in self							)







   def 	lowerCamelCase_  (    self	:	Optional[int]      ,      lowerCamelCase_	:	Union[str, Any]							):





    """simple docstring"""


    self.insert_at_nth(0      ,      __SCREAMING_SNAKE_CASE							)







   def 	lowerCamelCase_  (    self	:	List[Any]      ,      lowerCamelCase_	:	Optional[int]							):





    """simple docstring"""


    self.insert_at_nth(len(self							)      ,      __SCREAMING_SNAKE_CASE							)







   def 	lowerCamelCase_  (    self	:	Dict      ,      lowerCamelCase_	:	Dict      ,      lowerCamelCase_	:	Optional[Any]							):





    """simple docstring"""


    UpperCamelCase      =			len(self							)

    if not 0 <= index <= length:
     raise IndexError("""list index out of range"""							)
    UpperCamelCase      =			Node(__SCREAMING_SNAKE_CASE							)
    if self.head is None:
     UpperCamelCase      =			UpperCamelCase      =			new_node
    elif index == 0:
     UpperCamelCase      =			new_node
     UpperCamelCase      =			self.head
     UpperCamelCase      =			new_node
    elif index == length:
     UpperCamelCase      =			new_node
     UpperCamelCase      =			self.tail
     UpperCamelCase      =			new_node
    else:
     UpperCamelCase      =			self.head
     for _ in range(0      ,      __SCREAMING_SNAKE_CASE							):
      UpperCamelCase      =			temp.next
     UpperCamelCase      =			new_node
     UpperCamelCase      =			temp.previous
     UpperCamelCase      =			temp
     UpperCamelCase      =			new_node







   def 	lowerCamelCase_  (    self	:	Tuple							):





    """simple docstring"""


    return self.delete_at_nth(0							)







   def 	lowerCamelCase_  (    self	:	str							):





    """simple docstring"""


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







   def 	lowerCamelCase_  (    self	:	Dict      ,      lowerCamelCase_	:	Dict							):





    """simple docstring"""


    UpperCamelCase      =			len(self							)

    if not 0 <= index <= length - 1:
     raise IndexError("""list index out of range"""							)
    UpperCamelCase      =			self.head  # default first node
    if length == 1:
     UpperCamelCase      =			UpperCamelCase      =			None
    elif index == 0:
     UpperCamelCase      =			self.head.next
     UpperCamelCase      =			None
    elif index == length - 1:
     UpperCamelCase      =			self.tail
     UpperCamelCase      =			self.tail.previous
     UpperCamelCase      =			None
    else:
     UpperCamelCase      =			self.head
     for _ in range(0      ,      __SCREAMING_SNAKE_CASE							):
      UpperCamelCase      =			temp.next
     UpperCamelCase      =			temp
     UpperCamelCase      =			temp.previous
     UpperCamelCase      =			temp.next
    return delete_node.data







   def 	lowerCamelCase_  (    self	:	str      ,      lowerCamelCase_	:	Union[str, Any]							):





    """simple docstring"""


    UpperCamelCase      =			self.head

    while current.data != data:  # Find the position to delete
     if current.next:
      UpperCamelCase      =			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
     UpperCamelCase      =			current.next  # 1 --> 3
     UpperCamelCase      =			current.previous  # 1 <--> 3
    return data







   def 	lowerCamelCase_  (    self	:	str							):





    """simple docstring"""


    return len(self							) == 0





def  lowercase(  )		->  None:







 '''simple docstring'''
 UpperCamelCase      =			DoublyLinkedList()
 assert linked_list.is_empty() is True
 assert str(UpperCamelCase_					) == ""

 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(10					):
  assert len(UpperCamelCase_					) == i
  linked_list.insert_at_nth(UpperCamelCase_       ,				i + 1					)
 assert str(UpperCamelCase_					) == "->".join(str(UpperCamelCase_					) for i in range(1       ,				11					)					)

 linked_list.insert_at_head(0					)
 linked_list.insert_at_tail(11					)
 assert str(UpperCamelCase_					) == "->".join(str(UpperCamelCase_					) for i in range(0       ,				12					)					)

 assert linked_list.delete_head() == 0
 assert linked_list.delete_at_nth(9					) == 10
 assert linked_list.delete_tail() == 11
 assert len(UpperCamelCase_					) == 9
 assert str(UpperCamelCase_					) == "->".join(str(UpperCamelCase_					) for i in range(1       ,				10					)					)


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

     testmod()

import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
     import transformer_engine.pytorch as te





def  lowercase(  UpperCamelCase_       ,				UpperCamelCase_=True       ,				UpperCamelCase_=True       ,				UpperCamelCase_=True					)		->  int:







 '''simple docstring'''
 if not is_fpa_available():
  raise ImportError("""Using `convert_model` requires transformer_engine to be installed."""					)
 for name, module in model.named_children():
  if isinstance(UpperCamelCase_       ,				nn.Linear					) and to_transformer_engine and _convert_linear:
   # Return early if the linear layer weights are not multiples of 16
   if any(p % 16 != 0 for p in module.weight.shape					):
    return
   UpperCamelCase      =			module.bias is not None
   UpperCamelCase      =			te.Linear(
       module.in_features       ,				module.out_features       ,				bias=UpperCamelCase_       ,				params_dtype=module.weight.dtype					)
   UpperCamelCase      =			module.weight.data.clone()
   if has_bias:
    UpperCamelCase      =			module.bias.data.clone()

   setattr(UpperCamelCase_       ,				UpperCamelCase_       ,				UpperCamelCase_					)
  elif isinstance(UpperCamelCase_       ,				nn.LayerNorm					) and to_transformer_engine and _convert_ln:
   UpperCamelCase      =			te.LayerNorm(module.normalized_shape[0]       ,				eps=module.eps       ,				params_dtype=module.weight.dtype					)
   UpperCamelCase      =			module.weight.data.clone()
   UpperCamelCase      =			module.bias.data.clone()

   setattr(UpperCamelCase_       ,				UpperCamelCase_       ,				UpperCamelCase_					)
  elif isinstance(UpperCamelCase_       ,				te.Linear					) and not to_transformer_engine and _convert_linear:
   UpperCamelCase      =			module.bias is not None
   UpperCamelCase      =			nn.Linear(
       module.in_features       ,				module.out_features       ,				bias=UpperCamelCase_       ,				params_dtype=module.weight.dtype					)
   UpperCamelCase      =			module.weight.data.clone()
   if has_bias:
    UpperCamelCase      =			module.bias.data.clone()

   setattr(UpperCamelCase_       ,				UpperCamelCase_       ,				UpperCamelCase_					)
  elif isinstance(UpperCamelCase_       ,				te.LayerNorm					) and not to_transformer_engine and _convert_ln:
   UpperCamelCase      =			nn.LayerNorm(module.normalized_shape[0]       ,				eps=module.eps       ,				params_dtype=module.weight.dtype					)
   UpperCamelCase      =			module.weight.data.clone()
   UpperCamelCase      =			module.bias.data.clone()

   setattr(UpperCamelCase_       ,				UpperCamelCase_       ,				UpperCamelCase_					)
  else:
   convert_model(
       UpperCamelCase_       ,				to_transformer_engine=UpperCamelCase_       ,				_convert_linear=_convert_linear       ,				_convert_ln=_convert_ln       ,				)





def  lowercase(  UpperCamelCase_					)		->  Any:







 '''simple docstring'''
 if not is_fpa_available():
  raise ImportError("""Using `has_transformer_engine_layers` requires transformer_engine to be installed."""					)
 for m in model.modules():
  if isinstance(UpperCamelCase_       ,				(te.LayerNorm, te.Linear)					):
   return True
 return False
