目标是以 FP16 混合精度运行 python -m spacy train
,以便在有限的 VRAM 中使用大型转换器(roberta-large
、albert-large
等) (RTX 2080ti 11 GB)。
用于训练的新 Spacy3 project.yml approach 直接使用通过 Huggingface-transformers models 加载的 Spacy-transformers v1.0。只需添加 --fp16
标志 (as described here),即可以混合精度运行 Huggingface 模型。
spacy 配置是使用 python -m spacy init config --lang en --pipeline ner --optimize efficiency --gpu -F default.cfg
生成的,并由 python -m spacy init fill-config default.cfg config.cfg --diff
检查是否完整。然而没有找到 FP16/混合精度。
使用 init-config
中已更改的 project.yml
的 spaCy Project: Named Entity Recognition (WikiNER) 以使用 GPU 和转换器(默认为 roberta-base
):
commands:
-
name: init-config
help: "Generate a transformer English NER config"
script:
- "python -m spacy init config --lang en --pipeline ner --gpu -F --optimize efficiency -C configs/${vars.config}.cfg"
--fp16
添加到 python -m spacy project run
--fp16
添加到 python -m spacy train
fp16 = true
) 中将 default.cfg
添加到 [components.transformer], [components.transformer.model], [training], [initialize]
逻辑 transformers
在 FP16 中运行如下:
from transformers import TrainingArguments
TrainingArguments(..., fp16=True, ...)
- spacy 3.0.3
- spacy-transformers 1.0.1
- transformers 4.2.2
- torch 1.6.0+cu101