modelscope icon indicating copy to clipboard operation
modelscope copied to clipboard

pipeline 在有GPU的情况下,无法指定使用CPU,是我的用法不对吗?

Open liuzhuangyuan opened this issue 1 year ago • 2 comments

描述错误

class CartoonModelscape:
    def __init__(self, model="damo/cv_unet_person-image-cartoon_compound-models", model_revision=None):
        if model_revision:
            self.cartoon = pipeline(Tasks.image_portrait_stylization,
                                    model=model,
                                    model_revision=model_revision,
                                    device='cpu')
        else:
            self.cartoon = pipeline(Tasks.image_portrait_stylization,
                                    model=model,
                                    device='cpu')

在对pipeline指定device='cpu'时不生效,即便是在 import modelscope 之前使用了 os.environ["CUDA_VISIBLE_DEVICES"] = "-1" 也没有生效。

就普通的参考示例使用,没有对modelscope进行修改, 操作系统:windows 10 cpu:i9-10900k gpu:3090

2024-01-10 19:32:45,842 - modelscope - INFO - PyTorch version 1.13.1+cu117 Found.
2024-01-10 19:32:45,850 - modelscope - INFO - TensorFlow version 2.8.0 Found.
2024-01-10 19:32:45,842 - modelscope - INFO - PyTorch version 1.13.1+cu117 Found.
2024-01-10 19:32:45,850 - modelscope - INFO - TensorFlow version 2.8.0 Found.
2024-01-10 19:32:45,850 - modelscope - INFO - Loading ast index from C:\Users\admin\.cache\modelscope\ast_indexer
2024-01-10 19:32:46,258 - modelscope - INFO - Loading done! Current index file version is 1.10.0, with md5 2b8b9c3d786cd3e3515b41558be947fa and a total number of 946 components indexed
******************************************************************
IS_DEBUG: True
VERSION: v2.0 2024.01.10
******************************************************************
2024-01-10 19:32:52,880 - modelscope - INFO - initiate model from damo/cv_unet_person-image-cartoon_compound-models
2024-01-10 19:32:52,880 - modelscope - INFO - initiate model from location damo/cv_unet_person-image-cartoon_compound-models.
2024-01-10 19:32:52,896 - modelscope - WARNING - No preprocessor field found in cfg.
2024-01-10 19:32:52,896 - modelscope - WARNING - No val key and type key found in preprocessor domain of configuration.json file.
2024-01-10 19:32:52,896 - modelscope - WARNING - Cannot find available config to build preprocessor at mode inference, current config: {'model_dir': 'damo/cv_unet_person-image-cartoon_compound-models'}. trying to build by task and model information.
2024-01-10 19:32:52,896 - modelscope - WARNING - Find task: image-portrait-stylization, model type: None. Insufficient information to build preprocessor, skip building preprocessor
2024-01-10 19:32:52.901698: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-01-10 19:32:53.277106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4915 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:01:00.0, compute capability: 8.6
2024-01-10 19:32:53.394081: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4915 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:01:00.0, compute capability: 8.6
2024-01-10 19:32:53.643138: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4915 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:01:00.0, compute capability: 8.6
2024-01-10 19:32:53,642 - modelscope - INFO - loading model from damo/cv_unet_person-image-cartoon_compound-models\cartoon_h.pb
WARNING:tensorflow:From E:\PythonVenv\CartoonModelscape\lib\site-packages\modelscope\pipelines\cv\image_cartoon_pipeline.py:62: FastGFile.__init__ (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
2024-01-10 19:32:53,687 - modelscope - INFO - load model damo/cv_unet_person-image-cartoon_compound-models\cartoon_h.pb done.
2024-01-10 19:32:53.688680: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4915 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:01:00.0, compute capability: 8.6
2024-01-10 19:32:53,688 - modelscope - INFO - loading model from damo/cv_unet_person-image-cartoon_compound-models\cartoon_bg.pb
2024-01-10 19:32:53,737 - modelscope - INFO - load model damo/cv_unet_person-image-cartoon_compound-models\cartoon_bg.pb done.
2024-01-10 19:32:54.774467: I tensorflow/stream_executor/cuda/cuda_dnn.cc:368] Loaded cuDNN version 8500
E:\PythonVenv\CartoonModelscape\lib\site-packages\modelscope\models\cv\cartoon\mtcnn_pytorch\src\matlab_cp2tform.py:86: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`.
  r, _, _, _ = lstsq(X, U)
done.

liuzhuangyuan avatar Jan 10 '24 11:01 liuzhuangyuan

可以尝试debug看看,是否有按is_gpu_available()指定device。极少数模型有这种情况。

slin000111 avatar Jan 10 '24 12:01 slin000111

我菜狗,没找到问题原因,不过我通过一下方式可以切换为cpu,目前我的功能逻辑可以这么操作,不过我还是期望能在pipeline里面设置生效。

os.environ["CUDA_VISIBLE_DEVICES"] = "-1,"

import tensorflow as tf
# TensorFlow 配置:在某些情况下,TensorFlow 可能会使用自定义的 GPU 配置,覆盖了环境变量的设置。
# 可以尝试在 TensorFlow 导入之前设置 TensorFlow 的 GPU 配置。
# 设置 TensorFlow 的 GPU 配置
gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_visible_devices(gpus, 'GPU')

liuzhuangyuan avatar Jan 11 '24 02:01 liuzhuangyuan

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar May 30 '24 01:05 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jun 04 '24 01:06 github-actions[bot]