




'''simple docstring'''







import argparse
import copy
import json
import multiprocessing
import os
import time

from create_dummy_models import COMPOSITE_MODELS, create_tiny_models
from huggingface_hub import ModelFilter, hf_api

import transformers
from transformers import AutoFeatureExtractor, AutoImageProcessor, AutoTokenizer
from transformers.image_processing_utils import BaseImageProcessor



def 					lowerCamelCase__							(			):
     snake_case :			Union[str, Any]					   = set()
     # Each auto modeling files contains multiple mappings. Let's get them in a dynamic way.
     for module_name in ["modeling_auto", "modeling_tf_auto", "modeling_flax_auto"]:
          snake_case :			List[Any]					   = getattr(transformers.models.auto    ,      __lowercase    ,      __lowercase )
          if module is None:
               continue
          # all mappings in a single auto modeling file
          snake_case :			Optional[Any]					   = [
              x
              for x in dir(__lowercase )
              if x.endswith("""_MAPPING_NAMES""" )
              and (x.startswith("""MODEL_""" ) or x.startswith("""TF_MODEL_""" ) or x.startswith("""FLAX_MODEL_""" ))
          ]
          for name in mapping_names:
               snake_case :			List[str]					   = getattr(__lowercase    ,      __lowercase )
               if mapping is not None:
                    for v in mapping.values():
                         if isinstance(__lowercase    ,      (list, tuple) ):
                              model_names.update(__lowercase )
                         elif isinstance(__lowercase    ,      __lowercase ):
                              model_names.add(__lowercase )

     return sorted(__lowercase )



def 					lowerCamelCase__							(			):
     # All model names defined in auto mappings
     snake_case :			Union[str, Any]					   = set(get_all_model_names() )

     with open("""tests/utils/tiny_model_summary.json""" ) as fp:
          snake_case :			Optional[Any]					   = json.load(__lowercase )
     snake_case :			Tuple					   = set()
     for model_base_name in tiny_model_info:
          tiny_models_names.update(tiny_model_info[model_base_name]["""model_classes"""] )

     # Remove a tiny model name if one of its framework implementation hasn't yet a tiny version on the Hub.
     snake_case :			List[Any]					   = model_names.difference(__lowercase )
     for model_name in copy.copy(__lowercase ):
          if not model_name.startswith("""TF""" ) and F'''TF{model_name}''' in not_on_hub:
               tiny_models_names.remove(__lowercase )
          elif model_name.startswith("""TF""" ) and model_name[2:] in not_on_hub:
               tiny_models_names.remove(__lowercase )

     return sorted(__lowercase )



def 					lowerCamelCase__							(			__lowercase ):
     snake_case :			Optional[Any]					   = COMPOSITE_MODELS.values()

     # All tiny model base names on Hub
     snake_case :			Optional[Any]					   = get_all_model_names()
     snake_case :			Union[str, Any]					   = hf_api.list_models(
         filter=ModelFilter(
             author="""hf-internal-testing"""    ,      ) )
     snake_case :			Any					   = set()
     for x in models:
          snake_case :			Optional[int]					   = x.modelId
          snake_case :			str					   = model.split("""/""" )
          if not model.startswith("""tiny-random-""" ):
               continue
          snake_case :			Optional[Any]					   = model.replace("""tiny-random-"""    ,      """""" )
          if not model[0].isupper():
               continue
          if model not in model_names and model not in special_models:
               continue
          _models.add(__lowercase )

     snake_case :			List[Any]					   = sorted(_models )
     # All tiny model names on Hub
     snake_case :			int					   = {}
     for model in models:
          snake_case :			Optional[Any]					   = F'''hf-internal-testing/tiny-random-{model}'''
          snake_case :			Any					   = model.split("""-""" )[0]
          try:
               snake_case :			List[str]					   = hf_api.repo_info(__lowercase )
               snake_case :			List[str]					   = {
                   '''tokenizer_classes''': set(),
                   '''processor_classes''': set(),
                   '''model_classes''': set(),
                   '''sha''': repo_info.sha,
               }
          except Exception:
               continue
          try:
               time.sleep(1 )
               snake_case :			Union[str, Any]					   = AutoTokenizer.from_pretrained(__lowercase )
               content["tokenizer_classes"].add(tokenizer_fast.__class__.__name__ )
          except Exception:
               pass
          try:
               time.sleep(1 )
               snake_case :			int					   = AutoTokenizer.from_pretrained(__lowercase    ,      use_fast=__lowercase )
               content["tokenizer_classes"].add(tokenizer_slow.__class__.__name__ )
          except Exception:
               pass
          try:
               time.sleep(1 )
               snake_case :			int					   = AutoImageProcessor.from_pretrained(__lowercase )
               content["processor_classes"].add(img_p.__class__.__name__ )
          except Exception:
               pass
          try:
               time.sleep(1 )
               snake_case :			List[Any]					   = AutoFeatureExtractor.from_pretrained(__lowercase )
               if not isinstance(__lowercase    ,      __lowercase ):
                    content["processor_classes"].add(feat_p.__class__.__name__ )
          except Exception:
               pass
          try:
               time.sleep(1 )
               snake_case :			Tuple					   = getattr(__lowercase    ,      __lowercase )
               snake_case :			Tuple					   = model_class.from_pretrained(__lowercase )
               content["model_classes"].add(m.__class__.__name__ )
          except Exception:
               pass
          try:
               time.sleep(1 )
               snake_case :			Dict					   = getattr(__lowercase    ,      F'''TF{model}''' )
               snake_case :			Optional[Any]					   = model_class.from_pretrained(__lowercase )
               content["model_classes"].add(m.__class__.__name__ )
          except Exception:
               pass

          snake_case :			Dict					   = sorted(content["""tokenizer_classes"""] )
          snake_case :			Tuple					   = sorted(content["""processor_classes"""] )
          snake_case :			Union[str, Any]					   = sorted(content["""model_classes"""] )

          snake_case :			List[Any]					   = content
          with open(os.path.join(__lowercase    ,      """hub_tiny_model_summary.json""" )    ,      """w""" ) as fp:
               json.dump(__lowercase    ,      __lowercase    ,      ensure_ascii=__lowercase    ,      indent=4 )


if __name__ == "__main__":
      lowercase			:      List[str]			=					argparse.ArgumentParser()
      parser.add_argument("""--num_workers""", default=1, type=int, help="""The number of workers to run.""")
      lowercase			:      List[Any]			=					parser.parse_args()

      # This has to be `spawn` to avoid hanging forever!
      multiprocessing.set_start_method("""spawn""")

      lowercase			:      Optional[Any]			=					"""tiny_models"""
      lowercase			:      Optional[Any]			=					True
      lowercase			:      str			=					None
      lowercase			:      int			=					get_tiny_model_names_from_repo()
      lowercase			:      Optional[Any]			=					True
      lowercase			:      List[str]			=					True
      lowercase			:      str			=					"""hf-internal-testing"""

      create_tiny_models(
          output_path,
          all,
          model_types,
          models_to_skip,
          no_check,
          upload,
          organization,
          token=os.environ.get("""TOKEN""", None),
          num_workers=args.num_workers,
      )









'''simple docstring'''







from sklearn.metrics import mean_absolute_error

import datasets


lowercase			:      int			=					"""\
@article{scikit-learn,
 title={Scikit-learn: Machine Learning in {P}ython},
 author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
 journal={Journal of Machine Learning Research},
 volume={12},
 pages={2825--2830},
 year={2011}
}
"""

lowercase			:      Optional[Any]			=					"""\
Mean Absolute Error (MAE) is the mean of the magnitude of difference between the predicted and actual
values.
"""


lowercase			:      List[Any]			=					"""
Args:
    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Estimated target values.
    references: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Ground truth (correct) target values.
    sample_weight: array-like of shape (n_samples,), default=None
        Sample weights.
    multioutput: {\"raw_values\", \"uniform_average\"} or array-like of shape (n_outputs,), default=\"uniform_average\"
        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.

                 \"raw_values\" : Returns a full set of errors in case of multioutput input.

                 \"uniform_average\" : Errors of all outputs are averaged with uniform weight.

Returns:
    mae : mean absolute error.
        If multioutput is \"raw_values\", then mean absolute error is returned for each output separately. If multioutput is \"uniform_average\" or an ndarray of weights, then the weighted average of all output errors is returned.
        MAE output is non-negative floating point. The best value is 0.0.
Examples:

    >>> mae_metric = datasets.load_metric(\"mae\")
    >>> predictions = [2.5, 0.0, 2, 8]
    >>> references = [3, -0.5, 2, 7]
    >>> results = mae_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mae': 0.5}

    If you're using multi-dimensional lists, then set the config as follows :

    >>> mae_metric = datasets.load_metric(\"mae\", \"multilist\")
    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]
    >>> references = [[0, 2], [-1, 2], [8, -5]]
    >>> results = mae_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'mae': 0.75}
    >>> results = mae_metric.compute(predictions=predictions, references=references, multioutput='raw_values')
    >>> print(results)
    {'mae': array([0.5, 1. ])}
"""







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION,		_KWARGS_DESCRIPTION  )
class 				_a   (datasets.Metric  ):





     '''simple docstring'''



     def  snake_case_			(							self       )			->							int:
          return datasets.MetricInfo(
              description=_DESCRIPTION       ,citation=_CITATION       ,inputs_description=_KWARGS_DESCRIPTION       ,features=datasets.Features(self._get_feature_types()       )       ,reference_urls=[
                  """https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_absolute_error.html"""
              ]       ,)







     def  snake_case_			(							self       )			->							Any:
          if self.config_name == "multilist":
               return {
                   "predictions": datasets.Sequence(datasets.Value("""float"""       )       ),
                   "references": datasets.Sequence(datasets.Value("""float"""       )       ),
               }
          else:
               return {
                   "predictions": datasets.Value("""float"""       ),
                   "references": datasets.Value("""float"""       ),
               }







     def  snake_case_			(							self       ,__a       ,__a       ,__a=None       ,__a="uniform_average"       )			->							str:
          snake_case :			int					   = mean_absolute_error(__a       ,__a       ,sample_weight=__a       ,multioutput=__a       )

          return {"mae": mae_score}



