pytorch - 简单的 MultiGPU 在推理过程中使用 huggingface

标签 pytorch huggingface-transformers

我有两个 GPU。

如何将它们用于拥抱脸管道的推理

Huggingface 文档似乎说我们可以轻松地将 DataParallel 类与 huggingface 模型一起使用,但我没有看到任何示例。

例如使用 pytorch,只需执行以下操作就非常容易:

net = torch.nn.DataParallel(model, device_ids=[0, 1, 2])
output = net(input_var)  # input_var can be on any device, including CPU 

是否有与 huggingface 等价的东西?

最佳答案

我发现管道不可能,所以:

两种方式:

  • 用 huggingface 中的 Trainer 对象来做,它也支持推理,但不是最优的。
  • 使用多处理标准库中的队列,但这会产生大量样板代码

关于pytorch - 简单的 MultiGPU 在推理过程中使用 huggingface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71417355/

相关文章:

python - PyTorch:.movedim() 对比 .moveaxis() 对比 .permute()

python - PyTorch 数据加载器显示字符串数据集的奇怪行为

tensorflow - 微调 Blenderbot

python - 从 BERT 获取嵌入查找结果

python - conda list 在安装 PyTortch 后返回运行时错误 Path not Found

python - PyTorch 数据集类的子类找不到数据集文件

python - 如何在 pytorch 中实现对抗性示例?

python - 训练新的 AutoTokenizer 拥抱脸部

huggingface-transformers - 如何解码 TFGPT2Model 的输出序列?

language-model - 使用域文本预训练 BERT/RoBERTa 语言模型,预计需要多长时间?哪个更快?