在亞馬遜云科技AWS上利用SageMaker機器學習模型平臺搭建生成式AI應用(附Llama大模型部署和測試代碼)

項目簡介:

接下來,小李哥將會每天介紹一個基于亞馬遜云科技AWS云計算平臺的全球前沿AI技術解決方案,幫助大家快速了解國際上最熱門的云計算平臺亞馬遜云科技AWS AI最佳實踐,并應用到自己的日常工作里。本次介紹的是如何在Amazon SageMaker上使用大語言模型Meta Llama 7B,提供可擴展和安全的AI解決方案。通過Amazon API Gateway和AWS Lambda將應用程序與AI模型集成。本方案的解決方案架構圖如下:

本方案將主要使用亞馬遜云科技AWS上的大模型/機器學習模型托管服務Amazon SageMaker,下面我們介紹一下該服務。

什么是Amazon SageMaker?

Amazon SageMaker是一款由亞馬遜云科技提供的全面模型托管服務,旨在幫助開發者和數據科學家快速、輕松地構建、訓練和部署機器學習模型。SageMaker原生集成了機器行業熱門的工具和框架,使用戶能夠專注于模型的開發和優化,而無需擔心基礎設施的管理。

通過SageMaker,用戶可以使用預構建的算法和框架,或者將自己的自定義代碼帶入平臺進行訓練。其自動化的數據處理和模型訓練功能,可以大大減少模型開發的時間和復雜性。此外,SageMaker還提供了云托管Jupyter Notebook,用戶可以使用本地熟悉的訓練模型工具,以便無縫從本地遷移到云端模型訓練。

在模型訓練完成后,SageMaker可以將模型部署為托管的推理服務,配置API節點,確保高可用性和可擴展性。借助SageMaker,用戶可以無縫地集成機器學習模型到應用程序中,例如通過API Gateway和AWS Lambda來實現實時推理服務。

Amazon SageMaker還具備內置的監控和調優功能,使得模型的性能優化和管理更加高效。無論是初學者還是專業數據科學家,SageMaker都是一種理想的解決方案,幫助企業快速實現人工智能和機器學習的價值。

本方案包括的內容:

本方案主要包括如下內容:

1.?使用Amazon SageMaker部署基礎AI/ML模型(Meta Llama 7B)作為推理的應用節點

2. 在云原生代碼托管服務AWS Lambda部署代碼以調用SageMaker推理。

3.?使用測試應用程序為已部署的模型進行功能測試。

項目搭建具體步驟:

下面跟著小李哥手把手搭建一個亞馬遜云科技AWS上的生成式AI模型(Meta Llama 7B)的軟件應用,并且測試大模型的多種應用場景下的表現。

1. 首先進入SageMarker

2. 點擊進入Jumpstart->Foundation Models,查看目前SageMaker上現有的開源ML模型

3. 進入Studio,點擊已經創建好的“Open Studio”

4. 點擊“Studio Classic”,再點擊右側Open

5. 打開SageMaker Studio控制臺

6. 下載存放在S3中的ML模型工程代碼:

aws s3 sync s3://<Replace with lab-code bucket name> .

7. 配置ML模型訓練、預測的Python工程環境

8. 在第一個代碼單元中更新和安裝SageMaker SDK

!pip install sagemaker --quiet --upgrade --force-reinstall

9. 配置需要的ML開源模型ID和版本(Meta Llama 7B)

model_id, model_version, = ("huggingface-llm-falcon-7b-instruct-bf16","*",
)

10. 創建SageMaker上的API端點,供應用訪問

%%time
from sagemaker.jumpstart.model import JumpStartModelmy_model = JumpStartModel(model_id=model_id,instance_type="ml.g5.2xlarge" )
predictor = my_model.deploy()

項目測試階段:

11. 利用編寫好的模型提示詞,對部署的模型進行問答測試。

%%timeprompt = "Tell me about Amazon SageMaker."payload = {"inputs": prompt,"parameters": {"do_sample": True,"top_p": 0.9,"temperature": 0.8,"max_new_tokens": 1024,"stop": ["<|endoftext|>", "</s>"]}
}response = predictor.predict(payload)
print(response[0]["generated_text"])

得到測試結果

Amazon SageMaker is a machine learning platform provided by Amazon Web Services that enables users to train and deploy machine learning models without having to build, train, and manage a machine learning infrastructure.
CPU times: user 13.5 ms, sys: 6.66 ms, total: 20.1 ms
Wall time: 1.38 s

12. 對大模型代碼生成功能進行測試:


payload = {"inputs": "Write a program to compute factorial in python:", "parameters":{"max_new_tokens": 200}}
query_endpoint(payload)

得到測試結果

 Input: Write a program to compute factorial in python:Output: 
Here is a Python program to compute factorial:```python
def factorial(n):if n == 0:return 1else:return n * factorial(n-1)print(factorial(5)) # Output: 120
```

13. 對大模型進行推理、任務完成能力測試

payload = {"inputs": "Building a website can be done in 10 simple steps:","parameters":{"max_new_tokens": 110,"no_repeat_ngram_size": 3}
}
query_endpoint(payload)

得到測試結果

 Input: Building a website can be done in 10 simple steps:Output: 
1. Choose a domain name
2. Register a domain name
3. Choose a web hosting provider
4. Create a website design
5. Add content to your website
6. Test your website
7. Optimize your website for search engines
8. Promote your website
9. Update your website regularly
10. Monitor your website for security

14. 對大模型代碼進行語言翻譯測試:

payload = {"inputs": """Translate English to French:sea otter => loutre de merpeppermint => menthe poivréeplush girafe => girafe peluchecheese =>""","parameters":{"max_new_tokens": 3}
}query_endpoint(payload)

得到測試結果

 Input: Translate English to French:sea otter => loutre de merpeppermint => menthe poivréeplush girafe => girafe peluchecheese =>Output:  fromage

15. 對大模型的基于文字的情緒分析能力進行測試

payload = {"inputs": """"I hate it when my phone battery dies."Sentiment: Negative###Tweet: "My day has been :+1:"Sentiment: Positive###Tweet: "This is the link to the article"Sentiment: Neutral###Tweet: "This new music video was incredibile"Sentiment:""","parameters": {"max_new_tokens":2}
}
query_endpoint(payload)

得到測試結果

 Input: "I hate it when my phone battery dies."Sentiment: Negative###Tweet: "My day has been :+1:"Sentiment: Positive###Tweet: "This is the link to the article"Sentiment: Neutral###Tweet: "This new music video was incredibile"Sentiment:Output:  Positive

16. 對大模型的問答能力進行測試2

payload = {"inputs": "Could you remind me when was the C programming language invented?","parameters":{"max_new_tokens": 50}
}
query_endpoint(payload)

得到測試結果

 Input: Could you remind me when was the C programming language invented?Output: 
The C programming language was invented in 1972 by Dennis Ritchie at Bell Labs.

17.利用大模型生成食譜

payload = {"inputs": "What is the recipe for a delicious lemon cheesecake?", "parameters":{"max_new_tokens": 400}}
query_endpoint(payload)

得到測試結果

Input: What is the recipe for a delicious lemon cheesecake?Output: 
Here is a recipe for a delicious lemon cheesecake:Ingredients:
- 1 1/2 cups graham cracker crumbs
- 4 tablespoons butter, melted
- 2 (8 ounce) packages cream cheese, softened
- 1/2 cup granulated sugar
- 2 eggs
- 1/2 cup lemon juice
- 1/2 teaspoon salt
- 1/2 teaspoon vanilla extract
- 1/2 cup heavy cream
- 1/2 cup granulated sugar
- 1/2 teaspoon lemon zestInstructions:
1. Preheat oven to 350 degrees F.
2. In a medium bowl, mix together the graham cracker crumbs and melted butter. Press the mixture onto the bottom and sides of a 9-inch springform pan.
3. In a large bowl, beat the cream cheese and sugar until smooth. Add the eggs, lemon juice, salt, vanilla, and heavy cream. Beat until well combined.
4. Pour the mixture into the prepared pan.
5. Bake for 30 minutes or until the cheesecake is set.
6. Let cool for 10 minutes before serving.
7. In a small bowl, mix together the lemon zest and sugar. Sprinkle over the cheesecake before serving.
Step 4.2.7 : Test summarization?

18. 測試大模型的文字總結能力

payload = {"inputs":"""Amazon SageMaker is a fully managed machine learning service. With SageMaker, data scientists and developers can quickly and easily build and train machine learning models, and then directly deploy them into a production-ready hosted environment. It provides an integrated Jupyter authoring notebook instance for easy access to your data sources for exploration and analysis, so you don't have to manage servers. It also provides common machine learning algorithms that are optimized to run efficiently against extremely large data in a distributed environment. With native support for bring-your-own-algorithms and frameworks, SageMaker offers flexible distributed training options that adjust to your specific workflows. Deploy a model into a secure and scalable environment by launching it with a few clicks from SageMaker Studio or the SageMaker console. Summarize the article above:""","parameters":{"max_new_tokens":200}}
query_endpoint(payload)

得到測試結果

 Input: Amazon SageMaker is a fully managed machine learning service. With SageMaker, data scientists and developers can quickly and easily build and train machine learning models, and then directly deploy them into a production-ready hosted environment. It provides an integrated Jupyter authoring notebook instance for easy access to your data sources for exploration and analysis, so you don't have to manage servers. It also provides common machine learning algorithms that are optimized to run efficiently against extremely large data in a distributed environment. With native support for bring-your-own-algorithms and frameworks, SageMaker offers flexible distributed training options that adjust to your specific workflows. Deploy a model into a secure and scalable environment by launching it with a few clicks from SageMaker Studio or the SageMaker console. Summarize the article above:Output:  SageMaker is a cloud-based machine learning platform that provides a range of tools and services to help data scientists and developers build, train, and deploy machine learning models. It offers an integrated Jupyter notebook environment, optimized algorithms, and flexible distributed training options.

19. 完成所有測試后,我們獲取大模型在SageMaker上的URL端點,作為API供應用使用。

以上就是在亞馬遜云科技上部署開源大模型,并且多場景測試的全部步驟。歡迎大家關注小李哥,未來獲取更多國際前沿的生成式AI開發方案。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/44008.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/44008.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/44008.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

802.11漫游流程簡單解析與筆記_Part2_05_wpa_supplicant如何通過nl80211控制內核開始關聯

最近在進行和802.11漫游有關的工作&#xff0c;需要對wpa_supplicant認證流程和漫游過程有更多的了解&#xff0c;所以通過閱讀論文等方式&#xff0c;記錄整理漫游相關知識。Part1將記錄802.11漫游的基本流程、802.11R的基本流程、與認證和漫游都有關的三層秘鑰基礎。Part1將包…

Vue 3與Pinia:下一代狀態管理的探索

引言 隨著Vue 3的推出&#xff0c;Pinia應運而生&#xff0c;成為官方推薦的狀態管理庫&#xff0c;旨在替代Vuex。Pinia與Vuex相比&#xff0c;帶來了以下主要區別和優勢&#xff1a; 更簡潔的API&#xff1a;Pinia的API設計更加直觀和簡潔&#xff0c;易于理解和使用。更好…

220V降5V芯片輸出電壓電流封裝選型WT

220V降5V芯片輸出電壓電流封裝選型WT 220V降5V恒壓推薦&#xff1a;非隔離芯片選型及其應用方案 在考慮220V轉低壓應用方案時&#xff0c;以下非隔離芯片型號及其封裝形式提供了不同的電壓電流輸出能力&#xff1a; 1. WT5101A&#xff08;SOT23-3封裝&#xff09;適用于將2…

【實戰場景】大文件解析入庫的方案有哪些?

【實戰場景】大文件解析入庫的方案有哪些&#xff1f; 開篇詞&#xff1a;干貨篇&#xff1a;分塊解析內存映射文件流式處理數據庫集群處理分布式計算框架 總結篇&#xff1a;我是杰叔叔&#xff0c;一名滬漂的碼農&#xff0c;下期再會&#xff01; 開篇詞&#xff1a; 需求背…

14-57 劍和詩人31 - LLM/SLM 中的高級 RAG

??? 首先確定幾個縮寫的意思 SLM 小模型 LLM 大模型 檢索增強生成 (RAG) 已成為一種增強語言模型能力的強大技術。通過檢索和調整外部知識&#xff0c;RAG 可讓模型生成更準確、更相關、更全面的文本。 RAG 架構主要有三種類型&#xff1a;簡單型、模塊化和高級 RAG&…

性能測試的流程(企業真實流程詳解)(二)

性能測試的流程 1.需求分析以及需求確定(指標值&#xff0c;場景&#xff0c;環境&#xff0c;人員) 一般提出需求的人員有&#xff1a;客戶&#xff0c;產品經理&#xff0c;項目組領導等 2.性能測試計劃和方案制定 基準測試: 負覡測試: 壓力測試: 穩定性測試: 其他:配置測試…

Git安裝使用教程

# 《Git 操作使用教程》 一、Git 簡介 Git 是一個分布式版本控制系統&#xff0c;用于敏捷高效地處理任何或小或大的項目。它讓開發者可以輕松地跟蹤代碼的更改、與團隊成員協作&#xff0c;并管理項目的不同版本。 二、安裝 Git 在 Windows 系統上&#xff0c;可以從 Git 官…

刷題Day47|1143.最長公共子序列、1035.不相交的線、53. 最大子序和、

1143.最長公共子序列 1143. 最長公共子序列 - 力扣&#xff08;LeetCode&#xff09; 思路&#xff1a;dp數組含義是以i-1和j-1為結尾的最長公共子序列。當text1[i - 1] text2[i - 1], dp[i][j] dp[i - 1][j - 1] 1; 否則dp[i][j] max(dp[i - 1][j], dp[i][j - 1]); 因為兩…

無法連接Linux遠程服務器的Mysql,解決辦法

問題描述 如果是關閉虛擬機之后&#xff0c;二次打開無法連接Mysql&#xff0c;則可嘗試一下方法進行解決 解決方法 關閉虛擬機的防火墻 1&#xff1a;查看防火墻狀態 systemctl status firewalld 一下顯示說明防火墻是啟動的狀態 2&#xff1a;關閉防火墻 systemctl st…

git提交emoji指南

emoji 指南 emojiemoji 代碼commit 說明&#x1f389; (慶祝)tada初次提交? (火花)sparkles引入新功能&#x1f516; (書簽)bookmark發行/版本標簽&#x1f41b; (bug)bug修復 bug&#x1f691; (急救車)ambulance重要補丁&#x1f310; (地球)globe_with_meridians國際化與本…

PTA - 編寫函數計算圓面積

題目描述&#xff1a; 1.要求編寫函數getCircleArea(r)計算給定半徑r的圓面積&#xff0c;函數返回圓的面積。 2.要求編寫函數get_rList(n) 輸入n個值放入列表并將列表返回 函數接口定義&#xff1a; getCircleArea(r); get_rList(n); 傳入的參數r表示圓的半徑&#xff0c…

音視頻解封裝demo:將FLV文件解封裝(demux)得到文件中的H264數據和AAC數據(純手工,不依賴第三方開源庫)

1、README 前言 注意&#xff1a;flv是不支持h.265封裝的。目前解封裝功能正常&#xff0c;所得到的H.264文件與AAC文件均可正常播放。 a. demo使用 $ make clean && make DEBUG1 $ $ $ ./flv_demux_h264_aac Usage: ./flv_demux_h264_aac avfile/test1.flv./flv_d…

壓縮感知1——算法簡介

傳統的數據采集 傳統的數字信號采樣定律就是有名的香農采樣定理&#xff0c;又稱那奎斯特采樣定律定理內容如下&#xff1a;為了不失真地恢復模擬信號&#xff0c;采樣頻率應該不小于模擬信號頻譜中最高頻率的2倍 上述步驟得到的數字信號的數據量比較大&#xff0c;一方面不利…

C語言程序題(一)

一.三個整數從大到小輸出 首先做這個題目需要知道理清排序的思路&#xff0c;通過比較三個整數的值&#xff0c;使之從大到小輸出。解這道題有很多方法我就總結了兩種方法&#xff1a;一是通過中間變量比較和交換&#xff0c;二是可以用冒泡排序法&#xff08;雖然三個數字排序…

車載聚合路由器應用場景分析

乾元通QYT-X1z車載式1U多卡聚合路由器&#xff0c;支持最多8路聚合&#xff0c;無論是應急救援&#xff0c;還是車載交通&#xff0c;任何寬帶服務商無法覆蓋的區域&#xff0c;聚合路由器可提供現場需要的穩定、流暢、安全的視頻傳輸網絡&#xff0c;聚合路由器可無縫接入應急…

Dify中的weaviate向量數據庫操作

一.安裝weaviate客戶端 1.Dify 0.6.9中weaviate信息 在Dify 0.6.9版本中weaviate容器信息如下: # The Weaviate vector store. weaviate:image: semitechnologies/weaviate:1.19.0restart: alwaysvolumes:# Mount the Weaviate data directory to the container.- ./volume…

【操作系統】進程管理——信號量機制(個人筆記)

學習日期&#xff1a;2024.7.9 內容摘要&#xff1a;信號量機制&#xff0c;用信號量實現進程的同步與互斥 信號量機制 信號量的概念 在上節內容中&#xff0c;我們學習了進程互斥的軟件和硬件解決方案&#xff0c;但這些方案都有各自的問題&#xff0c;雙標志法都因為檢查和…

【自用】【高昆輪概率論與數理統計筆記】2.1 分布函數的概念與性質

不定期更新&#xff0c;前面的章節會在學完后補回來&#xff0c;重新學學概率&#xff0c;當年考研考的數學二&#xff0c;沒有概率基礎&#xff0c;想自己補補&#xff0c;視頻課是高昆輪老師講的浙大四版概率論教材的視頻課&#xff0c;地址&#xff1a; 第一章&#xff1a;h…

數據庫MySQL---基礎篇

存儲和管理數據的倉庫 MySQL概述 數據庫相關概念 數據庫&#xff08;DataBase&#xff09;---數據存儲的倉庫&#xff0c;數據是有組織的進行存儲 數據庫管理系統&#xff08;DBMS&#xff09;-----操縱和管理數據庫的大型軟件 SQL----操作關系型數據庫的編程語言&#xff…

Python:安裝/Mac

之前一直陸陸續續有學python&#xff01;今天開始&#xff01;正式開肝&#xff01;&#xff01;&#xff01; 進入網站&#xff1a;可能會有點慢&#xff0c;多開幾個網頁 https://www.python.org 點擊下載&#xff0c;然后進入新的頁面&#xff0c;往下滑 來到File&#xff0…