在亚马逊云科技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://xiahunao.cn/news/3224723.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

VBA实现Excel的数据透视表

前言 本节会介绍通过VBA的PivotCaches.Create方法实现Excel创建新的数据透视表、修改原有的数据透视表的数据源以及刷新数据透视表内容。 本节测试内容以下表信息为例 1、创建数据透视表 语法&#xff1a;PivotCaches.Create(SourceType, [SourceData], [Version]) 说明&am…

C语言程序题(一)

一.三个整数从大到小输出 首先做这个题目需要知道理清排序的思路&#xff0c;通过比较三个整数的值&#xff0c;使之从大到小输出。解这道题有很多方法我就总结了两种方法&#xff1a;一是通过中间变量比较和交换&#xff0c;二是可以用冒泡排序法&#xff08;虽然三个数字排序…

【重大消息】报告称OpenAI的产品可经由微软的服务提供给中国客户

尽管OpenAI正在采取措施限制中国用户访问其平台&#xff0c;但一份最新报告称&#xff0c;中国用户仍可通过微软的Azure云计算平台访问该公司的产品。微软和OpenAI有着密切的合作关系&#xff0c;前者通过人工智能功能获得了独家产品访问权以拓展企业计算。最新的报道来自《The…

秋招突击——7/9——复习{Java实现——LRU,Java实现——搜索插入位置}——新作{二分查找——搜索二维矩阵}

文章目录 引言复习Java实现——LRU缓存对照实现 Java实现——搜索插入位置java实现知识补充 新作搜索二维矩阵个人实现参考实现 总结 引言 以后都要向使用Java刷算法进行过滤了&#xff0c;所以今天主要是复习为主&#xff0c;复习两道之前做过的题目&#xff0c;然后做两道新…

STM32智能交通灯控制系统教程

目录 引言环境准备智能交通灯控制系统基础代码实现&#xff1a;实现智能交通灯控制系统 4.1 数据采集模块 4.2 数据处理与控制算法 4.3 通信与网络系统实现 4.4 用户界面与数据可视化应用场景&#xff1a;交通灯管理与优化问题解决方案与优化收尾与总结 1. 引言 智能交通灯控…

迅狐抖音机构号授权矩阵系统源码

在数字化营销的浪潮中&#xff0c;抖音以其独特的短视频形式迅速崛起&#xff0c;成为品牌传播和用户互动的重要平台。迅狐抖音机构号授权矩阵系统源码作为一项创新技术&#xff0c;为品牌在抖音上的深度运营提供了强大支持。 迅狐抖音机构号授权矩阵系统源码简介 迅狐抖音机…

Hadoop-20 Flume 采集数据双写至本地+HDFS中 监控目录变化 3个Agent MemoryChannel Source对比

章节内容 上一节完成了如下的内容&#xff1a; 编写Agent Conf配置文件收集Hive数据汇聚到HDFS中测试效果 背景介绍 这里是三台公网云服务器&#xff0c;每台 2C4G&#xff0c;搭建一个Hadoop的学习环境&#xff0c;供我学习。 之前已经在 VM 虚拟机上搭建过一次&#xff0…

【动态规划Ⅵ】背包问题 /// 组合问题

背包问题 什么是背包问题0-1背包问题分数背包完全背包问题重复背包问题 背包问题例题416. 分割等和子集474. 一和零 完全平方数279. 完全平方数322. 零钱兑换 排列与组合组合&#xff0c;无重复&#xff1a;518. 零钱兑换 II排列&#xff0c;可重复&#xff1a;377. 组合总和 Ⅳ…

【效率提升】多功能组织和整理软件一Notion

Notion下载地址&#xff1a;https://www.notion.so/desktop Notion 是一款多功能办公软件&#xff0c;非常适合进行知识整理、团队协作、项目整理等。 下面是几个我推荐Notion的关键点&#xff1a; 一、排版高度自由&#xff1a;Notion的页面可以嵌套&#xff0c;在页面中还支…

Games101——光珊化——深度缓存——shading着色 1

深度缓存 如何解决远近的问题&#xff0c;能正确的覆盖 按照画作来说&#xff0c;先画出远处的物体&#xff0c;再画出近处的物体&#xff0c;近处会将其覆盖&#xff0c;这种算法叫做画家算法 但事实上&#xff0c;排序不仅要花更多的时间&#xff0c;而且排序并不容易&…

apache:the requested operation has failed使用httpd -t

Apache24\bin cmd 回车 httpd -t 因为我重新压缩了&#xff0c;记住&#xff0c;重新压缩要使用原路径&#xff0c; 因为你安装的 时候使用的是原路径 还是不行就改个端口&#xff0c;切记修改配置文件httpd.conf先把Tomcat停了 Define SRVROOT "F:\Apache\Apache24&q…

“Numpy数据分析与挖掘:高效学习重点技能“

目录 # 开篇 # 补充 zeros & ones eye 1. numpy数组的创建 1.1 array 1.2 range 1.3 arange 1.4 常见的数据类型 1.5 astype 1.6 random.random() & round 2. numpy数组计算和数组计算 2.1 reshape 2.2 shape 2.3 将一维数组变成多维数组 2.4 指定一维…

生产者消费者模型和线程同步问题

文章目录 线程同步概念生产者消费者模型条件变量使用条件变量唤醒条件变量 阻塞队列 线程同步概念 互斥能保证安全,但是仅有安全不够,同步可以更高效的使用资源 生产者消费者模型 下面就基于生产者消费者来深入线程同步等概念: 如何理解生产消费者模型: 以函数调用为例: 两…

14-58 剑和诗人32 - 使用矢量数据库增强 LLM 应用程序

GPT-4、Bloom、LaMDA 等大型语言模型 (LLM) 在生成类似人类的文本方面表现出了令人印象深刻的能力。然而,它们在事实准确性和推理能力等方面仍然面临限制。这是因为,虽然它们的基础是从大量文本数据中提取统计模式,但它们缺乏结构化的知识源来为其输出提供依据。 最近,我们…

红日靶场----(三)漏洞利用

上期已经信息收集阶段已经完成&#xff0c;接下来是漏洞利用。 靶场思路 通过信息收集得到两个吧靶场的思路 1、http://192.168.195.33/phpmyadmin/&#xff08;数据库的管理界面&#xff09; root/root 2、http://192.168.195.33/yxcms/index.php?radmin/index/login&am…

(自用)gtest单元测试

gtest是Google的一套用于编写C测试的框架&#xff0c;可以运行在很多平台上&#xff08;包括Linux、Mac OS X、Windows、Cygwin等等&#xff09;。基于xUnit架构。支持很多好用的特性&#xff0c;包括自动识别测试、丰富的断言、断言自定义、死亡测试、非终止的失败、生成XML报…

Python | Leetcode Python题解之第225题用队列实现栈

题目&#xff1a; 题解&#xff1a; class MyStack:def __init__(self):"""Initialize your data structure here."""self.queue collections.deque()def push(self, x: int) -> None:"""Push element x onto stack."&…

14-59 剑和诗人33 - 端到端的LLMOps平台建设

​​​​ GPT-4、LlaMA、Falcon、Claude、Cohere、PaLM 等大型语言模型 (LLM) 已展示出强大的自然语言生成、推理、摘要、翻译等功能。然而&#xff0c;要有效利用这些模型来构建自定义应用程序&#xff0c;需要克服非同小可的机器学习工程挑战。 LLMOps 旨在提供一个精简的平…

从零开始学习嵌入式----C语言框架梳理与后期规划

目录 一、环境搭建. 二、见解 三、C语言框架梳理 四、嵌入式学习规划流程图&#xff08;学习顺序可能有变&#xff09; 一、环境搭建. C语言是一门编程语言&#xff0c;在学习的时候要准备好环境。我个人比较喜欢用VS,具体怎么安装请百度。学习C语言的时候&#xff0c;切忌…

clean code-代码整洁之道 阅读笔记(第十七章 终章)

大纲 第十七章 味道与启发 17.1 注释 C1&#xff1a;不恰当的信息 C2&#xff1a;废弃的注释 C3&#xff1a;冗余注释 C4&#xff1a;糟糕的注释 C5&#xff1a;注释掉的代码 17.2 环境 E1&#xff1a;需要多步才能实现的构建 E2&#xff1a;需要多步才能做到的测试 …