




import unittest
from dataclasses import dataclass

import pytest

from accelerate.commands.config.config_args import SageMakerConfig
from accelerate.utils import ComputeEnvironment
from accelerate.utils.launch import _convert_nargs_to_dict


@dataclass
class     UpperCamelCase_   (			__SCREAMING_SNAKE_CASE					):

    '''simple docstring'''






    UpperCAmelCase__							  =				ComputeEnvironment.AMAZON_SAGEMAKER
    UpperCAmelCase__							  =				True
    UpperCAmelCase__							  =				'ml.p3.2xlarge'
    UpperCAmelCase__							  =				'accelerate_sagemaker_execution_role'
    UpperCAmelCase__							  =				'hf-sm'
    UpperCAmelCase__							  =				'us-east-1'
    UpperCAmelCase__							  =				1
    UpperCAmelCase__							  =				'accelerate-sagemaker-1'
    UpperCAmelCase__							  =				'1.6'
    UpperCAmelCase__							  =				'4.4'
    UpperCAmelCase__							  =				'train.py'
    UpperCAmelCase__							  =				[
        '--model_name_or_path',
        'bert',
        '--do_train',
        'False',
        '--epochs',
        '3',
        '--learning_rate',
        '5e-5',
        '--max_steps',
        '50.5',
    ]
    UpperCAmelCase__							  =				[
        '--model_name_or_path',
        'bert',
        '--do_train',
        '--do_test',
        'False',
        '--do_predict',
        '--epochs',
        '3',
        '--learning_rate',
        '5e-5',
        '--max_steps',
        '50.5',
    ]


class     UpperCamelCase_   (			unittest.TestCase					):

    '''simple docstring'''






    def 	SCREAMING_SNAKE_CASE							(      self				:     str)						->List[Any]:





           '''simple docstring'''

           A__							=   _convert_nargs_to_dict(MockLaunchConfig.success_training_script_args)
           assert isinstance(converted_args['''model_name_or_path'''] ,			_a)
           assert isinstance(converted_args['''do_train'''] ,			_a)
           assert isinstance(converted_args['''epochs'''] ,			_a)
           assert isinstance(converted_args['''learning_rate'''] ,			_a)
           assert isinstance(converted_args['''max_steps'''] ,			_a)

           with pytest.raises(_a):
                  _convert_nargs_to_dict(MockLaunchConfig.fail_training_script_args)











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

    '''simple docstring'''






    def 	SCREAMING_SNAKE_CASE							(      self				:     Dict)						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 4], [1, 2, 3, 4]]
           A__							=   DisjunctiveConstraint(UpperCAmelCase__)
           self.assertTrue(isinstance(dc.token_ids ,			UpperCAmelCase__))

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

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->str:





           '''simple docstring'''

           A__							=   [[1, 2], [1, 2, 3, 4]]

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     Any)						->str:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1, 2])

           A__			,							A__			,							A__							=   dc.update(3)
           A__							=   stepped is True and completed is True and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(dc.completed)  # Completed!
           self.assertTrue(dc.current_seq == [1, 2, 3])





    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

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

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

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

           dc.reset()

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

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

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


