





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  A__       (	unittest.TestCase      ):





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : str	     =       [[1, 2, 4], [1, 2, 3, 4]]
       UpperCamelCase     : List[str]	     =       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 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Any	     =       [[1, 2], [1, 2, 3, 4]]

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





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[int]	     =       [[1, 2, 3], [1, 2, 4]]

       UpperCamelCase     : Any	     =       DisjunctiveConstraint(A_       )

       UpperCamelCase     ,   UpperCamelCase     ,   UpperCamelCase     : List[Any]	     =       dc.update(1       )
       UpperCamelCase     : Tuple	     =       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     : Union[str, Any]	     =       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[Any]	     =       dc.update(3       )
       UpperCamelCase     : Optional[Any]	     =       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 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Tuple	     =       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

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

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

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

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

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

       dc.reset()

       UpperCamelCase     ,   UpperCamelCase     ,   UpperCamelCase     : Tuple	     =       dc.update(1       )
       self.assertTrue(not dc.completed       )
       self.assertTrue(dc.remaining() == 3       )
       self.assertTrue(dc.current_seq == [1]       )

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

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







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCamelCase	:					Tuple			  =					logging.get_logger(__name__)



class  A__       (	__snake_case      ):
      _UpperCAmelCase     :List[Any]						   =       'timm_backbone'





      def __init__(			self	,							A_=None	,							A_=3	,							A_=True	,							A_=True	,							A_=None	,							**A_	,							):
       '''simple docstring'''




       super().__init__(**A_       )
       UpperCamelCase     : Tuple	     =       backbone
       UpperCamelCase     : Dict	     =       num_channels
       UpperCamelCase     : Tuple	     =       features_only
       UpperCamelCase     : Optional[int]	     =       use_pretrained_backbone
       UpperCamelCase     : Dict	     =       True
       UpperCamelCase     : List[str]	     =       out_indices if out_indices is not None else (-1,)
