
# Copyright 2022 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.

import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available


def     UpperCAmelCase_  (						__lowerCAmelCase=None	) ->						List[str]:
    if subparsers is not None:
        __lowercase		:			List[str]	    =       subparsers.add_parser('''env'''	)
    else:
        __lowercase		:			List[str]	    =       argparse.ArgumentParser('''Accelerate env command'''	)

    parser.add_argument(
        '''--config_file'''	,					default=__lowerCAmelCase	,					help='''The config file to use for the default values in the launching script.'''	)

    if subparsers is not None:
        parser.set_defaults(func=__lowerCAmelCase	)
    return parser


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						Tuple:
    __lowercase		:			Tuple	    =       torch.__version__
    __lowercase		:			Optional[Any]	    =       torch.cuda.is_available()
    __lowercase		:			Tuple	    =       is_xpu_available()
    __lowercase		:			int	    =       is_npu_available()

    __lowercase		:			int	    =       '''Not found'''
    # Get the default from the config file.
    if args.config_file is not None or os.path.isfile(__lowerCAmelCase	):
        __lowercase		:			int	    =       load_config_from_file(args.config_file	).to_dict()

    __lowercase		:			Optional[int]	    =       {
        '''`Accelerate` version''': version,
        '''Platform''': platform.platform(),
        '''Python version''': platform.python_version(),
        '''Numpy version''': np.__version__,
        '''PyTorch version (GPU?)''': F'{pt_version} ({pt_cuda_available})',
        '''PyTorch XPU available''': str(__lowerCAmelCase	),
        '''PyTorch NPU available''': str(__lowerCAmelCase	),
        '''System RAM''': F'{psutil.virtual_memory().total / 1_024 ** 3:.2f} GB',
    }
    if pt_cuda_available:
        __lowercase		:			Any	    =       torch.cuda.get_device_name()

    print('''\nCopy-and-paste the text below in your GitHub issue\n'''	)
    print('''\n'''.join([F'- {prop}: {val}' for prop, val in info.items()]	)	)

    print('''- `Accelerate` default config:''' if args.config_file is None else '''- `Accelerate` config passed:'''	)
    __lowercase		:			int	    =       (
        '''\n'''.join([F'\t- {prop}: {val}' for prop, val in accelerate_config.items()]	)
        if isinstance(__lowerCAmelCase	,					__lowerCAmelCase	)
        else F'\t{accelerate_config}'
    )
    print(__lowerCAmelCase	)

    __lowercase		:			Optional[Any]	    =       accelerate_config

    return info


def     UpperCAmelCase_  (						) ->						int:
    __lowercase		:			str	    =       env_command_parser()
    __lowercase		:			Optional[int]	    =       parser.parse_args()
    env_command(__lowerCAmelCase	)
    return 0


if __name__ == "__main__":
 raise SystemExit(main())




import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

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


__lowerCAmelCase					:			Union[str, Any]			      =		logging.get_logger(__name__)

__lowerCAmelCase					:			Optional[int]			      =		{
    "nvidia/segformer-b0-finetuned-ade-512-512": (
        "https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json"
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}


class 						__lowerCAmelCase	(	lowerCAmelCase_      ):



      """simple docstring"""







      A__	:			Dict        =    '''segformer'''




      def __init__(      self		:       Optional[Any]				,       _snake_case		:       List[str]=3				,       _snake_case		:       Union[str, Any]=4				,       _snake_case		:       str=[2, 2, 2, 2]				,       _snake_case		:       Dict=[8, 4, 2, 1]				,       _snake_case		:       List[Any]=[32, 64, 160, 256]				,       _snake_case		:       Dict=[7, 3, 3, 3]				,       _snake_case		:       List[Any]=[4, 2, 2, 2]				,       _snake_case		:       Tuple=[1, 2, 5, 8]				,       _snake_case		:       Optional[Any]=[4, 4, 4, 4]				,       _snake_case		:       Optional[int]="gelu"				,       _snake_case		:       Optional[int]=0.0				,       _snake_case		:       Optional[int]=0.0				,       _snake_case		:       int=0.1				,       _snake_case		:       Any=0.02				,       _snake_case		:       Optional[int]=0.1				,       _snake_case		:       Union[str, Any]=1E-6				,       _snake_case		:       Tuple=256				,       _snake_case		:       str=255				,       **_snake_case		:       Any				,       ):
          super().__init__(**_snake_case				)

          if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
              warnings.warn(
                  '''Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be'''
                  ''' removed, as the behaviour will default to that of reshape_last_stage = True.'''				,       _snake_case				,       )

          __lowercase		:			Any	    =       num_channels
          __lowercase		:			Optional[Any]	    =       num_encoder_blocks
          __lowercase		:			List[str]	    =       depths
          __lowercase		:			str	    =       sr_ratios
          __lowercase		:			List[str]	    =       hidden_sizes
          __lowercase		:			List[str]	    =       patch_sizes
          __lowercase		:			Dict	    =       strides
          __lowercase		:			Optional[int]	    =       mlp_ratios
          __lowercase		:			List[str]	    =       num_attention_heads
          __lowercase		:			Optional[int]	    =       hidden_act
          __lowercase		:			List[Any]	    =       hidden_dropout_prob
          __lowercase		:			Optional[Any]	    =       attention_probs_dropout_prob
          __lowercase		:			List[Any]	    =       classifier_dropout_prob
          __lowercase		:			str	    =       initializer_range
          __lowercase		:			Optional[int]	    =       drop_path_rate
          __lowercase		:			List[str]	    =       layer_norm_eps
          __lowercase		:			List[str]	    =       decoder_hidden_size
          __lowercase		:			Union[str, Any]	    =       kwargs.get('''reshape_last_stage'''				,       _snake_case				)
          __lowercase		:			str	    =       semantic_loss_ignore_index






class 						__lowerCAmelCase	(	lowerCAmelCase_      ):



      """simple docstring"""







      A__	:			Union[str, Any]        =    version.parse('''1.11'''      )




      @property
      def 		snake_case_			(      self		:       Dict				):
          return OrderedDict(
              [
                  ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
              ]				)




      @property
      def 		snake_case_			(      self		:       int				):
          return 1E-4




      @property
      def 		snake_case_			(      self		:       List[Any]				):
          return 12


