






from __future__ import annotations

from collections.abc import Iterable





class     __a						:







 def __init__(	self      :     List[str]							,     SCREAMING_SNAKE_CASE      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     Any		):


      '''simple docstring'''






      UpperCamelCase__       ,  UpperCamelCase__    :     Optional[Any]        =						float(SCREAMING_SNAKE_CASE		), float(SCREAMING_SNAKE_CASE		)







 def __eq__(	self      :     Any							,     SCREAMING_SNAKE_CASE      :     List[Any]		):


      '''simple docstring'''






      return self.x == other.x and self.y == other.y







 def __ne__(	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     int		):


      '''simple docstring'''






      return not self == other







 def __gt__(	self      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     Dict		):


      '''simple docstring'''






      if self.x > other.x:
           return True
      elif self.x == other.x:
           return self.y > other.y
      return False







 def __lt__(	self      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     str		):


      '''simple docstring'''






      return not self > other







 def __ge__(	self      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]		):


      '''simple docstring'''






      if self.x > other.x:
           return True
      elif self.x == other.x:
           return self.y >= other.y
      return False







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


      '''simple docstring'''






      if self.x < other.x:
           return True
      elif self.x == other.x:
           return self.y <= other.y
      return False







 def __repr__(	self      :     List[Any]		):


      '''simple docstring'''






      return F'({self.x}, {self.y})'







 def __hash__(	self      :     Dict		):


      '''simple docstring'''






      return hash(self.x		)







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase      ,					)				->			list[Point]:
     UpperCamelCase__    :     list[Point]        =						[]
     if list_of_tuples:
          for p in list_of_tuples:
               if isinstance(__lowerCAmelCase      ,					__lowerCAmelCase    ):
                    points.append(__lowerCAmelCase    )
               else:
                    try:
                         points.append(Point(p[0]      ,					p[1]    )    )
                    except (IndexError, TypeError):
                         print(
                             f'Ignoring deformed point {p}. All points'
                             " must have at least 2 coordinates."    )
     return points







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase    )				->			list[Point]:

     if not hasattr(__lowerCAmelCase      ,					"__iter__"    ):
          UpperCamelCase__    :     Dict        =						f'Expecting an iterable object but got an non-iterable type {points}'
          raise ValueError(__lowerCAmelCase    )

     if not points:
          UpperCamelCase__    :     Tuple        =						f'Expecting a list of points but got {points}'
          raise ValueError(__lowerCAmelCase    )

     return _construct_points(__lowerCAmelCase    )







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )				->			float:
     UpperCamelCase__    :     Optional[int]        =						(a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
     return det







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase    )				->			list[Point]:
     UpperCamelCase__    :     Union[str, Any]        =						sorted(_validate_input(__lowerCAmelCase    )    )
     UpperCamelCase__    :     int        =						len(__lowerCAmelCase    )
     UpperCamelCase__    :     List[Any]        =						set()

     for i in range(n - 1    ):
          for j in range(i + 1      ,					__lowerCAmelCase    ):
               UpperCamelCase__    :     int        =						False
               UpperCamelCase__    :     int        =						True
               for k in range(__lowerCAmelCase    ):
                    if k != i and k != j:
                         UpperCamelCase__    :     str        =						_det(points[i]      ,					points[j]      ,					points[k]    )

                         if det_k > 0:
                              UpperCamelCase__    :     Optional[Any]        =						True
                         elif det_k < 0:
                              UpperCamelCase__    :     List[Any]        =						True
                         else:
                              # point[i], point[j], point[k] all lie on a straight line
                              # if point[k] is to the left of point[i] or it's to the
                              # right of point[j], then point[i], point[j] cannot be
                              # part of the convex hull of A
                              if points[k] < points[i] or points[k] > points[j]:
                                   UpperCamelCase__    :     List[Any]        =						False
                                   break

                    if points_left_of_ij and points_right_of_ij:
                         UpperCamelCase__    :     Dict        =						False
                         break

               if ij_part_of_convex_hull:
                    convex_set.update([points[i], points[j]]    )

     return sorted(__lowerCAmelCase    )







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase    )				->			list[Point]:
     UpperCamelCase__    :     Union[str, Any]        =						sorted(_validate_input(__lowerCAmelCase    )    )
     UpperCamelCase__    :     Optional[int]        =						len(__lowerCAmelCase    )

     # divide all the points into an upper hull and a lower hull
     # the left most point and the right most point are definitely
     # members of the convex hull by definition.
     # use these two anchors to divide all the points into two hulls,
     # an upper hull and a lower hull.

     # all points to the left (above) the line joining the extreme points belong to the
     # upper hull
     # all points to the right (below) the line joining the extreme points below to the
     # lower hull
     # ignore all points on the line joining the extreme points since they cannot be
     # part of the convex hull

     UpperCamelCase__    :     List[str]        =						points[0]
     UpperCamelCase__    :     List[Any]        =						points[n - 1]

     UpperCamelCase__    :     List[Any]        =						{left_most_point, right_most_point}
     UpperCamelCase__    :     Dict        =						[]
     UpperCamelCase__    :     List[Any]        =						[]

     for i in range(1      ,					n - 1    ):
          UpperCamelCase__    :     str        =						_det(__lowerCAmelCase      ,					__lowerCAmelCase      ,					points[i]    )

          if det > 0:
               upper_hull.append(points[i]    )
          elif det < 0:
               lower_hull.append(points[i]    )

     _construct_hull(__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )
     _construct_hull(__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )

     return sorted(__lowerCAmelCase    )







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )				->			None:
     if points:
          UpperCamelCase__    :     str        =						None
          UpperCamelCase__    :     List[Any]        =						float("-inf"    )
          UpperCamelCase__    :     List[Any]        =						[]

          for p in points:
               UpperCamelCase__    :     List[str]        =						_det(__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )

               if det > 0:
                    candidate_points.append(__lowerCAmelCase    )

                    if det > extreme_point_distance:
                         UpperCamelCase__    :     Any        =						det
                         UpperCamelCase__    :     List[str]        =						p

          if extreme_point:
               _construct_hull(__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )
               convex_set.add(__lowerCAmelCase    )
               _construct_hull(__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase      ,					__lowerCAmelCase    )







def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase    )				->			list[Point]:
     UpperCamelCase__    :     Optional[int]        =						sorted(_validate_input(__lowerCAmelCase    )    )
     UpperCamelCase__    :     Any        =						len(__lowerCAmelCase    )

     UpperCamelCase__    :     Optional[Any]        =						points[:2]
     for i in range(2      ,					__lowerCAmelCase    ):
          UpperCamelCase__    :     Union[str, Any]        =						_det(convex_hull[1]      ,					convex_hull[0]      ,					points[i]    )
          if det > 0:
               convex_hull.insert(0      ,					points[i]    )
               break
          elif det < 0:
               convex_hull.append(points[i]    )
               break
          else:
               UpperCamelCase__    :     int        =						points[i]
     i += 1

     for j in range(__lowerCAmelCase      ,					__lowerCAmelCase    ):
          if (
              _det(convex_hull[0]      ,					convex_hull[-1]      ,					points[j]    ) > 0
              and _det(convex_hull[-1]      ,					convex_hull[0]      ,					points[1]    ) < 0
          ):
               # The point lies within the convex hull
               continue

          convex_hull.insert(0      ,					points[j]    )
          convex_hull.append(points[j]    )
          while _det(convex_hull[0]      ,					convex_hull[1]      ,					convex_hull[2]    ) >= 0:
               del convex_hull[1]
          while _det(convex_hull[-1]      ,					convex_hull[-2]      ,					convex_hull[-3]    ) <= 0:
               del convex_hull[-2]

    # `convex_hull` is contains the convex hull in circular order
     return sorted(convex_hull[1:] if len(__lowerCAmelCase    ) > 3 else convex_hull    )







def 	SCREAMING_SNAKE_CASE							(      )				->			Dict:
     UpperCamelCase__    :     Tuple        =						[
         (0, 3),
         (2, 2),
         (1, 1),
         (2, 1),
         (3, 0),
         (0, 0),
         (3, 3),
         (2, -1),
         (2, -4),
         (1, -3),
     ]
     # the convex set of points is
     # [(0, 0), (0, 3), (1, -3), (2, -4), (3, 0), (3, 3)]
     UpperCamelCase__    :     List[Any]        =						convex_hull_bf(__lowerCAmelCase    )

     UpperCamelCase__    :     Tuple        =						convex_hull_recursive(__lowerCAmelCase    )
     assert results_bf == results_recursive

     UpperCamelCase__    :     List[Any]        =						convex_hull_melkman(__lowerCAmelCase    )
     assert results_bf == results_melkman

     print(__lowerCAmelCase    )


if __name__ == "__main__":
 main()







import os
from dataclasses import replace

import jax
import wandb
from bigbird_flax import Args, DataCollator, FlaxBigBirdForNaturalQuestions, Trainer, build_tx, train_step, val_step
from datasets import load_dataset
from flax import jax_utils

from transformers import BigBirdTokenizerFast


if __name__ == "__main__":
 print('''#################### AVAILABLE DEVICES ####################''')
 print(jax.devices())
 print('''###########################################################''')

 # setup for wandb sweep
 lowerCamelCase			:							str       =Args()
 lowerCamelCase			:							str       =wandb.init(project='''bigbird-natural-questions''', config=args.__dict__)
 lowerCamelCase			:							Any       =dict(logger.config)
 del wandb_args["batch_size"]
 lowerCamelCase			:							str       =replace(args, **wandb_args)
 lowerCamelCase			:							List[str]       =args.base_dir + '''-''' + wandb.run.id
 lowerCamelCase			:							str       =replace(args, base_dir=base_dir)
 print(args)

 lowerCamelCase			:							List[Any]       =load_dataset('''json''', data_files=args.tr_data_path)['''train''']
 lowerCamelCase			:							str       =load_dataset('''json''', data_files=args.val_data_path)['''train''']

 # drop extra batch for now
 lowerCamelCase			:							List[Any]       =range(len(tr_dataset) - len(tr_dataset) % args.batch_size)
 lowerCamelCase			:							Union[str, Any]       =tr_dataset.shuffle().select(indices)
 lowerCamelCase			:							List[str]       =range(len(val_dataset) - len(val_dataset) % args.batch_size)
 lowerCamelCase			:							Dict       =val_dataset.shuffle().select(indices)

 if os.environ.get('''TRAIN_ON_SMALL''', '''false''') == "true":
  lowerCamelCase			:							Optional[int]       =tr_dataset.shuffle().select(range(80000))
  lowerCamelCase			:							List[Any]       =val_dataset.shuffle().select(range(8000))

 print(tr_dataset)
 print(val_dataset)

 lowerCamelCase			:							int       =FlaxBigBirdForNaturalQuestions.from_pretrained(
     args.model_id, block_size=args.block_size, num_random_blocks=args.num_random_blocks
 )
 lowerCamelCase			:							Union[str, Any]       =BigBirdTokenizerFast.from_pretrained(args.model_id)
 lowerCamelCase			:							Dict       =DataCollator(pad_id=tokenizer.pad_token_id, max_length=4096)

 lowerCamelCase			:							List[str]       ={
     '''lr''': args.lr,
     '''init_lr''': args.init_lr,
     '''warmup_steps''': args.warmup_steps,
     '''num_train_steps''': args.max_epochs * (len(tr_dataset) // args.batch_size),
     '''weight_decay''': args.weight_decay,
 }
 lowerCamelCase       ,    lowerCamelCase			:							Tuple       =build_tx(**tx_args)

 lowerCamelCase			:							Optional[Any]       =Trainer(
     args=args,
     data_collator=data_collator,
     model_save_fn=model.save_pretrained,
     train_step_fn=train_step,
     val_step_fn=val_step,
     logger=logger,
     scheduler_fn=lr,
 )

 lowerCamelCase			:							Tuple       =None
 lowerCamelCase			:							str       =trainer.create_state(model, tx, num_train_steps=tx_args['''num_train_steps'''], ckpt_dir=ckpt_dir)
 try:
  trainer.train(state, tr_dataset, val_dataset)
 except KeyboardInterrupt:
  print('''Oooops; TRAINING STOPPED UNFORTUNATELY''')

 print('''SAVING WEIGHTS IN `final-weights`''')
 lowerCamelCase			:							str       =jax_utils.unreplicate(state.params)
 model.save_pretrained(os.path.join(args.base_dir, '''final-weights'''), params=params)