モデル概要
モデル特徴
モデル能力
使用事例
🚀 MPT-7B-StoryWriter-65k+
MPT-7B-StoryWriter-65k+は、非常に長いコンテキスト長で架空の物語を読み書きするために設計されたモデルです。このモデルは、65kトークンのコンテキスト長を持つMPT-7Bを、books3データセットのフィルタリングされたフィクションサブセットでファインチューニングすることで構築されました。推論時には、ALiBiにより、MPT-7B-StoryWriter-65k+は65kトークンを超える長さの生成も可能です。ブログ記事では、8台のA100-80GB GPUを搭載した単一ノードで84kトークンの生成を実証しています。
- ライセンス: Apache 2.0
このモデルはMosaicMLによって訓練され、修正されたデコーダー専用のトランスフォーマーアーキテクチャに従っています。
🚀 クイックスタート
MPT-7B-StoryWriter-65k+を使い始めるには、以下の手順に従ってください。
モデルの読み込み
このモデルはカスタムモデルアーキテクチャを使用しているため、from_pretrained
メソッドにtrust_remote_code=True
を渡す必要があります。
import transformers
model = transformers.AutoModelForCausalLM.from_pretrained(
'mosaicml/mpt-7b-storywriter',
trust_remote_code=True
)
FlashAttentionの最適化された実装を使用する場合
FlashAttentionの最適化されたtriton実装を使用するには、attn_impl='triton'
とbfloat16
精度でモデルをGPU (cuda:0
) にロードできます。
import torch
import transformers
name = 'mosaicml/mpt-7b-storywriter'
config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
config.attn_config['attn_impl'] = 'triton'
config.init_device = 'cuda:0' # GPU上で直接高速に初期化するため!
model = transformers.AutoModelForCausalLM.from_pretrained(
name,
config=config,
torch_dtype=torch.bfloat16, # モデルの重みをbfloat16でロード
trust_remote_code=True
)
最大シーケンス長を増やす場合
モデルはシーケンス長2048で訓練され、シーケンス長65536でファインチューニングされましたが、ALiBiにより、ファインチューニングおよび/または推論時に最大シーケンス長を増やすことができます。
import transformers
name = 'mosaicml/mpt-7b'
config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
config.max_seq_len = 83968 # (入力 + 出力) トークンは最大83968まで可能
model = transformers.AutoModelForCausalLM.from_pretrained(
name,
config=config,
trust_remote_code=True
)
トークナイザーの読み込み
このモデルはEleutherAI/gpt-neox-20bトークナイザーで訓練されています。
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
テキスト生成パイプラインでの使用
モデルは、例えばテキスト生成パイプライン内で使用できます。Torchモジュールを低精度で実行する場合は、torch.autocastコンテキストマネージャーを使用することをお勧めします。
from transformers import pipeline
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
with torch.autocast('cuda', dtype=torch.bfloat16):
print(
pipe('Here is a recipe for vegan banana bread:\n',
max_new_tokens=100,
do_sample=True,
use_cache=True))
✨ 主な機能
- 超長いコンテキスト長での架空の物語の読み書きが可能。
- ALiBiにより、65kトークンを超える長さの生成も可能。
- 多くの訓練効率機能をサポートしています。例えば、FlashAttention (Dao et al. 2022)、ALiBi、QK LayerNormなど。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。必要に応じてインストールしてください。
pip install transformers
💻 使用例
基本的な使用法
import transformers
model = transformers.AutoModelForCausalLM.from_pretrained(
'mosaicml/mpt-7b-storywriter',
trust_remote_code=True
)
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
from transformers import pipeline
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
with torch.autocast('cuda', dtype=torch.bfloat16):
print(
pipe('Here is a recipe for vegan banana bread:\n',
max_new_tokens=100,
do_sample=True,
use_cache=True))
高度な使用法
FlashAttentionの最適化された実装を使用する場合や、最大シーケンス長を増やす場合のコードは、「クイックスタート」セクションを参照してください。
📚 ドキュメント
- ブログ記事: Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs
- コードベース (mosaicml/llm-foundryリポジトリ)
- 質問は、MosaicML Community Slackを通じてお問い合わせください!
🔧 技術詳細
モデルアーキテクチャ
モデルのアーキテクチャは、標準的なデコーダー専用のトランスフォーマーを修正したものです。以下の点で標準的なトランスフォーマーから変更されています。
- FlashAttentionを使用。
- ALiBi (Attention with Linear Biases)を使用し、位置埋め込みを使用しない。
- バイアスを使用しない。
プロパティ | 詳細 |
---|---|
モデルタイプ | 修正されたデコーダー専用トランスフォーマー |
パラメータ数 | 6.7B |
レイヤー数 | 32 |
ヘッド数 | 32 |
モデル次元数 | 4096 |
語彙サイズ | 50432 |
シーケンス長 | 65536 |
事前学習データ
事前学習プロセスの詳細については、MPT-7Bを参照してください。データはEleutherAI/gpt-neox-20bトークナイザーを使用してトークン化されました。
訓練設定
このモデルは、MosaicML Platformを使用して、8台のA100-80GB GPUで約2日間訓練されました。モデルはFSDPを使用したシャード化データ並列で訓練され、LIONオプティマイザーを使用しました。
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。
コミュニティが作成したリソース
これらはMosaicMLによって作成されたものではありませんが、役立つ場合があります。これらのリンクは、作成者やそのコンテンツを推奨するものではありません。
- Oobabooga Running MPT-7B-Storywriter
- NEW MPT-7B-StoryWriter CRUSHES GPT-4! - Oobaboogaを使用してローカルで実行する方法についての長いセクションがあります。
サンプルエピローグ
The Great Gatsby (67873トークン) の全文をモデルに入力し、その後に「EPILOGUE」というテキストを入力しました。
TheRealFitzgerald233:
...
So we beat on, boats against the current, borne back ceaselessly into the past
EPILOGUE
MPT-7B-StoryWriter:
I have lived so long in the shadow of this dream that I may never see the bright sunlight of reality. I may look up some morning and find that I am six feet under, and that Gatsby, who gave me the dream and everything else, will have vanished behind me.
And so it was. I had hardly crossed the threshold of the old world when my eye caught the headlines of a newspaper, and I knew at once that my dream was over. I knew that Gatsby was dead.
And I knew that day that I didn't love her.
That night I took the last train for West Egg, and when I reached home I went directly to my attic and brought down all Gatsby's letters.
I have sorted them by date and placed them in the order in which they were written. They are very few in number.
They are dated between April of nineteen eighteen and January of nineteen nineteen, and the last one I have here is the one that told me he was dead.
There is something in that last letter that frightens me. It is the sense of a finality, of a completeness. I never heard of him after that, and I was glad.
But a few months ago I read somewhere that he had been seen in New York. He had become a great man.
And I knew that he had not changed at all.
制限とバイアス
以下の文章はEleutherAIのGPT-NeoX-20Bから修正されたものです。
MPT-7B-StoryWriterは事実に誤りのある出力を生成する可能性があり、事実に基づく正確な情報を生成することに依存してはいけません。MPT-7B-StoryWriterはさまざまな公開データセットで訓練されています。事前学習データをクリーンアップするために多大な努力が払われていますが、このモデルが猥褻、偏見、またはその他の不快な出力を生成する可能性があります。
謝辞
このモデルはAlex TrottとMosaicMLのNLPチームによってファインチューニングされました。
MosaicMLプラットフォーム
MosaicML Platformで独自のMPTまたはLLMを訓練およびデプロイすることに興味がある場合は、こちらからサインアップしてください。
免責事項
このモデルのライセンスは法的なアドバイスを構成するものではありません。このモデルを使用する第三者の行動については責任を負いません。このモデルを商用目的で使用する前に、弁護士に相談してください。
引用
このモデルを引用する場合は、以下の形式を使用してください。
@online{MosaicML2023Introducing,
author = {MosaicML NLP Team},
title = {Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs},
year = {2023},
url = {www.mosaicml.com/blog/mpt-7b},
note = {Accessed: 2023-03-28}, % この日付を変更してください
urldate = {2023-03-28} % この日付を変更してください
}



