/usr/local/lib/python3.6/site-packages/transformers/utils
NameSizeModeActions
__pycache__/-0755rm
doc.py388360644editdlrm
dummy_detectron2_objects.py3910644editdlrm
dummy_flax_objects.py248550644editdlrm
dummy_pt_objects.py1114430644editdlrm
dummy_pytorch_quantization_and_torch_objects.py24760644editdlrm
dummy_scatter_objects.py11380644editdlrm
dummy_sentencepiece_and_speech_objects.py3420644editdlrm
dummy_sentencepiece_and_tokenizers_objects.py3010644editdlrm
dummy_sentencepiece_objects.py43710644editdlrm
dummy_speech_objects.py3150644editdlrm
dummy_tf_objects.py504560644editdlrm
dummy_timm_and_vision_objects.py9030644editdlrm
dummy_timm_objects.py8050644editdlrm
dummy_tokenizers_objects.py81730644editdlrm
dummy_vision_objects.py34860644editdlrm
fx.py231860644editdlrm
fx_transformations.py121780644editdlrm
generic.py98200644editdlrm
hp_naming.py49710644editdlrm
hub.py429320644editdlrm
import_utils.py292880644editdlrm
logging.py95160644editdlrm
model_parallel_utils.py22760644editdlrm
notebook.py145240644editdlrm
sentencepiece_model_pb2.py396070644editdlrm
versions.py43780644editdlrm
__init__.py50550644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/utils/versions.py (4378B)
# Copyright 2020 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. """ Utilities for working with package versions """ import operator import re import sys from typing import Optional from packaging import version # The package importlib_metadata is in a different place, depending on the python version. if sys.version_info < (3, 8): import importlib_metadata else: import importlib.metadata as importlib_metadata ops = { "<": operator.lt, "<=": operator.le, "==": operator.eq, "!=": operator.ne, ">=": operator.ge, ">": operator.gt, } def _compare_versions(op, got_ver, want_ver, requirement, pkg, hint): if got_ver is None: raise ValueError("got_ver is None") if want_ver is None: raise ValueError("want_ver is None") if not ops[op](version.parse(got_ver), version.parse(want_ver)): raise ImportError( f"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}" ) def require_version(requirement: str, hint: Optional[str] = None) -> None: """ Perform a runtime check of the dependency versions, using the exact same syntax used by pip. The installed module version comes from the *site-packages* dir via *importlib_metadata*. Args: requirement (`str`): pip style definition, e.g., "tokenizers==0.9.4", "tqdm>=4.27", "numpy" hint (`str`, *optional*): what suggestion to print in case of requirements not being met Example: ```python require_version("pandas>1.1.2") require_version("numpy>1.18.5", "this is important to have for whatever reason") ```""" hint = f"\n{hint}" if hint is not None else "" # non-versioned check if re.match(r"^[\w_\-\d]+$", requirement): pkg, op, want_ver = requirement, None, None else: match = re.findall(r"^([^!=<>\s]+)([\s!=<>]{1,2}.+)", requirement) if not match: raise ValueError( f"requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}" ) pkg, want_full = match[0] want_range = want_full.split(",") # there could be multiple requirements wanted = {} for w in want_range: match = re.findall(r"^([\s!=<>]{1,2})(.+)", w) if not match: raise ValueError( f"requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}" ) op, want_ver = match[0] wanted[op] = want_ver if op not in ops: raise ValueError(f"{requirement}: need one of {list(ops.keys())}, but got {op}") # special case if pkg == "python": got_ver = ".".join([str(x) for x in sys.version_info[:3]]) for op, want_ver in wanted.items(): _compare_versions(op, got_ver, want_ver, requirement, pkg, hint) return # check if any version is installed try: got_ver = importlib_metadata.version(pkg) except importlib_metadata.PackageNotFoundError: raise importlib_metadata.PackageNotFoundError( f"The '{requirement}' distribution was not found and is required by this application. {hint}" ) # check that the right version is installed if version number or a range was provided if want_ver is not None: for op, want_ver in wanted.items(): _compare_versions(op, got_ver, want_ver, requirement, pkg, hint) def require_version_core(requirement): """require_version wrapper which emits a core-specific hint on failure""" hint = "Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main" return require_version(requirement, hint)