|
7 | 7 |
|
8 | 8 | import logging
|
9 | 9 | import os
|
| 10 | +import re |
10 | 11 |
|
11 | 12 | import torch
|
12 | 13 |
|
| 14 | +# Based on the FBGEMM-PyTorch compatibility table at |
| 15 | +# https://docs.pytorch.org/FBGEMM/general/Releases.html#fbgemm-releases-compatibility |
| 16 | +_fbgemm_torch_compat_table = { |
| 17 | + "1.3": "2.8", |
| 18 | + "1.2": "2.7", |
| 19 | + "1.1": "2.6", |
| 20 | + "1.0": "2.5", |
| 21 | + "0.8": "2.4", |
| 22 | + "0.7": "2.3", |
| 23 | + "0.6": "2.2", |
| 24 | + "0.5": "2.1", |
| 25 | + "0.4": "2.0", |
| 26 | +} |
| 27 | + |
13 | 28 |
|
14 |
| -def _load_library(filename: str, no_throw: bool = False) -> None: |
| 29 | +def _load_library(filename: str, version: str, no_throw: bool = False) -> None: |
15 | 30 | """Load a shared library from the given filename."""
|
| 31 | + |
| 32 | + # Check if the version of PyTorch is compatible with the version of FBGEMM |
| 33 | + # that we are trying to load, and print a loud warning if not. This is |
| 34 | + # useful for the OSS build, where we have a single FBGEMM library that is |
| 35 | + # compatible with multiple versions of PyTorch. |
| 36 | + # |
| 37 | + # Based on: https://github.com/pytorch/ao/blob/main/torchao/__init__.py#L30 |
| 38 | + |
| 39 | + keys = [ |
| 40 | + key |
| 41 | + for key in _fbgemm_torch_compat_table.keys() |
| 42 | + if version.startswith(f"{key}.") |
| 43 | + ] |
| 44 | + |
| 45 | + if version == "INTERNAL" or "+git" in version: |
| 46 | + # if FBGEMM version has "+git", assume it's locally built and we don't know |
| 47 | + # anything about the PyTorch version used to build it |
| 48 | + logging.info( |
| 49 | + "FBGEMM version is INTERNAL or local, ignoring version compatibility check with PyTorch" |
| 50 | + ) |
| 51 | + |
| 52 | + elif re.match(r"^\d{4}\.\d{1,2}\.\d{1,2}.*$", version): |
| 53 | + # if FBGEMM version is a date, assume it's a nightly build and that we |
| 54 | + # know what we're doing |
| 55 | + logging.info( |
| 56 | + "FBGEMM version is a nightly version, ignoring version compatibility check with PyTorch" |
| 57 | + ) |
| 58 | + |
| 59 | + elif not keys: |
| 60 | + logging.warning( |
| 61 | + f""" |
| 62 | + \033[33m |
| 63 | + _fbgemm_torch_compat_table has no entry for {version} of FBGEMM; |
| 64 | + cannot determine compatibility with PyTorch {torch.__version__} |
| 65 | + \033[0m |
| 66 | + """ |
| 67 | + ) |
| 68 | + |
| 69 | + elif str(torch.__version__) != _fbgemm_torch_compat_table[keys[0]]: |
| 70 | + logging.warning( |
| 71 | + f""" |
| 72 | + \033[31m |
| 73 | + FBGEMM_GPU version is {version}, which is not guaranteed to be |
| 74 | + compatible with PyTorch {torch.__version__}; library loading might |
| 75 | + crash! |
| 76 | +
|
| 77 | + Please refer to |
| 78 | + https://docs.pytorch.org/FBGEMM/general/Releases.html#fbgemm-releases-compatibility |
| 79 | + for the FBGEMM-PyTorch compatibility table. |
| 80 | + \033[0m |
| 81 | + """ |
| 82 | + ) |
| 83 | + |
16 | 84 | try:
|
17 | 85 | torch.ops.load_library(os.path.join(os.path.dirname(__file__), filename))
|
18 | 86 | logging.info(f"Successfully loaded: '{filename}'")
|
| 87 | + |
19 | 88 | except Exception as error:
|
20 | 89 | logging.error(f"Could not load the library '{filename}'!\n\n\n{error}\n\n\n")
|
21 | 90 | if not no_throw:
|
@@ -87,7 +156,7 @@ def _load_library(filename: str, no_throw: bool = False) -> None:
|
87 | 156 | #
|
88 | 157 | # https://github.com/pytorch/FBGEMM/pull/3477
|
89 | 158 | # https://github.com/pytorch/FBGEMM/pull/3717
|
90 |
| - _load_library(f"{library}.so", __variant__ == "docs") |
| 159 | + _load_library(f"{library}.so", __version__, __variant__ == "docs") |
91 | 160 |
|
92 | 161 | try:
|
93 | 162 | # Trigger meta operator registrations
|
|
0 commit comments