1800亿参数,性能碾压Llama 2,世界最强开源大模型Falcon 180B发布
今年 5 月,TII(阿联酋阿布扎比技术创新研究所)推出了号称是 “史上最强的开源大语言模型”——Falcon(猎鹰)。虽然 Falcon 的参数比 LLaMA 小,但性能却更加强大。
硬件要求
类型 | 种类 | 最低要求 | 配置示例 | |
---|---|---|---|---|
Falcon 180B | Training | Full fine-tuning | 5120GB | 8x 8x A100 80GB |
Falcon 180B | Training | LoRA with ZeRO-3 | 1280GB | 2x 8x A100 80GB |
Falcon 180B | Training | QLoRA | 160GB | 2x A100 80GB |
Falcon 180B | Inference | BF16/FP16 | 640GB | 8x A100 80GB |
Falcon 180B | Inference | GPTQ/int4 | 320GB | 8x A100 40GB |
Prompt 格式
System: Add an optional system prompt here
User: This is the user input
Falcon: This is what the model generates
User: This might be a second turn input
Falcon: and so on
Transformers
pip install --upgrade transformers
huggingface-cli login
bfloat16
中使用基础模型的方法。Falcon 180B 是一个大型模型,所以请注意它的硬件要求(硬件要求如上所示)。from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import torch
model_id = "tiiuae/falcon-180B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
prompt = "My name is Pedro, I live in"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
output = model.generate(
input_ids=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
do_sample=True,
temperature=0.6,
top_p=0.9,
max_new_tokens=50,
)
output = output[0].to("cpu")
print(tokenizer.decode(output)
这可能会产生如下输出结果:
My name is Pedro, I live in Portugal and I am 25 years old. I am a graphic designer, but I am also passionate about photography and video.
I love to travel and I am always looking for new adventures. I love to meet new people and explore new places.
bfloat16
几乎没有差别!这对推理来说是个好消息,因为你可以放心地使用量化版本来降低硬件要求。请记住,在 8 位版本进行推理要比 4 位版本快得多。要使用量化,你需要安装 “bitsandbytes” 库,并在加载模型时启用相应的标志:model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
**load_in_8bit=True,**
device_map="auto",
)
format_prompt
函数:def format_prompt(message, history, system_prompt):
prompt = ""
if system_prompt:
prompt += f"System: {system_prompt}\n"
for user_prompt, bot_response in history:
prompt += f"User: {user_prompt}\n"
prompt += f"Falcon: {bot_response}\n"
prompt += f"User: {message}\nFalcon:"
return prompt
User:
和 Falcon:
分隔符。我们将它们连接在一起,形成一个包含整个对话历史的提示。这样就可以提供一个系统提示来调整生成风格。往期推荐
点这里 ↓↓↓ 记得 关注✔ 标星⭐ 哦
微信扫码关注该文公众号作者
戳这里提交新闻线索和高质量文章给我们。
来源: qq
点击查看作者最近其他文章