fyrizi commited on
Commit
5bb23e8
·
verified ·
1 Parent(s): 64712ed

Delete main/src/utils/requires.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. main/src/utils/requires.py +0 -39
main/src/utils/requires.py DELETED
@@ -1,39 +0,0 @@
1
- import torch
2
-
3
-
4
- def torch_requires(min_version: str, silent_fail: bool = False):
5
- """
6
- Requires a minimum pytorch version.
7
-
8
- If the version is not satisfy, the requested function will throw a :class:`RuntimeError` when called
9
- (but not when declared) if `silent_fail` is `False`. Otherwise, the function is not called and `None`
10
- is returned.
11
-
12
- Args:
13
- min_version: a version represented as string
14
- silent_fail: if True, the decorated function will not be executed and return `None`. If `False`,
15
- throw a :class:`RuntimeError`
16
- """
17
- def version_error(*args, **kwargs):
18
- raise RuntimeError(f'Requires pytorch version >= {min_version}')
19
-
20
- def return_none(*args, **kwargs):
21
- return None
22
-
23
- def inner(func):
24
- def wrapper(*args, **kwargs):
25
- return func(*args, **kwargs)
26
-
27
- from packaging.version import Version
28
- current_version = Version(torch.__version__)
29
-
30
- target_version = Version(min_version)
31
- if current_version >= target_version:
32
- return wrapper
33
- else:
34
- if silent_fail:
35
- return return_none
36
- else:
37
- return version_error
38
-
39
- return inner