Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。 アマゾン ウェブ サービス

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。 アマゾン ウェブ サービス

本日、Meta が開発した Llama 2 基盤モデルが、以下を通じてお客様に提供されることを発表できることを嬉しく思います。 Amazon SageMaker ジャンプスタート。 Llama 2 ファミリーの大規模言語モデル (LLM) は、7 億から 70 億のパラメーターの規模にわたる、事前トレーニングされ、微調整された生成テキスト モデルのコレクションです。 Llama-2-chat と呼ばれる微調整された LLM は、対話のユースケース向けに最適化されています。 これらのモデルは簡単に試したり、SageMaker JumpStart で使用したりできます。SageMaker JumpStart は、アルゴリズム、モデル、ML ソリューションへのアクセスを提供する機械学習 (ML) ハブであり、ML をすぐに始めることができます。

この投稿では、SageMaker JumpStart 経由で Llama 2 モデルを使用する方法を説明します。

ラマ2とは

Llama 2 は、最適化されたトランスフォーマー アーキテクチャを使用する自動回帰言語モデルです。 Llama 2 は、英語での商用および研究での使用を目的としています。 これには、7 億、13 億、70 億といったさまざまなパラメーター サイズがあり、事前トレーニングおよび微調整されたバリエーションも用意されています。 Meta 氏によると、調整されたバージョンでは、教師あり微調整 (SFT) とヒューマン フィードバックを伴う強化学習 (RLHF) が使用され、有用性と安全性に対する人間の好みに合わせられます。 Llama 2 は、公的に入手可能なソースからの 2 兆トークンのデータで事前トレーニングされました。 調整されたモデルはアシスタントのようなチャットを目的としていますが、事前トレーニングされたモデルはさまざまな自然言語生成タスクに適応できます。 開発者が使用するモデルのバージョンに関係なく、 メタからの責任ある使用ガイド 適切な安全性を緩和してモデルをカスタマイズおよび最適化するために必要となる可能性のある追加の微調整をガイドするのに役立ちます。

SageMaker JumpStart とは

SageMaker JumpStart を使用すると、ML 実践者はオープンソースの基盤モデルの幅広い選択肢から選択できます。 ML 実践者は基礎モデルを専用のモデルにデプロイできます。 アマゾンセージメーカー ネットワーク分離環境からインスタンスを抽出し、モデルのトレーニングとデプロイメントに SageMaker を使用してモデルをカスタマイズします。

数回クリックするだけで Llama 2 を検出して展開できるようになりました。 Amazon SageMakerスタジオ または、SageMaker Python SDK を介してプログラム的に、次のような SageMaker 機能を使用してモデルのパフォーマンスと MLOps コントロールを導き出すことができます。 AmazonSageMakerパイプライン, Amazon SageMakerデバッガ、またはコンテナーのログ。 モデルは AWS の安全な環境にデプロイされ、VPC の制御下に置かれるため、データのセキュリティが確保されます。 Llama 2 モデルは現在、Amazon SageMaker Studio で利用可能です。 us-east 1 および us-west 2 地域。

モデルを発見する

基礎モデルには、SageMaker Studio UI の SageMaker JumpStart および SageMaker Python SDK を通じてアクセスできます。 このセクションでは、SageMaker Studio でモデルを検出する方法について説明します。

SageMaker Studio は、単一の Web ベースのビジュアル インターフェイスを提供する統合開発環境 (IDE) であり、専用ツールにアクセスして、データの準備から ML モデルの構築、トレーニング、デプロイまで、すべての ML 開発ステップを実行できます。 SageMaker Studio の開始方法とセットアップ方法の詳細については、以下を参照してください。 Amazon SageMakerスタジオ.

SageMaker Studio にアクセスすると、事前トレーニングされたモデル、ノートブック、事前構築されたソリューションが含まれる SageMaker JumpStart にアクセスできます。 事前に構築された自動化されたソリューション.

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。

SageMaker JumpStart ランディング ページから、ソリューション、モデル、ノートブック、その他のリソースを参照できます。 2 つの主力 Llama XNUMX モデルが、 基礎モデル: テキスト生成 カルーセル。 Llama 2 モデルが表示されない場合は、シャットダウンして再起動して、SageMaker Studio のバージョンを更新してください。 バージョンアップデートの詳細については、以下を参照してください。 Studio アプリをシャットダウンして更新する.

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。

を選択すると、他の XNUMX つのモデル バリエーションを見つけることもできます。 すべてのテキスト生成モデルを調べる または検索 llama 検索ボックスに

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。

モデル カードを選択すると、ライセンス、トレーニングに使用されるデータ、使用方法などのモデルに関する詳細が表示されます。 ボタンも XNUMX つあります。 配備します および ノートブックを開く、モデルの使用に役立ちます。

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。

いずれかのボタンを選択すると、ポップアップにエンドユーザー使用許諾契約書と使用許諾ポリシーが表示され、同意する必要があります。

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。

承認すると、モデルを使用する次のステップに進みます。

モデルをデプロイする

選ぶとき 配備します 条件に同意すると、モデルのデプロイが開始されます。 あるいは、選択して表示されるサンプル ノートブックを通じてデプロイすることもできます。 ノートブックを開く。 サンプル ノートブックは、推論用のモデルをデプロイし、リソースをクリーンアップする方法に関するエンドツーエンドのガイダンスを提供します。

ノートブックを使用してデプロイするには、まず、 model_id。 次のコードを使用して、選択したモデルのいずれかを SageMaker にデプロイできます。

from sagemaker.jumpstart.model import JumpStartModel
my_model = JumpStartModel(model_id = "meta-textgeneration-llama-2-70b-f")
predictor = my_model.deploy()

これにより、デフォルトのインスタンス タイプやデフォルトの VPC 構成などのデフォルト構成でモデルが SageMaker にデプロイされます。 これらの構成は、デフォルト以外の値を指定することで変更できます。 ジャンプスタートモデル。 デプロイ後、SageMaker プレディクターを介して、デプロイされたエンドポイントに対して推論を実行できます。

payload = { “inputs”: [ [ {"role": "system", "content": "Always answer with Haiku"}, {"role": "user", "content": "I am going to Paris, what should I see?"}, ] ], "parameters":{"max_new_tokens":256, "top_p":0.9, "temperature":0.6}
}

微調整されたチャット モデル (Llama-2-7b-chat、Llama-2-13b-chat、Llama-2-70b-chat) は、ユーザーとチャット アシスタント間のチャット履歴を受け入れ、後続のチャットを生成します。 事前トレーニングされたモデル (Llama-2-7b、Llama-2-13b、Llama-2-70b) には文字列プロンプトが必要で、提供されたプロンプトでテキスト補完を実行します。 次のコードを参照してください。

predictor.predict(payload, custom_attributes="accept_eula=true")

デフォルトでは、 accept_eula false に設定されます。 設定する必要があります accept_eula=true エンドポイントを正常に呼び出すことができます。 これにより、前述のユーザー使用許諾契約および利用規定に同意したことになります。 あなたもすることができます ダウンロード ライセンス契約。

Custom_attributes EULA を渡すために使用されるのはキーと値のペアです。 キーと値は次のように区切られます。 = そしてペアは次のように区切られます ;。 ユーザーが同じキーを複数回渡す場合、最後の値が保持され、スクリプト ハンドラーに渡されます (つまり、この場合は条件付きロジックに使用されます)。 たとえば、次の場合 accept_eula=false; accept_eula=true サーバーに渡されると、  accept_eula=true 保持され、スクリプト ハンドラーに渡されます。

推論パラメータは、エンドポイントでのテキスト生成プロセスを制御します。 新しいトークンの最大数の制御は、モデルによって生成される出力のサイズを指します。 モデルの語彙は英語の語彙と同じではなく、各トークンは英語の単語ではない可能性があるため、これは単語の数と同じではないことに注意してください。 温度は出力のランダム性を制御します。 温度が高いほど、より創造的で幻覚的な出力が得られます。 すべての推論パラメータはオプションです。

次の表は、SageMaker JumpStart で利用可能なすべての Llama モデルと、 model_ids、デフォルトのインスタンス タイプ、およびこれらの各モデルでサポートされる合計トークンの最大数 (入力トークンの数と生成されたトークンの数の合計)。

モデル名 モデルID 最大合計トークン数 デフォルトのインスタンスタイプ
ラマ-2-7b メタテキス​​ト生成-ラマ-2-7b 4096 ml.g5.2xラージ
ラマ-2-7b-チャット メタテキス​​ト生成-ラマ-2-7b-f 4096 ml.g5.2xラージ
ラマ-2-13b メタテキス​​ト生成-ラマ-2-13b 4096 ml.g5.12xラージ
ラマ-2-13b-チャット メタテキス​​ト生成-ラマ-2-13b-f 4096 ml.g5.12xラージ
ラマ-2-70b メタテキス​​ト生成-ラマ-2-70b 4096 ml.g5.48xラージ
ラマ-2-70b-チャット メタテキス​​ト生成-ラマ-2-70b-f 4096 ml.g5.48xラージ

SageMaker エンドポイントには 60 秒のタイムアウト制限があることに注意してください。 したがって、モデルが 4096 個のトークンを生成できる場合でも、テキストの生成に 60 秒以上かかる場合、リクエストは失敗します。 7B、13B、70B モデルの場合は、 max_new_tokens トークンの合計数は 1500K 未満に保ちながら、それぞれ 1000、500、および 4 を超えないようにしてください。

Llama-2-70b の推論とプロンプト例

Llama モデルを使用して、あらゆるテキストのテキスト補完を行うことができます。 テキスト生成を通じて、質問への回答、言語翻訳、感情分析など、さまざまなタスクを実行できます。 エンドポイントへの入力ペイロードは次のコードのようになります。

payload = { “inputs”: str, (optional)"parameters":{"max_new_tokens":int, "top_p":float, "temperature":float}
}

以下は、プロンプトのサンプル例とモデルによって生成されたテキストです。 すべての出力は推論パラメーターを使用して生成されます {"max_new_tokens":256, "top_p":0.9, "temperature":0.6}.

Input: Simply put, the theory of relativity states that Output: 1) the laws of physics are the same for all observers in uniform motion relative to one another, and 2) the speed of light is the same for all observers, regardless of their relative motion or of the motion of the source of the light.
In the late 1800s, scientists believed that light travelled through a medium they called the luminiferous ether. But in 1887, Albert Michelson and Edward Morley designed an experiment to measure the speed of light in the ether, and found that the speed of light was the same no matter how they oriented their equipment. This result seemed to contradict the idea of the ether, and Michelson and Morley’s experiment became one of the most famous failed experiments in history.
In 1905, Albert Einstein published a paper that used the results of the Michelson-Morley experiment to develop the theory of special relativity. In 1915, Einstein published a paper on general relativity, which is a theory of gravitation.
In physics, the speed of light is considered to be a constant, and its value is 299,792,458 metres Input: I believe the meaning of life is Output: to be happy, to find joy in life, to love and be loved. To have the courage to be yourself and to be kind to others. To be able to express yourself, to create and to be inspired. To be able to give and receive. To be able to learn and grow. To be able to find beauty in the world and to be able to appreciate it. To be able to find peace and contentment. To be able to find meaning and purpose. To be able to make a difference in the world. To be able to find joy in the simple things. To be able to find joy in the difficult things. To be able to find joy in the journey. To be able to find joy in the destination. To be able to find joy in the present moment. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy in the future. To be able to find joy in the past. To be able to find joy in the present. To be able to find joy Input: A brief message congratulating the team on the launch: Hi everyone, I just Output: wanted to send a quick note to congratulate everyone on the launch of our new website. I know it’s been a long time coming and I’m sure we’re all relieved that it’s finally out there. Thanks to everyone for their hard work and dedication over the last few months. I know it wasn’t always easy, but I think we can all be proud of the final product. I’m looking forward to seeing how our users respond to the new site and I’m confident that it will be a success. Thanks again, and enjoy the rest of your day! Best, [Your Name] [Your Title] [Your Company] [Your Email] [Your Phone Number] [Your Website] [Your Social Media Handles] [Your Address] [Your City, State, Zip Code] [Your Country] [Your Postal Code] [Your Website] [

次の例では、少数ショットのインコンテキスト学習で Llama モデルを使用する方法を示し、モデルで利用できるトレーニング サンプルを提供します。 デプロイされたモデルに対してのみ推論が行われ、このプロセス中、モデルの重みは変更されないことに注意してください。

Input: Translate English to French: sea otter => loutre de mer peppermint => menthe poivrée plush girafe => girafe peluche cheese => Output: fromage chocolate => chocolat car => voiture hamster => hamster beer => bière bicycle => bicyclette banana => banane strawberry => fraise pizza => pizza cheeseburger => cheeseburger pineapple => ananas carrot => carotte watermelon => pastèque whale => baleine eggplant => aubergine cat => chat penguin => manchot lion => lion elephant => éléphant panda => panda tiger => tigre salmon => saumon squirrel => écureuil kangaroo => kangourou turtle => tortue octopus => poulpe frog => grenouille pig => cochon goldfish => poisson rouge tiger shark => requin tigre gorilla => gorille dol

Llama-2-70b-chat の推論とプロンプト例

対話のユースケース向けに最適化された Llama-2-Chat モデルでは、チャット モデルのエンドポイントへの入力は、チャット アシスタントとユーザーの間の以前の履歴です。 これまでの会話に関連した質問をすることができます。 チャット アシスタントの動作を定義するペルソナなどのシステム構成を提供することもできます。 エンドポイントへの入力ペイロードは次のコードのようになります。

payload = { “inputs”: [ [ (optional){"role": "system", "content": str}, (repeated k times) {"role": "user", "content": str}, {"role": "assistant", "content": str}, {"role": "user", "content": str}, ] ], (optional)"parameters":{"max_new_tokens":int, "top_p":float, "temperature":float}
}

以下は、プロンプトのサンプル例とモデルによって生成されたテキストです。 すべての出力は推論パラメータを使用して生成されます {"max_new_tokens": 512, "top_p": 0.9, "temperature": 0.6}.

Input:
User: what is the recipe of mayonnaise? Output:
Assistant: Sure, I can help you with that! Mayonnaise is a thick, creamy condiment made from a mixture of egg yolks, oil, vinegar or lemon juice, and seasonings. Here's a basic recipe for homemade mayonnaise: Ingredients: * 2 egg yolks
* 1/2 cup (120 ml) neutral-tasting oil, such as canola or grapeseed
* 1 tablespoon (15 ml) vinegar or lemon juice
* 1/2 teaspoon salt
* 1/4 teaspoon black pepper Instructions: 1. In a medium-sized bowl, whisk together the egg yolks, salt, and black pepper until well combined.
2. Slowly pour the oil into the bowl while continuously whisking the mixture. It's important to add the oil very slowly, otherwise the mixture can break and you'll end up with a separated, curdled mess.
3. Continue whisking until the mixture thickens and emulsifies, which should take about 5-7 minutes. You'll know it's ready when the mixture has doubled in volume and has a thick, creamy consistency.
4. Add the vinegar or lemon juice and continue whisking for another minute or two, until the flavors are fully incorporated.
5. Taste the mayonnaise and adjust the seasoning as needed. You can add more salt, pepper, or acid if desired.
6. Cover the bowl with plastic wrap and refrigerate the mayonnaise for at least 30 minutes before serving. This will allow the flavors to meld together and the mayonnaise to thicken further. That's it! This recipe makes about 1 1/2 cups (360 ml) of mayonnaise, which should be enough for a small to medium-sized batch of sandwiches or salads. You can also customize the recipe by adding different flavorings, such as garlic, mustard, or herbs, to create a unique taste. Enjoy!

次の例では、ユーザーはアシスタントとパリの観光地について会話しています。 次に、ユーザーはチャット アシスタントが推奨する最初のオプションについて問い合わせています。

Input:
User: I am going to Paris, what should I see?
Assistant: Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris: 1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows. These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.
User: What is so great about #1? Output:
Assistant: The Eiffel Tower is a world-renowned iconic landmark that symbolizes Paris and France. It was built for the World's Fair in 1889 and was initially intended to be a temporary structure, but it has become a permanent part of the Parisian skyline. Here are some reasons why the Eiffel Tower is so great: 1. Engineering marvel: The Eiffel Tower was a groundbreaking feat of engineering at the time of its construction. It stands at 324 meters (1,063 feet) tall and was the tallest structure in the world for over 40 years.
2. Iconic design: The Eiffel Tower's distinctive shape and design make it instantly recognizable. It has been the subject of countless works of art, photographs, and films, and has become a symbol of Paris and France.
3. Panoramic views: The Eiffel Tower offers breathtaking views of the city from its observation decks. Visitors can enjoy a 360-degree view of Paris, including famous landmarks such as the Seine River, the Arc de Triomphe, and the Montmartre neighborhood.
4. Historical significance: The Eiffel Tower has played a significant role in Paris's history, having been the site of numerous important events, including the famous "Battle of the Eiffel Tower" during World War II.
5. Cultural impact: The Eiffel Tower has had a significant impact on popular culture, inspiring countless works of art, literature, and music. It has also been the subject of numerous documentaries and films, including the classic movie "An American in Paris."
6. Romantic setting: The Eiffel Tower is known for its romantic atmosphere, making it a popular destination for couples and newlyweds. It has been the site of countless marriage proposals and has been featured in numerous romantic films and literature.
7. Accessibility: The Eiffel Tower is easily accessible by public transportation, making it a convenient destination for visitors. It is also wheelchair-friendly, with elevators and ramps providing access to all levels. Overall, the Eiffel Tower is a must-see destination for anyone visiting Paris, offering a unique and unforgettable experience that combines history, culture, engineering, and rom

次の例では、システムの構成を設定します。

Input:
System: Always answer with Haiku
User: I am going to Paris, what should I see? Output:
Assistant: Eiffel Tower high
Art in the Louvre Museum
River Seine flows Input:
System: Always answer with emojis
User: How to go from Beijing to NY? Output:
Assistant: Here are the emojis that represent the steps to go from Beijing to New York: 🇨🇳🛫🛬🇺🇸🗽🏙️🚕💨🛩️🛬🛫😴💤🛩️🛬🛫😍

クリーンアップ

ノートブックの実行が完了したら、プロセス中に作成したすべてのリソースが削除され、請求が停止されるように、必ずすべてのリソースを削除してください。

predictor.delete_model()
predictor.delete_endpoint()

まとめ

この投稿では、SageMaker Studio で Llama 2 モデルの使用を開始する方法を説明しました。 これにより、数十億のパラメータを含む 2 つの Llama XNUMX 基礎モデルにアクセスできるようになります。 基礎モデルは事前にトレーニングされているため、トレーニングとインフラストラクチャのコストを削減し、ユースケースに合わせたカスタマイズを可能にすることもできます。 SageMaker JumpStart の使用を開始するには、次のリソースにアクセスしてください。


著者について

Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。ジューン・ウォン SageMaker JumpStart のプロダクト マネージャーです。 彼は、顧客が生成 AI アプリケーションを構築できるように、基礎モデルを簡単に見つけて使用できるようにすることに重点を置いています。 Amazon での経験には、モバイル ショッピング アプリケーションやラスト マイル配送も含まれます。

ヴィヴェック・マダン ヴィヴェック・マダン博士 Amazon SageMaker JumpStart チームの応用科学者です。 イリノイ大学アーバナ シャンペーン校で博士号を取得し、ジョージア工科大学で博士研究員を務めました。 彼は機械学習とアルゴリズム設計の活発な研究者であり、EMNLP、ICLR、COLT、FOCS、および SODA カンファレンスで論文を発表しています。 Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。 カイル・ウルリッヒ博士 Amazon SageMaker JumpStart チームの応用科学者です。 彼の研究対象には、スケーラブルな機械学習アルゴリズム、コンピューター ビジョン、時系列、ベイジアン ノンパラメトリック、ガウス プロセスなどがあります。 彼はデューク大学で博士号を取得しており、NeurIPS、Cell、および Neuron で論文を発表しています。 Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。 アシッシュ・ケタン博士 Amazon SageMaker JumpStart の上級応用科学者であり、機械学習アルゴリズムの開発を支援しています。 イリノイ大学アーバナ・シャンペーン校で博士号を取得しました。 彼は機械学習と統計的推論の積極的な研究者であり、NeurIPS、ICML、ICLR、JMLR、ACL、および EMNLP カンファレンスで多くの論文を発表しています。 Meta の Llama 2 基礎モデルが Amazon SageMaker JumpStart | で利用できるようになりました。アマゾン ウェブ サービス PlatoBlockchain データ インテリジェンス。垂直検索。あい。 サンダー・ランガナサン AWS の GenAI/Frameworks GTM スペシャリストのグローバル ヘッドです。 彼は、大規模言語モデル、GenAI、および Amazon EC2、EKS、EFA、AWS Batch、Amazon SageMaker などの AWS サービスにわたる大規模 ML ワークロードの GTM 戦略の開発に重点を置いています。 彼の経験には、NetApp、Micron Technology、Qualcomm、Mentor Graphics での製品管理および製品開発におけるリーダーとしての役割が含まれます。

タイムスタンプ:

より多くの AWS機械学習