





import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs



@pytest.mark.parametrize(
    """kwargs, expected"""  ,[
        ({"""num_shards""": 0, """max_num_jobs""": 1}, []),
        ({"""num_shards""": 1_0, """max_num_jobs""": 1}, [range(1_0     )]),
        ({"""num_shards""": 1_0, """max_num_jobs""": 1_0}, [range(_lowerCAmelCase  ,i + 1     ) for i in range(1_0     )]),
        ({"""num_shards""": 1, """max_num_jobs""": 1_0}, [range(1     )]),
        ({"""num_shards""": 1_0, """max_num_jobs""": 3}, [range(0  ,4     ), range(4  ,7     ), range(7  ,1_0     )]),
        ({"""num_shards""": 3, """max_num_jobs""": 1_0}, [range(0  ,1     ), range(1  ,2     ), range(2  ,3     )]),
    ]  ,)
def     _lowerCAmelCase		(  _lowerCAmelCase  ,_lowerCAmelCase     ):
			'''simple docstring'''


			A_     :				Union[str, Any]			      =	_distribute_shards(**_lowerCAmelCase     )
			assert out == expected



@pytest.mark.parametrize(
    """gen_kwargs, max_num_jobs, expected"""  ,[
        ({"""foo""": 0}, 1_0, [{"""foo""": 0}]),
        ({"""shards""": [0, 1, 2, 3]}, 1, [{"""shards""": [0, 1, 2, 3]}]),
        ({"""shards""": [0, 1, 2, 3]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}, {"""shards""": [2]}, {"""shards""": [3]}]),
        ({"""shards""": [0, 1]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}]),
        ({"""shards""": [0, 1, 2, 3]}, 2, [{"""shards""": [0, 1]}, {"""shards""": [2, 3]}]),
    ]  ,)
def     _lowerCAmelCase		(  _lowerCAmelCase  ,_lowerCAmelCase  ,_lowerCAmelCase     ):
			'''simple docstring'''


			A_     :				str			      =	_split_gen_kwargs(_lowerCAmelCase  ,_lowerCAmelCase     )
			assert out == expected







@pytest.mark.parametrize(
    """gen_kwargs, expected"""  ,[
        ({"""foo""": 0}, 1),
        ({"""shards""": [0]}, 1),
        ({"""shards""": [0, 1, 2, 3]}, 4),
        ({"""shards""": [0, 1, 2, 3], """foo""": 0}, 4),
        ({"""shards""": [0, 1, 2, 3], """other""": (0, 1)}, 4),
        ({"""shards""": [0, 1, 2, 3], """shards2""": [0, 1]}, RuntimeError),
    ]  ,)
def     _lowerCAmelCase		(  _lowerCAmelCase  ,_lowerCAmelCase     ):
			'''simple docstring'''


			if expected is RuntimeError:
						with pytest.raises(_lowerCAmelCase     ):
									_number_of_shards_in_gen_kwargs(_lowerCAmelCase     )
			else:
						A_     :				Union[str, Any]			      =	_number_of_shards_in_gen_kwargs(_lowerCAmelCase     )
						assert out == expected













# 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


_lowerCAmelCase 				=     """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)






