在 Kaggle 平台使用 PaddlePaddle 进行深度学习训练时,可能会遇到以下错误:

100%|██████████| 151272/151272 [00:23<00:00, 6399.98it/s] 
/opt/conda/lib/python3.10/site-packages/paddle/fluid/dygraph/layers.py:1652: UserWarning: Skip loading for fc.weight. fc.weight receives a shape [2048, 1000], but the expected shape is [2048, 12].
  warnings.warn(('Skip loading for {}. '.format(key) + str(err)))
/opt/conda/lib/python3.10/site-packages/paddle/fluid/dygraph/layers.py:1652: UserWarning: Skip loading for fc.bias. fc.bias receives a shape [1000], but the expected shape is [12].
  warnings.warn(('Skip loading for {}. '.format(key) + str(err)))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[11], line 16
     13 loss_fn = paddle.nn.CrossEntropyLoss()
     15 # 设置gpu环境
---> 16 paddle.set_device('gpu:0')
     18 # 整体训练流程
     19 for epoch_id in range(15):

File /opt/conda/lib/python3.10/site-packages/paddle/device/__init__.py:316, in set_device(device)
    294 def set_device(device):
    295     '''
    296     Paddle supports running calculations on various types of devices, including CPU, GPU, XPU, NPU, MLU and IPU.
    297     They are represented by string identifiers. This function can specify the global device
   (...)
    314         data = paddle.stack([x1,x2], axis=1)
    315     '''
--> 316     place = _convert_to_place(device)
    317     framework._set_expected_place(place)
    318     return place

File /opt/conda/lib/python3.10/site-packages/paddle/device/__init__.py:257, in _convert_to_place(device)
    255 if avaliable_gpu_device:
    256     if not core.is_compiled_with_cuda():
--> 257         raise ValueError(
    258             'The device should not be {}, since PaddlePaddle is '
    259             'not compiled with CUDA'.format(avaliable_gpu_device))
    260     device_info_list = device.split(':', 1)
    261     device_id = device_info_list[1]

ValueError: The device should not be <re.Match object; span=(0, 5), match='gpu:0'>, since PaddlePaddle is not compiled with CUDA

这个错误信息表明,您在 Kaggle 平台上尝试使用 GPU 进行训练,但 PaddlePaddle 并没有被编译成支持 CUDA 的版本。

原因:

Kaggle 平台提供的环境中没有 CUDA 的驱动和运行时,因此您无法直接在 Kaggle 上编译 CUDA。

解决方法:

  • 本地安装 CUDA: 您可以尝试在本地机器上安装 CUDA,并使用 GPU 进行训练。
  • 使用 CPU 进行训练: 如果您无法在本地机器上安装 CUDA,可以在 Kaggle 平台上使用 CPU 进行训练。

在 Kaggle 平台上使用 CPU 进行训练的步骤:

  1. 修改代码: 在您的源代码中,将 paddle.set_device('gpu:0') 修改为 paddle.set_device('cpu')
# ...
# 设置 CPU 环境
paddle.set_device('cpu')
# ...
  1. 运行代码: 运行您的代码,PaddlePaddle 会自动使用 CPU 进行训练。

注意: 使用 CPU 进行训练可能会比使用 GPU 速度慢,但仍然可以获得不错的训练效果。

希望以上信息对您有所帮助!

Kaggle 平台 PaddlePaddle 训练错误:无法使用 GPU,如何解决?

原文地址: https://www.cveoy.top/t/topic/oHHW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录