mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 17:11:21 +08:00
polish code with new pre-commit rule (#2923)
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user