From a4de8c9e132d7524d112a99adc9d68d96978b6a5 Mon Sep 17 00:00:00 2001 From: zyw_hw Date: Tue, 4 Mar 2025 21:25:48 +0800 Subject: [PATCH] fix security questions --- mindformers/models/auto/processing_auto.py | 14 ++++++------- mindformers/utils/cann_cores_utils.py | 23 +++------------------- setup.py | 2 +- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/mindformers/models/auto/processing_auto.py b/mindformers/models/auto/processing_auto.py index 9876ecb9a..53b44f551 100644 --- a/mindformers/models/auto/processing_auto.py +++ b/mindformers/models/auto/processing_auto.py @@ -373,14 +373,12 @@ class AutoProcessor: return AutoImageProcessor.from_pretrained( pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs ) - except Exception: # pylint: disable=W0703 - pass - - raise ValueError( - f"Unrecognized processing class in {pretrained_model_name_or_path}. Can't instantiate a processor, a " - "tokenizer, an image processor for this model. Make sure the repository contains " - "the files of at least one of those processing classes." - ) + except Exception as e: # pylint: disable=W0703 + raise ValueError( + f"Unrecognized processing class in {pretrained_model_name_or_path}. " + f"Can't instantiate a processor, a tokenizer, an image processor for this model. " + f"Make sure the repository contains the files of at least one of those processing classes." + ) from e @staticmethod def register(config_class, processor_class, exist_ok=False): diff --git a/mindformers/utils/cann_cores_utils.py b/mindformers/utils/cann_cores_utils.py index 2ac5820ad..cd9032c9d 100644 --- a/mindformers/utils/cann_cores_utils.py +++ b/mindformers/utils/cann_cores_utils.py @@ -21,6 +21,7 @@ import os import psutil from mindformers.utils.bit_array import BitArray +from mindformers.tools.logger import logger def get_cann_workqueue_cores(device_id: int) -> list: @@ -73,24 +74,6 @@ def mask_to_str(mask: BitArray) -> str: return mask_str -def execute_cmd(cmd: str, fake: bool = True): - """ - execute shell command - - Args: - cmd (`str`): - The command need to execute. - fake (`bool`, *optional*, defaults to `False`): - If fake execute is True, then print command instead to execute. - - Returns: - NA. - """ - if fake: - print(cmd) - return - - def binding_cann_workqueue(device_num: int, core_num_per_workqueue: int, separate_device_cores: bool): """ binding cann workqueue cores @@ -126,7 +109,7 @@ def binding_cann_workqueue(device_num: int, core_num_per_workqueue: int, separat if separate_device_cores: mask_str = mask_to_str(mask) bind_cann_core_cmd = f"echo \"{mask_str}\" > {cann_workqueue_config_path}" - execute_cmd(bind_cann_core_cmd) + logger.info(bind_cann_core_cmd) if not separate_device_cores: device_core_mask_str = mask_to_str(device_core_mask) @@ -134,4 +117,4 @@ def binding_cann_workqueue(device_num: int, core_num_per_workqueue: int, separat for i in range(device_num): cann_workqueue_config_path = f"/sys/devices/virtual/workqueue/dev{i}_sq_send_wq/cpumask" bind_cann_core_cmd = f"echo \"{device_core_mask_str}\" > {cann_workqueue_config_path}" - execute_cmd(bind_cann_core_cmd) + logger.info(bind_cann_core_cmd) diff --git a/setup.py b/setup.py index 6c2ca1c93..a5385e96c 100644 --- a/setup.py +++ b/setup.py @@ -78,7 +78,7 @@ def update_permissions(path): for dirpath, dirnames, filenames in os.walk(path): for dirname in dirnames: dir_fullpath = os.path.join(dirpath, dirname) - os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP) + os.chmod(dir_fullpath, stat.S_IREAD | stat.S_IEXEC) for filename in filenames: file_fullpath = os.path.join(dirpath, filename) os.chmod(file_fullpath, stat.S_IREAD) -- Gitee