Skip to content

Commit 9500a9e

Browse files
committed
fix code style
1 parent 0b8db44 commit 9500a9e

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

src/flag_gems/runtime/backend/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ..common import vendors
1010
from . import backend_utils
1111

12+
1213
class BackendState:
1314
"""Singleton class to manage backend state variables."""
1415

@@ -37,7 +38,7 @@ def __init__(self):
3738
self.customized_ops = None
3839

3940

40-
# Global singleton instance
41+
# Global singleton instance
4142
_state = BackendState()
4243

4344

@@ -149,14 +150,13 @@ def _import_module_safe(module_name, vendor_name, module_type):
149150
return importlib.import_module(module_name)
150151
except ModuleNotFoundError:
151152
print(
152-
f"[Note] No specialized {module_type} operators were found for "
153-
f"the {vendor_name}, generic {module_type} operators will be used by default."
153+
f"[Note] No specialized {module_type} operators were found for "
154+
f"the {vendor_name}, generic {module_type} operators will be used by default."
154155
)
155156
except Exception as e:
156157
raise RuntimeError(f"Failed to import vendor extra lib: {e}")
157158

158159

159-
160160
def import_vendor_extra_lib(vendor_name=None):
161161
if _state.vendor_extra_lib_imported:
162162
return
@@ -239,7 +239,7 @@ def get_module(vendor_name):
239239
return get_module(vendor_name)
240240

241241
if _state.vendor_module is None:
242-
_state.vendor_module = get_module("_" + vendor_name)
242+
_state.vendor_module = get_module("_" + vendor_name)
243243
return _state.vendor_module
244244

245245

@@ -290,7 +290,7 @@ def get_heuristic_config(vendor_name=None):
290290
try:
291291
_state.heuristic_config_module = importlib.import_module(mod_name)
292292
except Exception:
293-
continue
293+
continue
294294
return getattr(_state.heuristic_config_module, "HEURISTICS_CONFIGS", None)
295295

296296

@@ -303,8 +303,10 @@ def get_tune_config(vendor_name=None):
303303
def get_expand_config(op_name=None, file_path=None):
304304
return backend_utils.get_expand_config(op_name=op_name, file_path=file_path)
305305

306+
306307
def get_backend_state() -> BackendState:
307308
"""Get the global BackendState singleton instance."""
308309
return _state
309310

311+
310312
__all__ = ["*"]

src/flag_gems/runtime/backend/device.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import torch # noqa: F401
77

88
from .. import backend, error
9-
109
from ..common import (
1110
_VENDOR_TORCH_ATTR,
1211
UNSUPPORT_BF16,
@@ -19,6 +18,7 @@
1918
# A singleton class to manage device context.
2019
class DeviceDetector:
2120
"""Singleton class to manage device context."""
21+
2222
_instance = None
2323

2424
def __new__(cls, *args, **kargs):
@@ -57,7 +57,7 @@ def get_vendor(self, vendor_name=None) -> tuple:
5757
return backend.get_vendor_info(vendor_from_env)
5858

5959
vendor_name = self._get_vendor_from_quick_cmd()
60-
if vendor_name :
60+
if vendor_name:
6161
return backend.get_vendor_info(vendor_name)
6262
try:
6363
# Obtaining a vendor_info from the methods provided by torch or triton, but is not currently implemented.
@@ -75,7 +75,7 @@ def _get_vendor_from_quick_cmd(self):
7575
for vendor_name, attr in _VENDOR_TORCH_ATTR.items():
7676
if hasattr(torch_npu, attr):
7777
return vendor_name
78-
except ImportError:
78+
except ImportError:
7979
pass
8080
return None
8181

@@ -85,24 +85,24 @@ def _get_vendor_from_env(self):
8585

8686
def _get_vendor_from_sys(self):
8787
vendor_infos = backend.get_vendor_infos()
88-
88+
8989
def check_vendor(info):
9090
try:
9191
cmd_args = shlex.split(info.device_query_cmd)
9292
result = subprocess.run(cmd_args, capture_output=True, text=True)
9393
return info if result.returncode == 0 else None
9494
except Exception:
9595
return None
96-
97-
with ThreadPoolExecutor() as executor:
96+
97+
with ThreadPoolExecutor() as executor:
9898
futures = {
9999
executor.submit(check_vendor, info): info for info in vendor_infos
100100
}
101101
for future in as_completed(futures):
102102
result = future.result()
103103
if result:
104104
return result
105-
105+
106106
error.device_not_found()
107107

108108
def get_vendor_name(self):

src/flag_gems/runtime/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from enum import Enum
21
import os
2+
from enum import Enum
33

44

55
class vendors(Enum):
@@ -126,4 +126,12 @@ def get_all_vendors(cls) -> dict:
126126
"enflame": "gcu",
127127
}
128128

129-
__all__ = ["vendors", "UNSUPPORT_FP64", "UNSUPPORT_BF16", "UNSUPPORT_INT64", "DEFAULT_STRATEGIES", "OP_KEY_ORDERS", "_VENDOR_TORCH_ATTR"]
129+
__all__ = [
130+
"vendors",
131+
"UNSUPPORT_FP64",
132+
"UNSUPPORT_BF16",
133+
"UNSUPPORT_INT64",
134+
"DEFAULT_STRATEGIES",
135+
"OP_KEY_ORDERS",
136+
"_VENDOR_TORCH_ATTR",
137+
]

src/flag_gems/runtime/configloader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import copy
2-
import os
32
import warnings
43

54
import triton
65

76
from . import backend, common
87
from .backend.device import DeviceDetector
98

9+
1010
class ConfigLoader(object):
1111
_instance = None
1212

@@ -47,7 +47,7 @@ def __init__(self):
4747
self.triton_config_default["num_ldmatrixes"] = 0
4848
self.expand_config_registry = self._build_expand_registry()
4949
self.load_all()
50-
50+
5151
def update_config_from_arch(self):
5252
try:
5353
archEvent = backend.BackendArchEvent()
@@ -76,9 +76,9 @@ def _create_triton_config(self, single_config, current_config):
7676
"num_ctas": current_config["num_ctas"],
7777
}
7878
if self.device.vendor_name == "hygon":
79-
kwargs["num_ldmatrixes"] = current_config["num_ldmatrixes"]
79+
kwargs["num_ldmatrixes"] = current_config["num_ldmatrixes"]
8080
return triton.Config(single_config["META"], **kwargs)
81-
81+
8282
def _build_configs_by_op(self, op_name, ranges, pre_hook=None):
8383
if op_name == "bmm":
8484
return [

0 commit comments

Comments
 (0)