使用 spacy v3 我应该在配置文件中更改哪个参数来解决 CUDA 内存不足问题? batch_size vs max_length vs batcher.size

问题描述

使用 spacy v3,我尝试使用 camemBert 训练分类器,但遇到了 CUDA out of memory 问题。 为了解决这个问题,我读到我应该减少批量大小,但我很困惑我应该改变哪个参数:

  • [nlp] 批量大小
  • [components.transformer] max_batch_items
  • [corpora.train 或 dev] max_length
  • [trainning.batcher] 大小
  • [trainning.batcher] 缓冲区

我试图了解每个参数之间的区别:

  1. [nlp] batch_size

管道和评估的认批量大小。认为 1000。

这些功能是否用于培训/评估过程?
快速启动小部件(https://spacy.io/usage/training#quickstart)中,为什么根据硬件的值不同? cpu 为 1000,GPU 为 128。
在训练过程中,如果这个值低,评估会不会变慢?

  1. [components.transformer] max_batch_items

填充批次的最大大小。认为 4096。

根据警告信息:Token indices sequence length is longer than the specified maximum sequence length for this model (556 > 512). Running this sequence through the model will result in indexing errors 解释here (https://github.com/explosion/spaCy/issues/6939), Camembert 模型指定的最大序列长度为 512。

参数 max_batch_item 是否重载到这个值?我应该将值更改为 512 吗?

  1. [corpora.train 或 dev] max_length

在我的理解中,这个值应该等于或低于最大序列长度。 在快速入门小部件中,此值对于训练集设置为 500,对于开发集设置为 0。 如果设置为0,是否会过载到transformer模型的最大序列长度?

  1. [trainning.batcher] spacy.batch_by_padded.v1 的大小

批量序列的最大填充大小。也可以是引用时间表的块,例如复合。

如果我不使用复合,这个参数与 max_lentgh 有什么不同?

这是我的配置文件的一些部分

[nlp]
lang = "fr"
pipeline = ["transformer","textcat"]
# Default batch size to use with nlp.pipe and nlp.evaluate
batch_size = 256
...

[components.transformer]
factory = "transformer"
# Maximum size of a padded batch. Defaults to 4096.
max_batch_items = 4096
...

[corpora.dev]
@readers = "spacy.Corpus.v1"
path = ${paths.dev}
# Limitations on training document length
max_length = 512
...

[training.batcher]
@batchers = "spacy.batch_by_padded.v1"
discard_oversize = true
# The largest padded size to batch sequences into. Can also be a block referencing a schedule,e.g. compounding.
size = 500
# The number of sequences to accumulate before sorting by length. A larger buffer will result in more even sizing,but if the buffer is very large,the iteration order will be less random,which can result in suboptimal training.
buffer = 128
get_length = null
...

解决方法

您的 GPU 有多少内存?

在 Spacy 2.x 下,我能够使用 6GB GPU。但是(如果我没记错的话)Spacy 3 文档建议使用 10-12 GB。 我尝试了各种参数,但我的 GPU 6GB 内存主要被 PyTorch 负载耗尽,因此无论 batch_size 调整如何,我很快就会“耗尽 GPU 内存”。这不仅适用于转换器,还适用于普通的 NR EntityRecognizer - Spacy 3 只是简单地为 GPU 加载了比以前的 Spacy 2 多得多的“东西”。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...