


import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
 import torch

 from transformers.generation import DisjunctiveConstraint


@require_torch
class 		_SCREAMING_SNAKE_CASE     (						unittest.TestCase     ):


     def        __snake_case(  self    ):
       # For consistency across different places the DisjunctiveConstraint is called,
       # dc.token_ids is a list of integers. It is also initialized only by integers.

       _UpperCAmelCase		:							Optional[int]							=     [[1, 2, 4], [1, 2, 3, 4]]
       _UpperCAmelCase		:							Tuple							=     DisjunctiveConstraint(A_    )
       self.assertTrue(isinstance(dc.token_ids							,					A_    )    )

       with self.assertRaises(A_    ):
         DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]    )    )

       with self.assertRaises(A_    ):
         DisjunctiveConstraint([torch.LongTensor([1, 2, 4]    ), torch.LongTensor([1, 2, 3, 4, 5]    )]    )


     def        __snake_case(  self    ):
       # We can't have constraints that are complete subsets of another. This leads to a preverse
       # interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
       # It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
       # fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
       # will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
       _UpperCAmelCase		:							List[Any]							=     [[1, 2], [1, 2, 3, 4]]

       with self.assertRaises(A_    ):
         DisjunctiveConstraint(A_    )  # fails here


     def        __snake_case(  self    ):
       _UpperCAmelCase		:							List[Any]							=     [[1, 2, 3], [1, 2, 4]]

       _UpperCAmelCase		:							Optional[Any]							=     DisjunctiveConstraint(A_    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Any							=     dc.update(1    )
       _UpperCAmelCase		:							Dict							=     stepped is True and completed is False and reset is False
       self.assertTrue(A_    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Tuple							=     dc.update(2    )
       _UpperCAmelCase		:							Union[str, Any]							=     stepped is True and completed is False and reset is False
       self.assertTrue(A_    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							List[str]							=     dc.update(3    )
       _UpperCAmelCase		:							List[str]							=     stepped is True and completed is True and reset is False
       self.assertTrue(A_    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.current_seq == [1, 2, 3]    )




     def        __snake_case(  self    ):
       _UpperCAmelCase		:							Optional[Any]							=     [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

       _UpperCAmelCase		:							Union[str, Any]							=     DisjunctiveConstraint(A_    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Any							=     dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Dict							=     dc.update(2    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							int							=     dc.update(4    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.current_seq == [1, 2, 4]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Union[str, Any]							=     dc.update(5    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.current_seq == [1, 2, 4, 5]    )

       dc.reset()

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Optional[int]							=     dc.update(1    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.remaining() == 3    )
       self.assertTrue(dc.current_seq == [1]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							int							=     dc.update(2    )
       self.assertTrue(not dc.completed    )
       self.assertTrue(dc.remaining() == 2    )
       self.assertTrue(dc.current_seq == [1, 2]    )

       _UpperCAmelCase,_UpperCAmelCase,_UpperCAmelCase		:							Dict							=     dc.update(5    )
       self.assertTrue(dc.completed    )  # Completed!
       self.assertTrue(dc.remaining() == 0    )
       self.assertTrue(dc.current_seq == [1, 2, 5]    )









from __future__ import annotations

from typing import Dict

from ...configuration_utils import PretrainedConfig


SCREAMING_SNAKE_CASE__					:     List[Any]       =     {
    'susnato/ernie-m-base_pytorch': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/config.json',
    'susnato/ernie-m-large_pytorch': 'https://huggingface.co/susnato/ernie-m-large_pytorch/blob/main/config.json',
}


class 		_SCREAMING_SNAKE_CASE     (						A     ):
     __SCREAMING_SNAKE_CASE     					=    '''ernie_m'''
     __SCREAMING_SNAKE_CASE     					=    {"dropout": "classifier_dropout", "num_classes": "num_labels"}


     def __init__(  self							,					A_ = 25_00_02							,					A_ = 7_68							,					A_ = 12							,					A_ = 12							,					A_ = 30_72							,					A_ = "gelu"							,					A_ = 0.1							,					A_ = 0.1							,					A_ = 5_14							,					A_ = 0.0_2							,					A_ = 1							,					A_ = 1e-05							,					A_=None							,					A_=False							,					A_=0.0							,					**A_							,					):
       super().__init__(pad_token_id=A_							,					**A_    )
       _UpperCAmelCase		:							Tuple							=     vocab_size
       _UpperCAmelCase		:							List[str]							=     hidden_size
       _UpperCAmelCase		:							Optional[int]							=     num_hidden_layers
       _UpperCAmelCase		:							Tuple							=     num_attention_heads
       _UpperCAmelCase		:							Dict							=     intermediate_size
       _UpperCAmelCase		:							List[Any]							=     hidden_act
       _UpperCAmelCase		:							Any							=     hidden_dropout_prob
       _UpperCAmelCase		:							Any							=     attention_probs_dropout_prob
       _UpperCAmelCase		:							Tuple							=     max_position_embeddings
       _UpperCAmelCase		:							Dict							=     initializer_range
       _UpperCAmelCase		:							Optional[Any]							=     layer_norm_eps
       _UpperCAmelCase		:							str							=     classifier_dropout
       _UpperCAmelCase		:							Any							=     is_decoder
       _UpperCAmelCase		:							Union[str, Any]							=     act_dropout





