Accepts a library version and returns True if the current version of the library is less than or equal to the given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches 2.7.0).
(library_version: str, accept_dev: bool = False)
| 180 | |
| 181 | @lru_cache |
| 182 | def is_torch_less_or_equal(library_version: str, accept_dev: bool = False) -> bool: |
| 183 | """ |
| 184 | Accepts a library version and returns True if the current version of the library is less than or equal to the |
| 185 | given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches |
| 186 | 2.7.0). |
| 187 | """ |
| 188 | if not is_torch_available(): |
| 189 | return False |
| 190 | |
| 191 | if accept_dev: |
| 192 | return version.parse(version.parse(get_torch_version()).base_version) <= version.parse(library_version) |
| 193 | else: |
| 194 | return version.parse(get_torch_version()) <= version.parse(library_version) |
| 195 | |
| 196 | |
| 197 | @lru_cache |
no test coverage detected