事情是这样的,本月初,一位 mattshumer 的小伙对外宣称基于 Llama3.1 训练了一个 70B 的模型,号称解决了GPT和Claude都无法解决的🍓数“R”的问题,并且该模型比现存的闭源模型都强。
于是,就像上次大学生一样,又招来了大神们的关注。发现他发布的模型并不是用所谓的 Llama 3.1
config.json
{
"_name_or_path": "meta-llama/Meta-Llama-3-70B-Instruct",
"architectures": [
"LlamaForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 128000,
"eos_token_id": 128009,
"hidden_act": "silu",
"hidden_size": 8192,
"initializer_range": 0.02,
"intermediate_size": 28672,
"max_position_embeddings": 8192,
"model_type": "llama",
"num_attention_heads": 64,
"num_hidden_layers": 80,
"num_key_value_heads": 8,
"pretraining_tp": 1,
"rms_norm_eps": 1e-05,
"rope_scaling": null,
"rope_theta": 500000.0,
"tie_word_embeddings": false,
"torch_dtype": "float32",
"transformers_version": "4.40.0",
"use_cache": true,
"vocab_size": 128262
}
当然这个问题还不是很大,但是随着越来越多的大神使用提示词攻击和反提示词工程,渐渐发现他给出的 Free API 貌似有点不对劲。
发图作者表示:“Reflection API "是一个带有提示符的 sonnet 3.5 封装程序。目前,他们正在通过过滤掉 “claude ”字符串来伪装它。
在社区讨论后不久,开发者立刻修改了,移除了过滤机制,但是模型本身仍然是Claude 3.5 Sonnet。
如此高度一致的回答。。。
目前 Huggingface 的 该模型 Community 出现了许多声讨之声。谁让他还吹自己能训练 405B 的大模型。
喝,这就是开源。小集市又不是时尚芭莎,没点暴脾气能叫开发者🙂
当然并不是所有人都用 Llama 3.1 会“滥竽充数”的,也有其他公司和机构尝试通过 Llama 3.1 开发属于自己的 LLM/VLM。
THUDM/LongCite-llama3.1-8b
LongCite-llama3.1-8b 以 Meta-Llama-3.1-8B 为基础进行训练,能够在长语境问题解答中生成细粒度引文。该模型支持最大 128K 词组的上下文窗口。
transforemrs>=4.43.0
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained('THUDM/LongCite-llama3.1-8b', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained('THUDM/LongCite-llama3.1-8b', torch_dtype=torch.bfloat16, trust_remote_code=True, device_map='auto')
context = '''
W. Russell Todd, 94, United States Army general (b. 1928). February 13. Tim Aymar, 59, heavy metal singer (Pharaoh) (b. 1963). Marshall \"Eddie\" Conway, 76, Black Panther Party leader (b. 1946). Roger Bonk, 78, football player (North Dakota Fighting Sioux, Winnipeg Blue Bombers) (b. 1944). Conrad Dobler, 72, football player (St. Louis Cardinals, New Orleans Saints, Buffalo Bills) (b. 1950). Brian DuBois, 55, baseball player (Detroit Tigers) (b. 1967). Robert Geddes, 99, architect, dean of the Princeton University School of Architecture (1965–1982) (b. 1923). Tom Luddy, 79, film producer (Barfly, The Secret Garden), co-founder of the Telluride Film Festival (b. 1943). David Singmaster, 84, mathematician (b. 1938).
'''
query = "What was Robert Geddes' profession?"
result = model.query_longcite(context, query, tokenizer=tokenizer, max_input_length=128000, max_new_tokens=1024)
print("Answer:\n{}\n".format(result['answer']))
print("Statement with citations:\n{}\n".format(
json.dumps(result['statements_with_citations'], indent=2, ensure_ascii=False)))
print("Context (divided into sentences):\n{}\n".format(result['splited_context']))
Skywork/Skywork-Reward-Llama-3.1-8B
Skywork-Reward-Gemma-2-27B 和 Skywork-Reward-Llama-3.1-8B 是分别建立在 gemma-2-27b-it 和 Meta-Llama-3.1-8B-Instruct 架构上的两个高级奖励模型。这两个模型都是使用 Skywork 奖励数据集进行训练的,该数据集仅包含 8 万个来自公开数据的高质量偏好对。
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
# Load model and tokenizer
device = "cuda:0"
model_name = "Skywork/Skywork-Reward-Llama-3.1-8B"
rm = AutoModelForSequenceClassification.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map=device,
attn_implementation="flash_attention_2",
num_labels=1,
)
rm_tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "Jane has 12 apples. She gives 4 apples to her friend Mark, then buys 1 more apple, and finally splits all her apples equally among herself and her 2 siblings. How many apples does each person get?"
response1 = "1. Jane starts with 12 apples and gives 4 to Mark. 12 - 4 = 8. Jane now has 8 apples.\n2. Jane buys 1 more apple. 8 + 1 = 9. Jane now has 9 apples.\n3. Jane splits the 9 apples equally among herself and her 2 siblings (3 people in total). 9 ÷ 3 = 3 apples each. Each person gets 3 apples."
response2 = "1. Jane starts with 12 apples and gives 4 to Mark. 12 - 4 = 8. Jane now has 8 apples.\n2. Jane buys 1 more apple. 8 + 1 = 9. Jane now has 9 apples.\n3. Jane splits the 9 apples equally among her 2 siblings (2 people in total). 9 ÷ 2 = 4.5 apples each. Each person gets 4 apples."
conv1 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response1}]
conv2 = [{"role": "user", "content": prompt}, {"role": "assistant", "content": response2}]
# Format and tokenize the conversations
conv1_formatted = rm_tokenizer.apply_chat_template(conv1, tokenize=False)
conv2_formatted = rm_tokenizer.apply_chat_template(conv2, tokenize=False)
conv1_tokenized = rm_tokenizer(conv1_formatted, return_tensors="pt").to(device)
conv2_tokenized = rm_tokenizer(conv2_formatted, return_tensors="pt").to(device)
# Get the reward scores
with torch.no_grad():
score1 = rm(**conv1_tokenized).logits[0][0].item()
score2 = rm(**conv2_tokenized).logits[0][0].item()
print(f"Score for response 1: {score1}")
print(f"Score for response 2: {score2}")
# Output:
# Score for response 1: 9.1875
# Score for response 2: -17.875
Bllossom/llama-3.1-Korean-Bllossom-Vision-8B
Bllossom 团队很高兴地宣布 Bllossom-Vision 的发布,这是一个基于 llama3.1 的韩英视觉和语言模型。
这是 Bllossom-Vision 的预览版,具有以下特点
- 通用语言模型和视觉语言模型可双向使用。
- 它既可作为有图像的视觉语言模型使用,也可作为无图像的语言模型使用,既可在视觉语言模型中学习和推断,也可在纯语言模型中学习和推断。
- 我们非常谨慎地保留了现有语言模型的性能,并将其作为视觉语言模型使用。
- 这是一个完全的双语模型,在英语性能方面没有任何妥协。
- 不过,(1) 推理偏差严重,这取决于图像大小;(2) 对韩文表格、图形和 PDF 文档的解释能力较弱。这两项功能将在 10 月份发布的高级模型中提供。
该模型是在以下合作的基础上建立的!
- 采用首尔国立大学 MLP 实验室的视觉语言+语言模型预训练技术。
- TeddyThumb 复杂的指令调整和 RAG 技术。
- 基于 Euclidsoft 提供的视觉和语言训练数据进行训练。
- 得到了 AICA 的支持。
- 我们利用了 EuclidSoft 和首尔国立大学 MLP 实验室在过去五年(2020-2024 年)中合作开发的所有韩国 VQA 数据。
Quick Start
pip install torch transformers==4.44.0
聊天
from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
import torch
model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B')
with torch.no_grad():
PROMPT=\
"""You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
instruction = '자연어처리 15주 분량 커리큘럼을 짜줘'
messages = [
{'role': 'system', 'content': f"{PROMPT}"},
{'role': 'user', 'content': f"{instruction}"}
]
chat_messages = processor.tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors='pt',
)
bos_token = processor.tokenizer.bos_token_id
chat_messages = torch.cat([torch.tensor([[bos_token]]),chat_messages],dim=-1)
output = model.generate(
input_ids = chat_messages,
use_cache=False,
max_new_tokens=2048,
top_p=0.9,
temperature=0.6,
do_sample=True,
)
print(processor.tokenizer.decode(output[0]))
图文对话
from PIL import Image
from transformers import LlavaNextForConditionalGeneration,LlavaNextProcessor
import torch
model = LlavaNextForConditionalGeneration.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B', torch_dtype=torch.bfloat16)
processor = LlavaNextProcessor.from_pretrained('Bllossom/llama-3.1-Korean-Bllossom-Vision-8B')
image = Image.open('[IMAGE_PATH]').convert('RGB')
PROMPT=\
"""You are a versatile AI assistant named Bllava, capable of both understanding and generating text as well as interpreting and analyzing images. Your role is to kindly and effectively answer the user’s questions, whether they are about text or images, and provide appropriate and helpful responses to all types of queries.
당신은 텍스트를 이해하고 생성하는 것뿐만 아니라 이미지를 해석하고 분석할 수 있는 다재다능한 AI 어시스턴트 블라바입니다. 사용자의 질문이 텍스트에 관한 것이든 이미지에 관한 것이든 친절하고 효과적으로 답변하며, 모든 유형의 질의에 대해 적절하고 유용한 응답을 제공하는 것이 당신의 역할입니다."""
instruction = '이미지에 대해서 설명해주세요.'
messages = [
{'role': 'system', 'content': f"{PROMPT}"},
{'role': 'user', 'content': f"<image>\n{instruction}"}
]
chat_messages = processor.tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
inputs = processor(
chat_messages,
image,
return_tensors='pt',
)
output = model.generate(
**inputs,
max_new_tokens=1024,
)
print(processor.tokenizer.decode(output[0]))
开源虽然比不上大企业闭源有稳定的资源渠道,但是玩开源的人却从不孤单,只有你想不到的,没有我们做不到的。