You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpaCy结合classy classification训练文本分类器无法调用GPU问题

使用SpaCy + classy classification训练文本分类器时GPU未调用的问题

我使用SpaCy搭配classy classification训练文本分类器,但训练过程中模型未调用GPU,导致微调耗时过长。

GPU硬件与驱动信息

$ nvidia-smi 
Mon Apr 22 09:41:13 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.06              Driver Version: 545.29.06    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce GTX 1650 Ti     Off | 00000000:01:00.0 Off |                  N/A |
| N/A   62C    P8               1W /  50W |      6MiB /  4096MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      2154      G   /usr/bin/gnome-shell                          1MiB |
+---------------------------------------------------------------------------------------+

GPU已被各计算库正常识别

CuPy

import cupy as cp
x = cp.array([1, 2, 3])
print(x)

# 输出:
# [1 2 3]

PyTorch与TensorFlow

import torch
print(torch.__version__)
print(torch.version.cuda)

import tensorflow as tf
print(tf.__version__)
print(tf.test.gpu_device_name())

# 输出:
# 12.1
# 2.15.0
# /device:GPU:0

已尝试的操作

  • 强制SpaCy使用GPU:
spacy.require_gpu()
  • 指定优先使用GPU设备0:
spacy.prefer_gpu(0)
  • 在classy_classification配置中指定GPU设备:
nlp.add_pipe(
 'classy_classification', 
 config={
      'data'    : train_samples,
      'model'   : 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2',
      'device'  : 'gpu',
      'verbose' : True
    }
)

内容的提问来源于stack exchange,提问作者user24558711

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 11:20:57