【问题标题】:GPU on apply function colabGPU 上的应用功能 colab
【发布时间】:2021-11-11 06:47:03
【问题描述】:

我在我的代码上使用了这个应用函数:

def entities_extraction(text):
    doc = nlp(text)
    entities= [ent.text for sentence in doc.sentences for ent in sentence.entities if ent.type in {"PERSON", "ORG", "GPE", "NORP", "FAC", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "MISC"}]
    return entities

df["entities"] = df['text'].progress_apply(lambda x: entities_extraction(x))

问题是,目前太慢了(需要将近12个小时)

所以我尝试修改它以使用colab gpu:

@cuda.jit
def entities_extraction(text):
    doc = nlp(text)
    entities= [ent.text for sentence in doc.sentences for ent in sentence.entities if ent.type in {"PERSON", "ORG", "GPE", "NORP", "FAC", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "MISC"}]
    return entities

但我收到此错误:

ValueError: 
Kernel launch configuration was not specified. Use the syntax:

kernel_function[blockspergrid, threadsperblock](arg0, arg1, ..., argn)

See https://numba.pydata.org/numba-doc/latest/cuda/kernels.html#kernel-invocation for help.

您知道如何解决它,或者您在应用函数上有更好的 gpu 实现吗?

对不起,如果我犯了很多错误,我对 gpu 的论点是新的,以获得更快的代码。 感谢您的帮助!

【问题讨论】:

  • nlp 函数是取自 spaCy 还是其他?
  • 取自 Stanza
  • 你不能使用 Numba cuda 内核来做你想做的事情。 GPU 不支持 entities_extraction 函数中的任何内容

标签: python cuda gpu google-colaboratory stanford-nlp


【解决方案1】:

您应该编写 cuda.jit 装饰器期望的代码,如 link 所示,或者您可以尝试使用 cuDF.apply。但是,我不确定 cuDF 是否支持您在 lambda 中的函数。

或者,您可以将 Stanza Pipeline APIuse_gpu=True 参数一起使用。请参阅基本示例部分,您应该注意其中的注释。

【讨论】:

  • 问题是 cuDF 在 colab 中不可用,当我尝试安装它时出现此错误:错误:cudf 构建轮失败,构建 cudf 失败
  • @Radix 我认为您可以使用 Stanza Pipeline,而不是在 Google Colab 中构建 cuDF。
猜你喜欢
  • 2021-08-13
  • 2020-12-04
  • 1970-01-01
  • 2021-08-07
  • 2021-05-15
  • 1970-01-01
  • 2015-01-10
  • 2019-11-23
相关资源
最近更新 更多