在亚马逊云科技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 JumpStartModel

my_model = JumpStartModel(model_id=model_id,instance_type="ml.g5.2xlarge" )
predictor = my_model.deploy()

项目测试阶段:

11. 利用编写好的模型提示词,对部署的模型进行问答测试。

%%time


prompt = "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 1
    else:
        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 mer

    peppermint => menthe poivrée

    plush girafe => girafe peluche

    cheese =>""",
    "parameters":{
        "max_new_tokens": 3
    }
}

query_endpoint(payload)

得到测试结果

 Input: Translate English to French:

    sea otter => loutre de mer

    peppermint => menthe poivrée

    plush girafe => girafe peluche

    cheese =>
 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 zest

Instructions:
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.mfbz.cn/a/789544.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【割点 C++BFS】2556. 二进制矩阵中翻转最多一次使路径不连通

本文涉及知识点 割点 图论知识汇总 CBFS算法 LeetCode2556. 二进制矩阵中翻转最多一次使路径不连通 给你一个下标从 0 开始的 m x n 二进制 矩阵 grid 。你可以从一个格子 (row, col) 移动到格子 (row 1, col) 或者 (row, col 1) &#xff0c;前提是前往的格子值为 1 。如…

【经典链表OJ】环形链表

一、题目要求 给你一个链表的头节点 head &#xff0c;判断链表中是否有环。如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测系统内部使用整数 pos 来表示链表尾连接到链表中的位置&…

NSAT-8000电源检测软件测试砖式电源模块的方案及优势

砖式电源模块类型 砖式电源&#xff0c;顾名思义其外观尺寸像块砖&#xff0c;具有体积小、功率大、安装方便等特点。砖式电源模块具备高可靠性和高稳定性&#xff0c;能够为设备提供稳定的电力输出&#xff0c;在通信、工业、医疗等领域广泛应用。 根据尺寸大小&#xff0c;砖…

《WebGIS快速开发教程》第7版发布

老规矩先看封面&#xff1a; 可以看到我们在封面上加了“classic”的字样&#xff0c;这意味着第7版将会是经典版本&#xff0c;或者说具有里程碑意义的一个版本。 拿到新书我们可以看到第7版的整体风格是以“业务场景”为核心&#xff0c;所有讲解的知识点和案例都是围绕着业…

window下载安装clang

执行clang报错&#xff1a; c:/>clang test.cclang: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found] clang: error: unable to execute command: program not executable clang: error: li…

【北京迅为】《i.MX8MM嵌入式Linux开发指南》-第一篇 嵌入式Linux入门篇-第十七章 Linux 环境变量

i.MX8MM处理器采用了先进的14LPCFinFET工艺&#xff0c;提供更快的速度和更高的电源效率;四核Cortex-A53&#xff0c;单核Cortex-M4&#xff0c;多达五个内核 &#xff0c;主频高达1.8GHz&#xff0c;2G DDR4内存、8G EMMC存储。千兆工业级以太网、MIPI-DSI、USB HOST、WIFI/BT…

【竞技宝 】欧洲杯:赛事水货盘点

本届欧洲杯接近尾声,有些球员抓住机会趁势崛起,踢出了身价。可惜还有一些球员的表现无法让球迷和媒体满意,下面我们就来盘点下本届欧洲杯的水货球员,看看哪些人因为糟糕的表现上榜? 格瓦迪奥尔(克罗地亚) 本届欧洲杯是克罗地亚黄金一代球员的谢幕之战,原本格瓦迪奥尔作为球队…

24/07/08数据结构(2.1203)顺序表实现

size属于结构体的作用域 如果要访问一个结构体的指针用-> 如果要访问一个结构体的变量用. 点操作 #include<stdio.h> #include<stdlib.h> #include<string.h> #include"seqlist.h" //typedef struct seqList{ // SLDataType* _data; //需…

重磅来袭!MoneyPrinterPlus一键发布短视频到视频号,抖音,快手,小红书上线了

MoneyPrinterPlus开源有一段时间了&#xff0c;已经实现了批量短视频混剪&#xff0c;一键生成短视频等功能。 有些小伙伴说了&#xff0c;我批量生成的短视频能不能一键上传到视频号,抖音,快手,小红书这些视频平台呢&#xff1f;答案是必须可以。 下面上干货。 软件准备 当…

【Android】基于 LocationManager 原生实现定位打卡

目录 前言一、实现效果二、定位原理三、具体实现1. 获取权限2. 页面绘制3. 获取经纬度4. 方法调用5. 坐标转换6. 距离计算7. 完整代码 前言 最近公司有个新需求&#xff0c;想要用定位进行考勤打卡&#xff0c;在距离打卡地一定范围内才可以进行打卡。本文将借鉴 RxTool 的 Rx…

sdwan是硬件还是网络协议?

SD-WAN&#xff08;Software-Defined Wide Area Network&#xff0c;软件定义广域网&#xff09;并不是一个硬件产品或单一的网络协议&#xff0c;而是结合了软件、硬件和网络技术的一种解决方案。SD-WAN的核心在于其软件定义的特性&#xff0c;它通过软件来控制和管理广域网的…

如何压缩pdf文件大小,怎么压缩pdf文件大小

在数字化时代&#xff0c;pdf文件因其稳定的格式和跨平台兼容性&#xff0c;成为了工作与学习中不可或缺的一部分。然而&#xff0c;随着pdf文件内容的丰富&#xff0c;pdf文件的体积也随之增大&#xff0c;给传输和存储带来了不少挑战。本文将深入探讨如何高效压缩pdf文件大小…

@RequestPart 与 @RequestBody、@RequestParam 注解的异同点

前言 RequestPart 注解是我们在JavaEE 开发中&#xff0c;比较常见的一个注解。它经常会与 RequestBody 、RequestParam 注解进行比较&#xff0c;这篇博文我们以案例和源码相结合&#xff0c;分析这几个注解的异同点。 案例演示 创建实体类 User Data NoArgsConstructor A…

Python requests爬虫

Python的requests库是一个强大且易于使用的HTTP库&#xff0c;用于发送HTTP请求和处理响应。它是Python中最受欢迎的网络爬虫框架之一&#xff0c;被广泛用于从网页中提取数据、爬取网站和进行API调用。 使用requests库&#xff0c;你可以轻松地发送各种HTTP请求&#xff0c;包…

提示词工程(Prompt Engineering)是什么?

一、定义 Prompt Engineering 提示词工程&#xff08;Prompt Engineering&#xff09;是一项通过优化提示词&#xff08;Prompt&#xff09;和生成策略&#xff0c;从而获得更好的模型返回结果的工程技术。 二、System message 系统指令 System message可以被广泛应用在&am…

linux自动化内存监控与告警

文章目录 前言一、脚本实现1. shell脚本实现2. 脚本功能概览 二、设置定时执行1. 编辑cron任务表2. 设置定时任务 三、通知结果示例总结 前言 在当今数字化与网络化日益普及的时代&#xff0c;系统管理与维护成为了确保业务连续性和数据安全的关键环节。其中&#xff0c;监控系…

大模型时代:人工智能与大数据平台的深度融合

在当今的大数据时代&#xff0c;数据已经成为驱动业务增长和创新的关键因素。与此同时&#xff0c;随着人工智能技术的不断进步&#xff0c;AI在大规模数据处理和分析方面的能力日益强大。因此&#xff0c;将人工智能与大数据平台相结合&#xff0c;可以为企业带来巨大的商业价…

linux信息收集与提权

目录 版本信息收集 kali得一些exp网站 kali自带的searchsploit工具 脏牛提权漏洞&#xff08;改写没有写权限的文件&#xff09; 测试靶场下载链接 sudo提权 上传恶意C脚本进行编译生成dirty的elf文件&#xff0c;也可以在攻击机编译好上传 启动&#xff0c;123456是设…

网站地址显示不安全怎么办

当网址栏显示不安全时&#xff0c;通常是因为网站使用的是HTTP而不是HTTPS协议&#xff0c;或者因为网站的SSL证书存在问题。以下是一些解决方法&#xff1a;1、迁移到HTTPS&#xff1a;如果您是网站所有者&#xff0c;最好的解决方法是将网站迁移到HTTPS。HTTPS通过使用SSL/TL…

室内精准定位是什么?室内精准定位的方式有哪些?

说到室内精准定位很多人可能会比较陌生&#xff0c;因为这一说法并没有大范围推广&#xff0c;又或者说只是很多相关行业的人才知道这样的说法。但是定位这一问题大家都知道吧&#xff1f;尤其是要到一个地方去&#xff0c;都会进行定位导航。那么这一般都是户外定位&#xff0…