柏拉圖數據智能。
垂直搜索和人工智能。

Databricks DBRX 現已在 Amazon SageMaker JumpStart 中提供 |亞馬遜網路服務

日期:

今天,我們很高興地宣布 DBRX型號,一個開放的、通用的大語言模型(LLM),由 數據塊,客戶可以透過 亞馬遜SageMaker JumpStart 一鍵部署以運行推理。 DBRX LLM 採用細粒度專家混合 (MoE) 架構,針對 12 兆個精心策劃的資料令牌和最大上下文長度 32,000 個令牌進行預訓練。

您可以使用 SageMaker JumpStart 嘗試此模型,SageMaker JumpStart 是一個機器學習 (ML) 中心,提供對演算法和模型的訪問,以便您可以快速開始使用 ML。在這篇文章中,我們將介紹如何發現和部署 DBRX 模型。

DBRX是什麼型號

DBRX 是基於 Transformer 架構的複雜的僅解碼器 LLM。它採用細粒度的 MoE 架構,包含 132 億個總參數,其中 36 億個參數對於任何給定輸入都是活動的。

該模型使用由 12 兆個文字和程式碼組成的資料集進行了預訓練。與 Mixtral 和 Grok-1 等其他開放 MoE 模型相比,DBRX 採用細粒度方法,使用更多數量的小型專家來優化效能。與其他 MoE 模型相比,DBRX 有 16 位專家,選擇 4 位。

該模型根據 Databricks 開放模型許可證提供,可以不受限制地使用。

什麼是 SageMaker JumpStart

SageMaker JumpStart 是一個完全託管的平台,為內容編寫、程式碼產生、問答、文案編寫、摘要、分類和資訊檢索等各種用例提供最先進的基礎模型。它提供了一系列預先訓練的模型,您可以快速輕鬆地部署這些模型,從而加速 ML 應用程式的開發和部署。 SageMaker JumpStart 的關鍵組件之一是模型中心,它提供了大量預訓練模型(例如 DBRX),適用於各種任務。

現在,您只需點擊幾下即可發現並部署 DBRX 模型 亞馬遜SageMaker Studio 或透過 SageMaker Python SDK 以程式設計方式取得模型效能和 MLOps 控制 亞馬遜SageMaker 功能,例如 Amazon SageMaker管道, Amazon SageMaker調試器,或容器日誌。此模型部署在 AWS 安全環境中並受您的 VPC 控制,有助於提供資料安全。

在 SageMaker JumpStart 中發現模型

您可以透過 SageMaker Studio UI 和 SageMaker Python SDK 中的 SageMaker JumpStart 存取 DBRX 模型。在本節中,我們將介紹如何在 SageMaker Studio 中發現模型。

SageMaker Studio 是一個集成開發環境 (IDE),提供基於 Web 的單一可視化界面,您可以在其中訪問專用工具來執行所有 ML 開發步驟,從準備數據到構建、訓練和部署 ML 模型。 有關如何開始和設置 SageMaker Studio 的更多詳細信息,請參閱 亞馬遜SageMaker Studio.

在 SageMaker Studio 中,您可以透過選擇來存取 SageMaker JumpStart 快速啟動 在導航窗格中。

在 SageMaker JumpStart 登入頁面中,您可以在搜尋框中搜尋「DBRX」。搜尋結果將列出 DBRX指令DBRX 底座.

您可以選擇模型卡來查看有關模型的詳細信息,例如許可證、用於訓練的數據以及如何使用模型。您也會發現 部署 按鈕來部署模型並建立端點。

在 SageMaker JumpStart 中部署模型

當您選擇 部署 按鈕。部署完成後,您將看到已建立端點。您可以透過傳遞範例推理請求負載或使用 SDK 選擇測試選項來測試端點。當您選擇使用 SDK 的選項時,您將看到可在 SageMaker Studio 中選擇的筆記本編輯器中使用的範例程式碼。

DBRX 底座

要使用 SDK 進行部署,我們首先選擇 DBRX Base 模型,由 model_id 具有值huggingface-llm-dbrx-base。您可以使用下列程式碼在 SageMaker 上部署任何選定的模型。同樣,您可以使用 DBRX Instruct 自己的模型 ID 來部署它。

from sagemaker.jumpstart.model import JumpStartModel

accept_eula = True

model = JumpStartModel(model_id="huggingface-llm-dbrx-base")
predictor = model.deploy(accept_eula=accept_eula)

這會使用默認配置在 SageMaker 上部署模型,包括默認實例類型和默認 VPC 配置。 您可以通過在中指定非默認值來更改這些配置 快速啟動模型。 Eula 值必須明確定義為 True 才能接受最終使用者授權協議 (EULA)。另請確保您具有將 ml.p4d.24xlarge 或 ml.pde.24xlarge 端點用作一個或多個實例的帳戶級服務限制。您可以按照說明進行操作 点击這裡 以請求增加服務配額。

部署後,您可以透過 SageMaker 預測器對部署的端點執行推理:

payload = {
    "inputs": "Hello!",
    "parameters": {
        "max_new_tokens": 10,
    },
}
predictor.predict(payload)

示例提示

您可以像任何標準文字生成模型一樣與 DBRX Base 模型進行交互,其中模型處理輸入序列並輸出序列中預測的下一個單字。在本節中,我們提供一些範例提示和範例輸出。

代碼生成

使用前面的範例,我們可以使用程式碼產生提示,如下所示:

payload = { 
      "inputs": "Write a function to read a CSV file in Python using pandas library:", 
      "parameters": { 
          "max_new_tokens": 30, }, } 
           response = predictor.predict(payload)["generated_text"].strip() 
           print(response)

以下是輸出:

import pandas as pd 
df = pd.read_csv("file_name.csv") 
#The above code will import pandas library and then read the CSV file using read_csv

情緒分析

您可以使用 DBRX 使用下列提示執行情緒分析:

payload = {
"inputs": """
Tweet: "I am so excited for the weekend!"
Sentiment: Positive

Tweet: "Why does traffic have to be so terrible?"
Sentiment: Negative

Tweet: "Just saw a great movie, would recommend it."
Sentiment: Positive

Tweet: "According to the weather report, it will be cloudy today."
Sentiment: Neutral

Tweet: "This restaurant is absolutely terrible."
Sentiment: Negative

Tweet: "I love spending time with my family."
Sentiment:""",
"parameters": {
"max_new_tokens": 2,
},
}
response = predictor.predict(payload)["generated_text"].strip()
print(response)

以下是輸出:

問題回答

您可以在 DBRX 中使用如下所示的問答提示:

# Question answering
payload = {
    "inputs": "Respond to the question: How did the development of transportation systems, such as railroads and steamships, impact global trade and cultural exchange?",
    "parameters": {
        "max_new_tokens": 225,
    },
}
response = predictor.predict(payload)["generated_text"].strip()
print(response)

以下是輸出:

The development of transportation systems, such as railroads and steamships, impacted global trade and cultural exchange in a number of ways. 
The documents provided show that the development of these systems had a profound effect on the way people and goods were able to move around the world. 
One of the most significant impacts of the development of transportation systems was the way it facilitated global trade. 
The documents show that the development of railroads and steamships made it possible for goods to be transported more quickly and efficiently than ever before. 
This allowed for a greater exchange of goods between different parts of the world, which in turn led to a greater exchange of ideas and cultures. 
Another impact of the development of transportation systems was the way it facilitated cultural exchange. The documents show that the development of railroads and steamships made it possible for people to travel more easily and quickly than ever before. 
This allowed for a greater exchange of ideas and cultures between different parts of the world. Overall, the development of transportation systems, such as railroads and steamships, had a profound impact on global trade and cultural exchange.

DBRX指令

DBRX 的指令調整版本接受格式化指令,其中對話角色必須以使用者的提示開始,並在使用者指令和助手之間交替(DBRX 指令)。必須嚴格遵守指令格式,否則模型將產生次優輸出。為 Instruct 模型建立提示的範本定義如下:

<|im_start|>system
{system_message} <|im_end|>
<|im_start|>user
{human_message} <|im_end|>
<|im_start|>assistantn

<|im_start|><|im_end|> 是字串開頭 (BOS) 和字串結尾 (EOS) 的特殊標記。該模型可以包含系統、使用者和助手之間的多個對話回合,從而允許合併少量範例來增強模型的回應。

以下程式碼顯示如何將提示格式化為指令格式:

from typing import Dict, List

def format_instructions(instructions: List[Dict[str, str]]) -> List[str]:
    """Format instructions where conversation roles must alternate system/user/assistant/user/assistant/..."""
    prompt: List[str] = []
    for instruction in instructions:
        if instruction["role"] == "system":
            prompt.extend(["<|im_start|>systemn", (instruction["content"]).strip(), " <|im_end|>n"])
        elif instruction["role"] == "user":
            prompt.extend(["<|im_start|>usern", (instruction["content"]).strip(), " <|im_end|>n"])
        else:
            raise ValueError(f"Invalid role: {instruction['role']}. Role must be either 'user' or 'system'.")
    prompt.extend(["<|im_start|>assistantn"])
    return "".join(prompt)

def print_instructions(prompt: str, response: str) -> None:
    bold, unbold = '33[1m', '33[0m'
    print(f"{bold}> Input{unbold}n{prompt}nn{bold}> Output{unbold}n{response['generated_text'].strip()}n")

知識檢索

您可以使用以下提示進行知識檢索:

instructions = [
{"role": "system", "content": "You are an expert in suggesting diet plans optimized for different sports or fitness activities, taking into account energy requirements, and recovery requirements."},
{"role": "user", "content": "I am trying to build muscle mass and increase my strength. What kind of high-protein, calorie-dense diet plan would you recommend for me?"}
]
prompt = format_instructions(instructions)
payload = {
"inputs": prompt,
"parameters": {"max_new_tokens": 700, "temperature": 0.5, "do_sample": True}
}
response=predictor.predict(payload)
print_instructions(prompt, response)

以下是輸出:

> Input
<|im_start|>system
You are an expert in suggesting diet plans optimized for different sports or fitness activities, taking into account energy requirements, and recovery requirements. <|im_end|>
<|im_start|>user
I am trying to build muscle mass and increase my strength. What kind of high-protein, calorie-dense diet plan would you recommend for me? <|im_end|>
<|im_start|>assistant

> Output
Absolutely, I'd be happy to help you with that. Given your goal of building muscle mass and increasing strength, you'll want a diet that's high in protein and provides sufficient calories to support muscle growth and recovery. Here's a basic outline of what your diet plan could look like:

1. **Breakfast:**
   - 3 whole eggs
   - 3 egg whites
   - 1 cup of oatmeal
   - 1 scoop of whey protein
   - 1 banana

2. **Mid-Morning Snack:**
   - 1.5 ounces of almonds
   - 1 apple

3. **Lunch:**
   - 8 ounces of chicken breast
   - 1 cup of brown rice
   - 1 cup of mixed vegetables

4. **Afternoon Snack:**
   - 1.5 cups of Greek yogurt
   - 1 cup of mixed berries

5. **Dinner:**
   - 8 ounces of salmon or lean beef
   - 1 cup of quinoa
   - 1.5 cups of mixed vegetables

6. **Evening Snack:**
   - 1 scoop of casein protein
   - 1 tablespoon of almond butter

This is a high-protein, calorie-dense diet that includes a variety of nutrient-rich foods. It's important to note that everyone's nutritional needs are different, so you may need to adjust portion sizes or food choices based on your specific needs and preferences.

Also, remember to stay hydrated by drinking plenty of water throughout the day. Regular exercise, particularly strength training, is crucial to achieving your goals. It's also important to get enough sleep to aid in muscle recovery and growth.

Before starting any new diet or exercise program, it's a good idea to consult with a healthcare professional or a registered dietitian. They can provide personalized advice based on your health history and current lifestyle.

代碼生成

DBRX 模型展示了編碼任務的基準優勢。例如,請參閱以下程式碼:

instructions = [ 
{"role": "system", "content": "You are an expert in coding and programming. Your role is to provide examples, explanations, and insights related to programming languages, algorithms, data structures, and software development practices."}, 
{"role": "user", "content": "Write a Python script to read a CSV file containing stock prices and plot the closing prices over time using Matplotlib."} 
] 
prompt = format_instructions(instructions) 
payload = { "inputs": prompt, "parameters": {"max_new_tokens": 315, "temperature": 0.3, "do_sample": True} } 
response=predictor.predict(payload) 
print_instructions(prompt, response)

以下是輸出:

> Input
<|im_start|>system
You are an expert in coding and programming. Your role is to provide examples, explanations, and insights related to programming languages, algorithms, data structures, and software development practices. <|im_end|>
<|im_start|>user
Write a Python script to read a CSV file containing stock prices and plot the closing prices over time using Matplotlib. <|im_end|>
<|im_start|>assistant

> Output
Sure, I'd be happy to help you with that. Here's a simple Python script that uses the `pandas` library to read a CSV file and `matplotlib` to plot the closing prices over time.

```python
import pandas as pd
import matplotlib.pyplot as plt

# Load the data from a CSV file
df = pd.read_csv('stock_prices.csv')

# Plot the closing prices over time
plt.figure(figsize=(12,5))
plt.plot(df['Date'], df['Close'])
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Stock Prices Over Time')
plt.show()
```

In this script, replace `'stock_prices.csv'` with the path to your CSV file. The file should have columns named 'Date' and 'Close' for this script to work correctly. If your file uses different column names, you'll need to adjust the script accordingly.

The `pandas` library is a powerful tool for data manipulation and analysis. It can read data from a variety of sources, including CSV files, and represent the data in a tabular format. The `matplotlib` library is a popular choice for creating static, animated, and interactive visualizations in Python.

This script first loads the data from the CSV file into a pandas DataFrame. It then plots the 'Close' column against the 'Date' column using matplotlib's `plot()` function. The `figure()` function is used to specify the size of the plot, and `show()` is used to display the plot.

數學與推理

DBRX 模型也報告了數學準確性方面的優勢。例如,請參閱以下程式碼:

instructions = [
  {"role": "system", "content": "You are an expert in mathematics and reasoning. Your role is to provide examples, explanations, and insights related to mathematical concepts, problem-solving techniques, and logical reasoning."},
  {"role": "user", "content": "A car rental company charges $40 per day plus $0.25 per mile driven. If I rented a car for 3 days and drove 250 miles, what would be the total cost? Break down the calculation steps before giving the final answer."}
]
prompt = format_instructions(instructions)
payload = {
"inputs": prompt,
"parameters": {"max_new_tokens": 400, "temperature": 0.2, "do_sample": True}
}
response=predictor.predict(payload)
print_instructions(prompt, response)

DBRX 可以透過數學邏輯提供如下輸出所示的理解:

> Input
<|im_start|>system
You are an expert in mathematics and reasoning. Your role is to provide examples, explanations, and insights related to mathematical concepts, problem-solving techniques, and logical reasoning. <|im_end|>
<|im_start|>user
A car rental company charges $40 per day plus $0.25 per mile driven. If I rented a car for 3 days and drove 250 miles, what would be the total cost? Break down the calculation steps before giving the final answer. <|im_end|>
<|im_start|>assistant

> Output
Sure, I'd be happy to help with that! The problem you've presented involves both fixed costs (the daily rate) and variable costs (the cost per mile). Let's break it down:

1. First, let's calculate the total cost of the fixed daily rate. The car rental company charges $40 per day, and you rented the car for 3 days. So, the total cost for the daily rate is $40/day * 3 days = $120.

2. Next, let's calculate the total cost of the variable rate, which is the cost per mile driven. The company charges $0.25 per mile, and you drove 250 miles. So, the total cost for the mileage is $0.25/mile * 250 miles = $62.50.

3. Finally, to find the total cost of renting the car, we add the total cost of the daily rate and the total cost of the mileage. So, the total cost is $120 + $62.50 = $182.50.

So, the total cost of renting the car for 3 days and driving 250 miles would be $182.50.

清理

運行完筆記本後,請確保刪除在此過程中創建的所有資源,以便停止計費。 使用以下代碼:

predictor.delete_model()
predictor.delete_endpoint()

結論

在這篇文章中,我們向您展示如何在 SageMaker Studio 中開始使用 DBRX 並部署模型進行推理。由於基礎模型是預先訓練的,因此它們可以幫助降低培訓和基礎設施成本,並支援針對您的用例進行客製化。立即造訪 SageMaker Studio 中的 SageMaker JumpStart 以開始使用。

資源


關於作者

希哈夸特拉 是 Amazon Web Services 的 AI/ML 專家解決方案架構師,與領先的全球系統整合商合作。他獲得了印度最年輕的發明大師之一的稱號,在 AI/ML 和 IoT 領域擁有 400 多項專利。他擁有超過 8 年的行業經驗,從新創公司到大型企業,從物聯網研究工程師、資料科學家到資料和人工智慧架構師。 Shikhar 協助組織設計、建構和維護經濟高效、可擴展的雲端環境,並支援 GSI 合作夥伴建立策略產業

尼森·維傑斯瓦蘭 是 AWS 的解決方案架構師。他的重點領域是生成式 AI 和 AWS AI 加速器。他擁有電腦科學和生物資訊學士學位。 Niithiyn 與 Generative AI GTM 團隊密切合作,在多個方面為 AWS 客戶提供支持,並加速他們對生成式 AI 的採用。他是達拉斯小牛隊的狂熱粉絲,喜歡收集運動鞋。

塞巴斯蒂安·布斯蒂略 是 AWS 的解決方案架構師。他專注於人工智慧/機器學習技術,對生成式人工智慧和運算加速器充滿熱情。在 AWS,他幫助客戶透過生成式 AI 釋放商業價值。當他不工作時,他喜歡沖泡一杯完美的精品咖啡,並與妻子一起探索世界。

阿曼多·迪亞茲 是 AWS 的解決方案架構師。他專注於生成人工智慧、人工智慧/機器學習和數據分析。在 AWS,Armando 幫助客戶將尖端的生成式 AI 功能整合到他們的系統中,從而促進創新和競爭優勢。當他不工作時,他喜歡與妻子和家人共度時光、遠足和環遊世界。

現貨圖片

最新情報

現貨圖片

和我們線上諮詢

你好呀!我怎麼幫你?