def validate_flags_or_throw(self):
    """Validate the input FLAGS or throw an exception."""
    if FLAGS.model_config_file is None:
      raise ValueError("model_config_file is required.")
    if self.output_dir is None:
      raise ValueError("output_dir is required.")

    if not self.do_train and not self.do_predict:
      raise ValueError("At least one of `{do_train,do_predict}` must be True.")

    if self.do_train:
      if not self.train_records_file:
        raise ValueError("If `do_train` is True, then `train_records_file` "
                         "must be specified.")
      if not self.record_count_file:
        raise ValueError("If `do_train` is True, then `record_count_file` "
                         "must be specified.")
      if not self.train_batch_size:
        raise ValueError("If `do_train` is True, then `train_batch_size` "
                         "must be specified.")
      if not self.learning_rate:
        raise ValueError("If `do_train` is True, then `learning_rate` "
                         "must be specified.")
      if not self.num_train_epochs:
        raise ValueError("If `do_train` is True, then `num_train_epochs` "
                         "must be specified.")
      if not self.warmup_proportion:
        raise ValueError("If `do_train` is True, then `warmup_proportion` "
                         "must be specified.")
    else:
      if self.train_batch_size is None:
        # TPUEstimator errors if train_batch_size is not a positive integer,
        # even if we're not actually training.
        self.train_batch_size = 1

    if self.do_predict:
      if not self.predict_file:
        raise ValueError("If `do_predict` is True, "
                         "then `predict_file` must be specified.")
      if not self.max_answer_length:
        raise ValueError("If `do_predict` is True, "
                         "then `max_answer_length` must be specified.")
      if not self.candidate_beam:
        raise ValueError("If `do_predict` is True, "
                         "then `candidate_beam` must be specified.")
      if not self.predict_batch_size:
        raise ValueError("If `do_predict` is True, "
                         "then `predict_batch_size` must be specified.")
      if not self.output_prediction_file:
        raise ValueError("If `do_predict` is True, "
                         "then `output_prediction_file` must be specified.")

      if not self.precomputed_predict_file:
        if not self.max_passages:
          raise ValueError("If `precomputed_predict_file` is not specified, "
                           "then `max_passages` must be specified.")
        if not self.max_position:
          raise ValueError("If `precomputed_predict_file` is not specified, "
                           "then `max_position` must be specified.")
        if not self.doc_stride:
          raise ValueError("If `precomputed_predict_file` is not specified, "
                           "then `doc_stride` must be specified.")
        if not self.max_question_length:
          raise ValueError("If `precomputed_predict_file` is not specified, "
                           "then `max_question_length` must be specified.")
        if self.max_seq_length <= self.max_question_length + 3:
          raise ValueError(
              f"The max_seq_length ({self.max_seq_length}) must be greater "
              f"than max_question_length ({self.max_question_length}) + 3")
        if not self.include_unknowns:
          raise ValueError("If `precomputed_predict_file` is not specified, "
                           "then `include_unknowns` must be specified.")

    if self.max_seq_length > self.model_config.max_positions:
      raise ValueError(
          f"Cannot use sequence length {self.max_seq_length} "
          "because the CANINE model was only trained up to sequence length "
          f"{self.model_config.max_positions}")
Validate the input FLAGS or throw an exception.
language/canine/tydiqa/run_tydi.py