Transformers documentation

FLAN-UL2

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

该模型于 2023-06-20 贡献至 Hugging Face Transformers。

FLAN-UL2

概述

Flan-UL2 是一个基于 T5 架构的编码器-解码器模型。它使用了去年早些时候发布的 UL2 模型的相同配置。 该模型使用“Flan”提示调优和数据集集合进行了微调。与 Flan-T5 类似,可以直接使用 FLAN-UL2 的权重,而无需对模型进行微调:

根据原始博客,主要改进如下:

  • 原始的 UL2 模型仅使用 512 的 receptive field 进行训练,这使得它在 N 较大的 N-shot prompting 场景中并非理想选择。
  • Flan-UL2 检查点使用 2048 的感受野,使其更适用于少样本上下文学习。
  • 原始的 UL2 模型也包含模式切换 token,这对于获得良好的性能几乎是必需的。然而,这些 token 使用起来有些繁琐,因为在推理或微调过程中通常需要对其进行一些更改。在本次更新/变更中,我们使用较小的 batch 继续训练 UL2 20B 额外 100k 步,以“遗忘”模式 token,然后再应用 Flan 指令微调。这个 Flan-UL2 checkpoint 不再需要模式 token。 Google 发布了以下变体:

原始检查点可以在此处找到。

在低资源设备上运行

该模型相当庞大(半精度下约 40GB),因此如果您只是想运行该模型,请确保以 8bit 加载模型,并使用 device_map="auto" 以避免出现 OOM 问题!

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, BitsAndBytesConfig


model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-ul2", quantization_config=BitsAndBytesConfig(load_in_8bit=True), device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("google/flan-ul2")

inputs = tokenizer("A step by step recipe to make bolognese pasta:", return_tensors="pt").to(model.device)
outputs = model.generate(**inputs)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
['In a large skillet, brown the ground beef and onion over medium heat. Add the garlic']

请参阅 T5 的文档页面 以获取 API 参考、技巧、代码示例和笔记本。

Update on GitHub