
"""simple docstring"""





import torch

from accelerate import PartialState
from accelerate.utils.operations import broadcast, gather, gather_object, pad_across_processes, reduce
def 				A_  (__a					):

					'''simple docstring'''





					return (torch.arange(state.num_processes					) + 1.0 + (state.num_processes * state.process_index)).to(state.device					)
def 				A_  (__a					):

					'''simple docstring'''





					A_								=    create_tensor(__a					)
					A_								=    gather(__a					)
					assert gathered_tensor.tolist() == list(range(1					, state.num_processes**2 + 1					)					)
def 				A_  (__a					):

					'''simple docstring'''





					A_								=    [state.process_index]
					A_								=    gather_object(__a					)
					assert len(__a					) == state.num_processes, f'{gathered_obj}, {len(__a					)} != {state.num_processes}'
					assert gathered_obj == list(range(state.num_processes					)					), f'{gathered_obj} != {list(range(state.num_processes					)					)}'
def 				A_  (__a					):

					'''simple docstring'''





					A_								=    create_tensor(__a					)
					A_								=    broadcast(__a					)
					assert broadcasted_tensor.shape == torch.Size([state.num_processes]					)
					assert broadcasted_tensor.tolist() == list(range(1					, state.num_processes + 1					)					)
def 				A_  (__a					):

					'''simple docstring'''





					if state.is_main_process:
										A_								=    torch.arange(state.num_processes + 1					).to(state.device					)
					else:
										A_								=    torch.arange(state.num_processes					).to(state.device					)
					A_								=    pad_across_processes(__a					)
					assert padded_tensor.shape == torch.Size([state.num_processes + 1]					)
					if not state.is_main_process:
										assert padded_tensor.tolist() == list(range(0					, state.num_processes					)					) + [0]
def 				A_  (__a					):

					'''simple docstring'''





					if state.num_processes != 2:
										return
					A_								=    create_tensor(__a					)
					A_								=    reduce(__a					, "sum"					)
					A_								=    torch.tensor([4.0, 6]					).to(state.device					)
					assert torch.allclose(__a					, __a					), f'{reduced_tensor} != {truth_tensor}'
def 				A_  (__a					):

					'''simple docstring'''





					if state.num_processes != 2:
										return
					A_								=    create_tensor(__a					)
					A_								=    reduce(__a					, "mean"					)
					A_								=    torch.tensor([2.0, 3]					).to(state.device					)
					assert torch.allclose(__a					, __a					), f'{reduced_tensor} != {truth_tensor}'
def 				A_  (__a					):

					'''simple docstring'''





					main()
def 				A_  ():

					'''simple docstring'''





					A_								=    PartialState()
					state.print(f'State: {state}'					)
					state.print("testing gather"					)
					test_gather(__a					)
					state.print("testing gather_object"					)
					test_gather_object(__a					)
					state.print("testing broadcast"					)
					test_broadcast(__a					)
					state.print("testing pad_across_processes"					)
					test_pad_across_processes(__a					)
					state.print("testing reduce_sum"					)
					test_reduce_sum(__a					)
					state.print("testing reduce_mean"					)
					test_reduce_mean(__a					)


if __name__ == "__main__":
		main()











'''simple docstring'''






from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
      from ... import FeatureExtractionMixin, TensorType

A__							:  Tuple    =logging.get_logger(__name__)

A__							:  Any    ={
    '''openai/imagegpt-small''': '''''',
    '''openai/imagegpt-medium''': '''''',
    '''openai/imagegpt-large''': '''''',
}




class 					UpperCAmelCase	(     snake_case_  ):
      _lowercase:     Tuple			=  '''imagegpt'''
      _lowercase:     Optional[int]			=  ['''past_key_values''']
      _lowercase:     str			=  {
          '''hidden_size''': '''n_embd''',
          '''max_position_embeddings''': '''n_positions''',
          '''num_attention_heads''': '''n_head''',
          '''num_hidden_layers''': '''n_layer''',
      }




      def __init__(     self     :					Optional[int]     ,     __snake_case     :					Optional[Any]=5_12 + 1     ,     __snake_case     :					Union[str, Any]=32 * 32     ,     __snake_case     :					List[Any]=5_12     ,     __snake_case     :					Any=24     ,     __snake_case     :					Optional[Any]=8     ,     __snake_case     :					List[Any]=None     ,     __snake_case     :					str="quick_gelu"     ,     __snake_case     :					List[Any]=0.1     ,     __snake_case     :					str=0.1     ,     __snake_case     :					Optional[int]=0.1     ,     __snake_case     :					Tuple=1E-5     ,     __snake_case     :					Optional[int]=0.02     ,     __snake_case     :					str=True     ,     __snake_case     :					Dict=True     ,     __snake_case     :					Union[str, Any]=False     ,     __snake_case     :					Dict=False     ,     __snake_case     :					Union[str, Any]=False     ,     **__snake_case     :					Union[str, Any]     ,     )							-> List[Any]:
            _lowerCAmelCase					=				vocab_size
            _lowerCAmelCase					=				n_positions
            _lowerCAmelCase					=				n_embd
            _lowerCAmelCase					=				n_layer
            _lowerCAmelCase					=				n_head
            _lowerCAmelCase					=				n_inner
            _lowerCAmelCase					=				activation_function
            _lowerCAmelCase					=				resid_pdrop
            _lowerCAmelCase					=				embd_pdrop
            _lowerCAmelCase					=				attn_pdrop
            _lowerCAmelCase					=				layer_norm_epsilon
            _lowerCAmelCase					=				initializer_range
            _lowerCAmelCase					=				scale_attn_weights
            _lowerCAmelCase					=				use_cache
            _lowerCAmelCase					=				scale_attn_by_inverse_layer_idx
            _lowerCAmelCase					=				reorder_and_upcast_attn
            _lowerCAmelCase					=				tie_word_embeddings

            super().__init__(tie_word_embeddings=__snake_case     ,     **__snake_case    )




class 					UpperCAmelCase	(     snake_case_  ):




      @property
      def 							lowercase__       (     self     :					Optional[Any]    )							-> Mapping[str, Mapping[int, str]]:
            return OrderedDict(
                [
                    ("""input_ids""", {0: """batch""", 1: """sequence"""}),
                ]    )




      def 							lowercase__       (     self     :					Union[str, Any]     ,     __snake_case     :					"FeatureExtractionMixin"     ,     __snake_case     :					int = 1     ,     __snake_case     :					int = -1     ,     __snake_case     :					bool = False     ,     __snake_case     :					Optional["TensorType"] = None     ,     __snake_case     :					int = 3     ,     __snake_case     :					int = 32     ,     __snake_case     :					int = 32     ,     )							-> Mapping[str, Any]:
            _lowerCAmelCase					=				self._generate_dummy_images(__snake_case     ,     __snake_case     ,     __snake_case     ,     __snake_case    )
            _lowerCAmelCase					=				dict(preprocessor(images=__snake_case     ,     return_tensors=__snake_case    )    )

            return inputs






