polish code with new pre-commit rule (#2923)

This commit is contained in:
Zero Rains
2025-07-19 23:19:27 +08:00
committed by GitHub
parent b8676d71a8
commit 25698d56d1
424 changed files with 14307 additions and 13518 deletions
+5 -9
View File
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
import importlib
import inspect
import os
@@ -28,26 +29,21 @@ def _find_py_files(root_dir):
rel_path = py_file.relative_to(root_dir)
if "__init__" in str(py_file):
continue
dotted_path = str(rel_path).replace("/", ".").replace("\\",
".").replace(
".py", "")
dotted_path = str(rel_path).replace("/", ".").replace("\\", ".").replace(".py", "")
py_files.append(dotted_path)
return py_files
def auto_models_registry(dir_path,
register_path="fastdeploy.model_executor.models"):
def auto_models_registry(dir_path, register_path="fastdeploy.model_executor.models"):
"""
auto registry all models in this folder
"""
for module_file in _find_py_files(dir_path):
try:
module = importlib.import_module(f'{register_path}.{module_file}')
module = importlib.import_module(f"{register_path}.{module_file}")
for attr_name in dir(module):
attr = getattr(module, attr_name)
if inspect.isclass(attr) and issubclass(
attr,
ModelForCasualLM) and attr is not ModelForCasualLM:
if inspect.isclass(attr) and issubclass(attr, ModelForCasualLM) and attr is not ModelForCasualLM:
ModelRegistry.register(attr)
except ImportError:
raise ImportError(f"{module_file=} import error")