



'''simple docstring'''





# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
       import torch







class        UpperCAmelCase_			(			TensorFormatter[Mapping, "torch.Tensor", Mapping]      ):
    """simple docstring"""







    def __init__(       self   :	int					,	snake_case_   :	int=None					,	**snake_case_   :	List[str]		):
          super().__init__(features=snake_case_		)
          snake_case__    :       Any       		= torch_tensor_kwargs
          import torch  # noqa import torch at initialization




    def lowerCamelCase			(       self   :	Optional[Any]					,	snake_case_   :	Optional[int]		):
          import torch

          if isinstance(snake_case_					,	snake_case_		) and column:
                if all(
                    isinstance(snake_case_					,	torch.Tensor		) and x.shape == column[0].shape and x.dtype == column[0].dtype
                    for x in column		):
                      return torch.stack(snake_case_		)
          return column




    def lowerCamelCase			(       self   :	int					,	snake_case_   :	List[str]		):
          import torch

          if isinstance(snake_case_					,	(str, bytes, type(snake_case_		))		):
                return value
          elif isinstance(snake_case_					,	(np.character, np.ndarray)		) and np.issubdtype(value.dtype					,	np.character		):
                return value.tolist()

          snake_case__    :       Dict       		= {}

          if isinstance(snake_case_					,	(np.number, np.ndarray)		) and np.issubdtype(value.dtype					,	np.integer		):
                snake_case__    :       Optional[Any]       		= {"""dtype""": torch.intaa}
          elif isinstance(snake_case_					,	(np.number, np.ndarray)		) and np.issubdtype(value.dtype					,	np.floating		):
                snake_case__    :       Dict       		= {"""dtype""": torch.floataa}
          elif config.PIL_AVAILABLE and "PIL" in sys.modules:
                import PIL.Image

                if isinstance(snake_case_					,	PIL.Image.Image		):
                      snake_case__    :       Optional[int]       		= np.asarray(snake_case_		)
          return torch.tensor(snake_case_					,	**{**default_dtype, **self.torch_tensor_kwargs}		)




    def lowerCamelCase			(       self   :	List[str]					,	snake_case_   :	List[Any]		):
          import torch

          # support for torch, tf, jax etc.
          if hasattr(snake_case_					,	"""__array__"""		) and not isinstance(snake_case_					,	torch.Tensor		):
                snake_case__    :       Optional[Any]       		= data_struct.__array__()
          # support for nested types like struct of list of struct
          if isinstance(snake_case_					,	np.ndarray		):
                if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
                      return self._consolidate([self.recursive_tensorize(snake_case_		) for substruct in data_struct]		)
          elif isinstance(snake_case_					,	(list, tuple)		):
                return self._consolidate([self.recursive_tensorize(snake_case_		) for substruct in data_struct]		)
          return self._tensorize(snake_case_		)




    def lowerCamelCase			(       self   :	Any					,	snake_case_   :	dict		):
          return map_nested(self._recursive_tensorize					,	snake_case_					,	map_list=snake_case_		)




    def lowerCamelCase			(       self   :	List[Any]					,	snake_case_   :	pa.Table		):
          snake_case__    :       str       		= self.numpy_arrow_extractor().extract_row(snake_case_		)
          snake_case__    :       List[Any]       		= self.python_features_decoder.decode_row(snake_case_		)
          return self.recursive_tensorize(snake_case_		)




    def lowerCamelCase			(       self   :	Tuple					,	snake_case_   :	pa.Table		):
          snake_case__    :       Any       		= self.numpy_arrow_extractor().extract_column(snake_case_		)
          snake_case__    :       Optional[Any]       		= self.python_features_decoder.decode_column(snake_case_					,	pa_table.column_names[0]		)
          snake_case__    :       str       		= self.recursive_tensorize(snake_case_		)
          snake_case__    :       Tuple       		= self._consolidate(snake_case_		)
          return column




    def lowerCamelCase			(       self   :	List[str]					,	snake_case_   :	pa.Table		):
          snake_case__    :       Any       		= self.numpy_arrow_extractor().extract_batch(snake_case_		)
          snake_case__    :       str       		= self.python_features_decoder.decode_batch(snake_case_		)
          snake_case__    :       str       		= self.recursive_tensorize(snake_case_		)
          for column_name in batch:
                snake_case__    :       int       		= self._consolidate(batch[column_name]		)
          return batch





'''simple docstring'''





# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import sys

import transformers


__a  			=						"3"

print("Python version:", sys.version)
print("transformers version:", transformers.__version__)

try:
       import torch

       print("Torch version:", torch.__version__)
       print("Cuda available:", torch.cuda.is_available())
       print("Cuda version:", torch.version.cuda)
       print("CuDNN version:", torch.backends.cudnn.version())
       print("Number of GPUs available:", torch.cuda.device_count())
       print("NCCL version:", torch.cuda.nccl.version())
except ImportError:
       print("Torch version:", None)

try:
       import deepspeed

       print("DeepSpeed version:", deepspeed.__version__)
except ImportError:
       print("DeepSpeed version:", None)

try:
       import tensorflow as tf

       print("TensorFlow version:", tf.__version__)
       print("TF GPUs available:", bool(tf.config.list_physical_devices("GPU")))
       print("Number of TF GPUs available:", len(tf.config.list_physical_devices("GPU")))
except ImportError:
       print("TensorFlow version:", None)
