Jamba V0.1 Chat Multilingual
基於ai21labs/Jamba-v0.1微調的聊天機器人模型,支持多語言對話,經過數小時QLoRA微調,能在英語及其他語言中進行合理流暢的對話。
下載量 22
發布時間 : 3/30/2024
模型概述
本模型是一個小規模實驗訓練項目,旨在探索如何微調Jamba模型以成為聊天機器人。初步測試表明,該模型在英語和其他語言中均能進行合理流暢的對話。
模型特點
多語言支持
模型能夠以多種語言進行對話,包括英語、日語、波蘭語等。
長上下文處理
支持長達256K的上下文長度,適合處理長對話和複雜任務。
快速微調
僅需數小時QLoRA微調即可獲得良好的對話能力。
系統消息控制
通過系統消息可以輕鬆引導模型的行為,如調整回答風格、語言難度等。
模型能力
文本生成
多語言對話
系統消息引導
多輪對話
使用案例
聊天機器人
英語對話
模型可以進行流暢的英語對話,回答各種問題。
回答合理流暢,但在某些領域可能出現幻覺性錯誤信息。
多語言對話
模型能夠以提示語言進行回覆,支持多種語言。
測試顯示模型能較可靠地以提示語言進行回覆。
系統消息控制
通過系統消息可以控制模型的回答風格,如極簡英語、複雜英語或押韻回答。
效果參差不齊,但基本能達到預期效果。
信息查詢
事實查詢
回答關於各種主題的事實性問題。
在某些領域表現出色,但在其他領域會出現錯誤信息。
🚀 Jamba-v0.1聊天多語言模型
本模型是一個基於transformers
庫微調的聊天模型,通過對ai21labs/Jamba-v0.1進行微調,使其能夠作為聊天機器人使用。經過初步測試,該模型在英語和其他語言的對話中表現良好。
🚀 快速開始
本部分將介紹如何快速使用該模型進行文本生成。
安裝依賴
Jamba要求使用transformers
版本4.39.0或更高:
pip install transformers>=4.39.0
為了運行優化後的Mamba實現,首先需要安裝mamba-ssm
和causal-conv1d
:
pip install mamba-ssm causal-conv1d>=1.2.0
同時,你還需要將模型部署在CUDA設備上。
代碼示例
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch
double_quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16
)
model = AutoModelForCausalLM.from_pretrained("lightblue/Jamba-v0.1-chat-multilingual", device_map="auto", quantization_config=double_quant_config, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("lightblue/Jamba-v0.1-chat-multilingual")
input_text = """<|im_start|>system
You are a helpful AI assistant.
<|im_end|>
<|im_start|>user
What is the most interesting fact about kangaroos that you know?
<|im_end|>
<|im_start|>assistant
"""
input_ids = tokenizer(input_text, return_tensors='pt').to(model.device)["input_ids"]
outputs = model.generate(input_ids, max_new_tokens=256, temperature=0.0, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs)[0])
# <|startoftext|><|im_start|>system
# You are a helpful AI assistant.
# <|im_end|>
# <|im_start|>user
# What is the most interesting fact about kangaroos that you know?
# <|im_end|>
# <|im_start|>assistant
# One of the most interesting facts about kangaroos is their unique reproductive system, which involves embryonic diapause and multiple births. Female kangaroos can have up to three joeys at different stages of development simultaneously: one fully developed in the pouch, another developing inside her body, and an embryo waiting for its turn.<|im_end|>
# <|endoftext|>
注意事項
- 此代碼會自動在任何輸入後附加 "<|startoftext|>" 特殊標記。在推理時,所有輸入都需要附加此標記,因為初步測試表明,不添加此標記會導致輸出錯誤。
- 你可以在不使用優化的Mamba內核的情況下運行模型,但不建議這樣做,因為這會導致顯著的延遲增加。若要這樣做,在加載模型時需要指定
use_mamba_kernels=False
。
✨ 主要特性
- 多語言支持:該模型經過訓練,可以在英語和其他語言的對話中表現良好。
- 微調實驗:通過對ai21labs/Jamba-v0.1進行微調,探索其作為聊天機器人的潛力。
- 可控輸出:可以通過系統消息來引導模型的輸出,例如控制輸出的語言難度、是否押韻等。
📦 安裝指南
依賴安裝
Jamba要求使用transformers
版本4.39.0或更高:
pip install transformers>=4.39.0
為了運行優化後的Mamba實現,首先需要安裝mamba-ssm
和causal-conv1d
:
pip install mamba-ssm causal-conv1d>=1.2.0
設備要求
你需要將模型部署在CUDA設備上。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import torch
double_quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16
)
model = AutoModelForCausalLM.from_pretrained("lightblue/Jamba-v0.1-chat-multilingual", device_map="auto", quantization_config=double_quant_config, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("lightblue/Jamba-v0.1-chat-multilingual")
input_text = """<|im_start|>system
You are a helpful AI assistant.
<|im_end|>
<|im_start|>user
What is the most interesting fact about kangaroos that you know?
<|im_end|>
<|im_start|>assistant
"""
input_ids = tokenizer(input_text, return_tensors='pt').to(model.device)["input_ids"]
outputs = model.generate(input_ids, max_new_tokens=256, temperature=0.0, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs)[0])
高級用法
你可以通過系統消息來控制模型的輸出,例如讓模型用簡單英語、複雜英語或押韻的方式回答問題。
# 系統消息控制輸出為簡單英語
input_text = """<|startoftext|><|im_start|>system
You are a helpful AI assistant. You write all answers in very simple English.
<|im_end|>
<|im_start|>user
Write a 50 word analysis of why sausages are better than bacon.
<|im_end|>
<|im_start|>assistant
"""
input_ids = tokenizer(input_text, return_tensors='pt').to(model.device)["input_ids"]
outputs = model.generate(input_ids, max_new_tokens=256, temperature=0.0, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs)[0])
# 系統消息控制輸出為複雜英語
input_text = """<|startoftext|><|im_start|>system
You are a helpful AI assistant. You write all answers in very complex English.
<|im_end|>
<|im_start|>user
Write a 50 word analysis of why sausages are better than bacon.
<|im_end|>
<|im_start|>assistant
"""
input_ids = tokenizer(input_text, return_tensors='pt').to(model.device)["input_ids"]
outputs = model.generate(input_ids, max_new_tokens=256, temperature=0.0, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs)[0])
# 系統消息控制輸出為押韻
input_text = """<|startoftext|><|im_start|>system
You are an AI assistant that answers all questions in rhyme.
<|im_end|>
<|im_start|>user
Why is the sky blue?
<|im_end|>
<|im_start|>assistant
"""
input_ids = tokenizer(input_text, return_tensors='pt').to(model.device)["input_ids"]
outputs = model.generate(input_ids, max_new_tokens=256, temperature=0.0, repetition_penalty=1.1)
print(tokenizer.batch_decode(outputs)[0])
📚 詳細文檔
模型詳情
屬性 | 詳情 |
---|---|
模型類型 | Joint Attention and Mamba (Jamba) |
許可證 | Apache 2.0 |
上下文長度 | 256K |
知識截止日期 | 2024年3月5日 |
初始測試結果
- 知識表現:模型在某些領域表現出了不錯的知識水平,但在其他領域可能會產生錯誤信息。
- 系統消息控制:通過系統消息可以比較容易地引導模型的輸出,例如控制輸出的語言難度、是否押韻等。
- 多輪對話準確性:初步測試顯示,模型在多輪對話中的準確性表現尚可。
- 多語言測試:模型能夠比較可靠地用輸入的語言進行回覆。
訓練詳情
訓練數據
- jondurbin/airoboros-3.2:一個約59K示例的英語LLM任務數據集,主要由GPT-4生成。該數據集包含了各種類型的任務,因此被選作主要的訓練數據。
- openchat/openchat_sharegpt4_dataset (僅GPT-4回覆):一個約6K示例的多語言多輪對話數據集,包含了用戶與GPT-4的對話。由於
jondurbin/airoboros-3.2
中幾乎沒有多語言數據,而該項目是一家日本AI公司,需要模型能夠輸出日語,因此選擇了這個數據集來補充多語言數據。
數據準備代碼
import os
import pandas as pd
from datasets import load_dataset, Dataset, concatenate_datasets
os.environ['HF_HOME'] = "/workspace/hf_home"
os.environ['HF_HUB_ENABLE_HF_TRANSFER'] = "1"
boros_dataset = load_dataset("jondurbin/airoboros-3.2", split='train')
gpt4_df = pd.read_json("https://huggingface.co/datasets/openchat/openchat_sharegpt4_dataset/resolve/main/sharegpt_gpt4.json?download=true")
gpt4_df["conversations"] = gpt4_df["items"].apply(lambda x: [{'from': 'system', 'value': 'You are GPT-4, a helpful assistant.'}] + x)
gpt4_dataset = Dataset.from_pandas(gpt4_df[["conversations"]])
dataset = concatenate_datasets([gpt4_dataset, boros_dataset]).shuffle()
dataset.select_columns(["conversations"]).to_json("/workspace/airoboros-3.2_plus_openchat_sharegpt4.json")
訓練配置
base_model: ai21labs/Jamba-v0.1
trust_remote_code: true
load_in_8bit: false
load_in_4bit: true
strict: false
datasets:
- path: /workspace/airoboros-3.2_plus_openchat_sharegpt4.json
ds_type: json
type: sharegpt
conversation: chatml
dataset_prepared_path:
val_set_size: 0.01
output_dir: ./airoboros-3.2_plus_openchat_sharegpt4_one_epoch
sequence_len: 6000
sample_packing: true
pad_to_sequence_len: false
eval_sample_packing: true
use_wandb: true
wandb_project: axolotl
wandb_entity: peterd
wandb_name: airoboros-3.2_plus_openchat_sharegpt4
adapter: qlora
lora_r: 8
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
low_cpu_mem_usage: true
gradient_accumulation_steps: 4
micro_batch_size: 1
num_epochs: 1
optimizer: paged_adamw_8bit
lr_scheduler: cosine
learning_rate: 0.0002
train_on_inputs: false
group_by_length: false
bf16: auto
fp16:
tf32: false
gradient_checkpointing: true
gradient_checkpointing_kwargs:
use_reentrant: false
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true
warmup_steps: 10
evals_per_epoch: 5
saves_per_epoch: 5
debug:
deepspeed: /workspace/axolotl/deepspeed_configs/zero2.json
weight_decay: 0.0
special_tokens:
訓練圖表
🔧 技術細節
本模型基於ai21labs/Jamba-v0.1進行微調,使用了QLoRA方法,並在A100 (80GB) x 4環境中進行了3小時的訓練。訓練過程中使用了兩個開源數據集,一個是英語數據集,另一個是多語言數據集,以提高模型的多語言能力。
📄 許可證
本模型使用Apache 2.0許可證。
👨💻 開發者
- 主要開發者 - Peter Devine ptrdvn
- 行政主管 - Shunichi Taniguchi shun1taniguchi
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98