Buckets:
MisterAI/LocalAI_Demo_backends / cpu-diffusers.upgrade-tmp /venv /lib /python3.10 /site-packages /accelerate /utils /versions.py
| # 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 importlib.metadata | |
| from typing import Union | |
| from packaging.version import Version, parse | |
| from .constants import STR_OPERATION_TO_FUNC | |
| torch_version = parse(importlib.metadata.version("torch")) | |
| def compare_versions(library_or_version: Union[str, Version], operation: str, requirement_version: str): | |
| """ | |
| Compares a library version to some requirement using a given operation. | |
| Args: | |
| library_or_version (`str` or `packaging.version.Version`): | |
| A library name or a version to check. | |
| operation (`str`): | |
| A string representation of an operator, such as `">"` or `"<="`. | |
| requirement_version (`str`): | |
| The version to compare the library version against | |
| """ | |
| if operation not in STR_OPERATION_TO_FUNC.keys(): | |
| raise ValueError(f"`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys())}, received {operation}") | |
| operation = STR_OPERATION_TO_FUNC[operation] | |
| if isinstance(library_or_version, str): | |
| library_or_version = parse(importlib.metadata.version(library_or_version)) | |
| return operation(library_or_version, parse(requirement_version)) | |
| def is_torch_version(operation: str, version: str): | |
| """ | |
| Compares the current PyTorch version to a given reference with an operation. | |
| Args: | |
| operation (`str`): | |
| A string representation of an operator, such as `">"` or `"<="` | |
| version (`str`): | |
| A string version of PyTorch | |
| """ | |
| return compare_versions(torch_version, operation, version) | |
Xet Storage Details
- Size:
- 2.15 kB
- Xet hash:
- afc5aa2a746b06a468ac444d8e664d434b0dfd958e0f3829bb1d2663a1fe2cb5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.