【问题标题】:gensim LdaMulticore not multiprocessing?gensim LdaMulticore 不是多处理?
【发布时间】:2016-02-29 00:29:36
【问题描述】:

当我在一台 12 核的机器上运行 gensim 的 LdaMulticore 模型时,使用:

lda = LdaMulticore(corpus, num_topics=64, workers=10)

我收到一条日志消息,上面写着

using serial LDA version on this node  

几行之后,我看到另一条日志消息显示

training LDA model using 10 processes

当我运行 top 时,我看到 11 个 python 进程已生成,但 9 个正在休眠,即只有一名工人处于活动状态。该机器有 24 个核心,无论如何都不会被压垮。为什么 LdaMulticore 不以并行模式运行?

【问题讨论】:

标签: python multiprocessing lda gensim


【解决方案1】:

首先,确保您have installed a fast BLAS library,因为大部分耗时的工作都是在线性代数的低级例程中完成的。

在我的机器上,gensim.models.ldamodel.LdaMulticore 可以在训练期间用 workers=4 耗尽所有 20 个 cpu 内核。设置比这更大的工人并没有加快培训速度。 One reason might be the corpus iterator is too slow to use LdaMulticore effectively.

您可以尝试使用ShardedCorpus 来序列化和替换corpus,这样读/写应该会快得多。此外,简单地压缩你的大 .mm 文件,这样它占用更少的空间(=更少的 I/O)也可能会有所帮助。例如,

mm = gensim.corpora.MmCorpus(bz2.BZ2File('enwiki-latest-pages-articles_tfidf.mm.bz2'))
lda = gensim.models.ldamulticore.LdaMulticore(corpus=mm, id2word=id2word, num_topics=100, workers=4)

【讨论】:

  • 我的问题确实是因为加载语料库的 I/O 瓶颈。我想使用ShardedCorpus 可能会有所帮助——我下次会尝试。对我来说,只需先将整个语料库预加载到内存中(机器几乎有 1 T 内存),就解决了这个问题。预加载比按需加载文档快方式。下次我会试试你的其他建议!
  • corpora.MmCorpus('some_corpus.mm') 不会将语料库预加载到内存中吗?我也陷入了这个问题,记录器说using serial LDA version on this node,然后什么也没有……
  • 遇到了类似的问题,LdaMulticore 在一个环境中工作,而不是在另一个环境中工作,比较了软件包,发现删除 scikit-learn(带有 llvm-openmp - 可能的问题来源)解决了它。
  • 这是旧的,但可以确认冲突也是我的问题。创建一个没有 scikitlearn 的 conda 环境解决了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 2022-01-03
  • 2021-01-10
  • 1970-01-01
  • 2013-03-18
相关资源
最近更新 更多