





"""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_	: Dict      				=logging.get_logger(__name__)

A_	: List[Any]      				={
    """openai/imagegpt-small""": """""",
    """openai/imagegpt-medium""": """""",
    """openai/imagegpt-large""": """""",
}







class       __a  (    snake_case__						):
     SCREAMING_SNAKE_CASE__					: Tuple									=     "imagegpt"
     SCREAMING_SNAKE_CASE__					: Tuple									=     ["past_key_values"]
     SCREAMING_SNAKE_CASE__					: Optional[Any]									=     {
         "hidden_size": "n_embd",
         "max_position_embeddings": "n_positions",
         "num_attention_heads": "n_head",
         "num_hidden_layers": "n_layer",
     }



     def __init__(			self   ,	a__=5_12 + 1   ,	a__=32 * 32   ,	a__=5_12   ,	a__=24   ,	a__=8   ,	a__=None   ,	a__="quick_gelu"   ,	a__=0.1   ,	a__=0.1   ,	a__=0.1   ,	a__=1e-5   ,	a__=0.02   ,	a__=True   ,	a__=True   ,	a__=False   ,	a__=False   ,	a__=False   ,	**a__   ,	):
            _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=_UpperCamelCase   ,	**_UpperCamelCase  )







class       __a  (    snake_case__						):



     @property
     def 		snake_case_     (			self  ):
            return OrderedDict(
                [
                    ('input_ids', {0: 'batch', 1: 'sequence'}),
                ]  )



     def 		snake_case_     (			self   ,	a__   ,	a__ = 1   ,	a__ = -1   ,	a__ = False   ,	a__ = None   ,	a__ = 3   ,	a__ = 32   ,	a__ = 32   ,	):
            _lowerCamelCase             =   self._generate_dummy_images(_UpperCamelCase   ,	_UpperCamelCase   ,	_UpperCamelCase   ,	_UpperCamelCase  )
            _lowerCamelCase             =   dict(preprocessor(images=_UpperCamelCase   ,	return_tensors=_UpperCamelCase  )  )

            return inputs









# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path

import torch

from ...utils import is_npu_available, is_xpu_available
from .config_args import ClusterConfig, default_json_config_file
from .config_utils import SubcommandHelpFormatter


UpperCamelCase__		 =     '''Create a default config file for Accelerate with only a few flags set.'''







def 						lowerCamelCase__      ( __A    :List[Any]="no"	,__A    :str = default_json_config_file	,__A    :bool = False		):


       """simple docstring"""




       __snake_case       	=							Path(__A		)
       path.parent.mkdir(parents=__A	,exist_ok=__A		)
       if path.exists():
              print(
                  F'Configuration already exists at {save_location}, will not override. Run `accelerate config` manually or pass a different `save_location`.'		)
              return False
       __snake_case       	=							mixed_precision.lower()
       if mixed_precision not in ["no", "fp16", "bf16", "fp8"]:
              raise ValueError(
                  F'`mixed_precision` should be one of \'no\', \'fp16\', \'bf16\', or \'fp8\'. Received {mixed_precision}'		)
       __snake_case       	=							{
           """compute_environment""": """LOCAL_MACHINE""",
           """mixed_precision""": mixed_precision,
       }
       if torch.cuda.is_available():
              __snake_case       	=							torch.cuda.device_count()
              __snake_case       	=							num_gpus
              __snake_case       	=							False
              if num_gpus > 1:
                     __snake_case       	=							"""MULTI_GPU"""
              else:
                     __snake_case       	=							"""NO"""
       elif is_xpu_available() and use_xpu:
              __snake_case       	=							torch.xpu.device_count()
              __snake_case       	=							num_xpus
              __snake_case       	=							False
              if num_xpus > 1:
                     __snake_case       	=							"""MULTI_XPU"""
              else:
                     __snake_case       	=							"""NO"""
       elif is_npu_available():
              __snake_case       	=							torch.npu.device_count()
              __snake_case       	=							num_npus
              __snake_case       	=							False
              if num_npus > 1:
                     __snake_case       	=							"""MULTI_NPU"""
              else:
                     __snake_case       	=							"""NO"""
       else:
              __snake_case       	=							0
              __snake_case       	=							True
              __snake_case       	=							1
              __snake_case       	=							"""NO"""
       __snake_case       	=							ClusterConfig(**__A		)
       config.to_json_file(__A		)
       return path







def 						lowerCamelCase__      ( __A    :Dict	,__A    :List[Any]		):


       """simple docstring"""




       __snake_case       	=							parser.add_parser("""default"""	,parents=__A	,help=__A	,formatter_class=__A		)
       parser.add_argument(
           """--config_file"""	,default=__A	,help=(
               """The path to use to store the config file. Will default to a file named default_config.yaml in the cache """
               """location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have """
               """such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed """
               """with 'huggingface'."""
           )	,dest="""save_location"""	,)

       parser.add_argument(
           """--mixed_precision"""	,choices=["""no""", """fp16""", """bf16"""]	,type=__A	,help="""Whether or not to use mixed precision training. """
           """Choose between FP16 and BF16 (bfloat16) training. """
           """BF16 training is only supported on Nvidia Ampere GPUs and PyTorch 1.10 or later."""	,default="""no"""	,)
       parser.set_defaults(func=__A		)
       return parser







def 						lowerCamelCase__      ( __A    :Optional[Any]		):


       """simple docstring"""




       __snake_case       	=							write_basic_config(args.mixed_precision	,args.save_location		)
       if config_file:
              print(F'accelerate configuration saved at {config_file}'		)

