关于#mindspore的gpu版本#的问题,如何解决?

我用gpu版本运行mindspore快速入门的数据集时会爆下面的错误,cpu版本就不会,这是为啥

C:\Users\ZGY\AppData\Local\Programs\Python\Python39\python.exe L:\Mindspore\1\快速入门.py 
Traceback (most recent call last):
  File "L:\Mindspore\1\快速入门.py", line 1, in <module>
    import  mindspore
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\__init__.py", line 18, in <module>
    from mindspore.run_check import run_check
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\__init__.py", line 17, in <module>
    from ._check_version import check_version_and_env_config
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\_check_version.py", line 565, in <module>
    check_version_and_env_config()
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\_check_version.py", line 525, in check_version_and_env_config
    MSContext.get_instance().set_param(ms_ctx_param.device_target,
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\_check_version.py", line 499, in set_env
    env_checker = GPUEnvChecker(library_path)
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\_check_version.py", line 84, in __init__
    self.cuda_lib_path = self._get_lib_path("libcu")
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\run_check\_check_version.py", line 220, in _get_lib_path
    ldd_r = subprocess.Popen(['ldd', self.library_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
[ERROR] PIPELINE(,1c68,?):2023-5-10 20:45:37 [mindspore\ccsrc\pipeline\jit\init.cc:427] pybind11_init__c_expression::<lambda_668b0eb440c03b6a3508b8bc7dd0d0d5>::operator ()] Failed to parse profiler data.RuntimeError: can't register atexit after shutdown

At:
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\threading.py(1407): _register_atexit
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py(101): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\__init__.py(44): __getattr__
  <frozen importlib._bootstrap>(1055): _handle_fromlist
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\callback\_landscape.py(26): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\callback\__init__.py(31): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap>(972): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\model.py(29): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\__init__.py(22): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap>(972): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\callback\ds_callback.py(21): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\callback\__init__.py(18): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\engine\__init__.py(25): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\__init__.py(119): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap>(1066): _handle_fromlist
  C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\__init__.py(19): <module>
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap_external>(850): exec_module
  <frozen importlib._bootstrap>(695): _load_unlocked
  <frozen importlib._bootstrap>(986): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load
  <frozen importlib._bootstrap>(228): _call_with_frames_removed
  <frozen importlib._bootstrap>(972): _find_and_load_unlocked
  <frozen importlib._bootstrap>(1007): _find_and_load

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\__init__.py", line 19, in <module>
    from mindspore import common, dataset, mindrecord, train, log
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\__init__.py", line 119, in <module>
    from .engine import *
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\engine\__init__.py", line 25, in <module>
    from ..callback import DSCallback, WaitedDSCallback
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\callback\__init__.py", line 18, in <module>
    from mindspore.dataset.callback.ds_callback import DSCallback, WaitedDSCallback
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\dataset\callback\ds_callback.py", line 21, in <module>
    from mindspore.train.callback import Callback
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\__init__.py", line 22, in <module>
    from mindspore.train.model import Model
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\model.py", line 33, in <module>
    from mindspore.train.callback import _InternalCallbackParam, RunContext, _CallbackManager, Callback, TimeMonitor
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\callback\__init__.py", line 31, in <module>
    from mindspore.train.callback._landscape import SummaryLandscape
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\site-packages\mindspore\train\callback\_landscape.py", line 26, in <module>
    from concurrent.futures import wait, ALL_COMPLETED, ProcessPoolExecutor
  File "<frozen importlib._bootstrap>", line 1055, in _handle_fromlist
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\__init__.py", line 44, in __getattr__
    from .process import ProcessPoolExecutor as pe
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\concurrent\futures\process.py", line 101, in <module>
    threading._register_atexit(_python_exit)
  File "C:\Users\ZGY\AppData\Local\Programs\Python\Python39\lib\threading.py", line 1407, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

进程已结束,退出代码1


下面是我的代码


import  mindspore
from mindspore import nn
from mindspore.dataset import transforms
from mindspore.dataset import MnistDataset
import mindspore.dataset.vision as vision
from download import download

url = "https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/" \
      "notebook/datasets/MNIST_Data.zip"
path = download(url, "./", kind="zip", replace=True)
# url参数是待下载文件的URL。
# ./参数指定了本地目录,在该目录下文件将被保存。点号(".")表示当前工作目录。
# kind参数指定了要下载文件的格式(在本例中为ZIP格式)。
# replace参数指定是否要覆盖目标目录中同名的已有文件。

train_dataset = MnistDataset('MNIST_Data/train')
test_dataset = MnistDataset('MNIST_Data/test')


def datapipe(dataset, batch_size):
    image_transforms = [
        vision.Rescale(1.0 / 255.0, 0),
        vision.Normalize(mean=(0.1307,), std=(0.3081,)),
        vision.HWC2CHW()
    ]
    label_transform = transforms.TypeCast(mindspore.int32)
    dataset = dataset.map(image_transforms, 'image')
    dataset = dataset.map(label_transform, 'label')
    dataset = dataset.batch(batch_size)
    return dataset


train_dataset = datapipe(train_dataset, 64)
test_dataset = datapipe(test_dataset, 64)

for image, label in test_dataset.create_tuple_iterator():
    print(f"Shape of image [N, C, H, W]: {image.shape} {image.dtype}")
    print(f"Shape of label: {label.shape} {label.dtype}")
    break


class Network(nn.Cell):
    def __init__(self):
        super().__init__()
        self.flatten = nn.Flatten()
        self.dense_relu_sequential = nn.SequentialCell(
            nn.Dense(28 * 28, 512),
            nn.ReLU(),
            nn.Dense(512, 512),
            nn.ReLU(),
            nn.Dense(512, 10)
        )

    def construct(self, x):
        x = self.flatten(x)
        logits = self.dense_relu_sequential(x)
        return logits


model = Network()
print(model)

loss_fn = nn.CrossEntropyLoss()

optimizer = nn.SGD(model.trainable_params(), 1e-2)


def forward_fn(data, label):
    logits = model(data)
    loss = loss_fn(logits, label)
    return loss, logits


grad_fn = mindspore.value_and_grad(forward_fn, None, optimizer.parameters, has_aux=True)


def train_step(data, label):
    (loss, _), grads = grad_fn(data, label)
    optimizer(grads)
    return loss


def train(model, dataset):
    size = dataset.get_dataset_size()
    model.set_train()
    for batch, (data, label) in enumerate(dataset.create_tuple_iterator()):
        loss = train_step(data, label)

        if batch % 100 == 0:
            loss, current = loss.asnumpy(), batch
            print(f"loss: {loss:>7f}  [{current:>3d}/{size:>3d}]")


def test(model, dataset, loss_fn):
    num_batches = dataset.get_dataset_size()
    model.set_train(False)
    total, test_loss, correct = 0, 0, 0
    for data, label in dataset.create_tuple_iterator():
        pred = model(data)
        total += len(data)
        test_loss += loss_fn(pred, label).asnumpy()
        correct += (pred.argmax(1) == label).asnumpy().sum()
    test_loss /= num_batches
    correct /= total
    print(f"Test: \n Accuracy: {(100 * correct):>0.1f}%, Avg loss: {test_loss:>8f} \n")


epochs = 3
for t in range(epochs):
    print(f"Epoch {t + 1}\n-------------------------------")
    train(model, train_dataset)
    test(model, test_dataset, loss_fn)
print("Done!")

print("Done!")

# Save checkpoint
mindspore.save_checkpoint(model, "model.ckpt")
print("Saved Model to model.ckpt")

如果cpu版本可以正常执行,没问题的话,看一下是不是GPU版本也成功安装了。一般情况下,是可以共存的。否则就是GPU版本没有成功安装。