在亚马逊云科技AWS上利用SageMaker机器学习模型平台搭建生成式AI应用(附Llama大模型部署和测试代码)

news2024/10/1 20:16:03

项目简介:

接下来,小李哥将会每天介绍一个基于亚马逊云科技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.coloradmin.cn/o/1912617.html

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

相关文章

Jmeter在信息头中设置Bearer与 token 的拼接值

思路&#xff1a;先获取token&#xff0c;将token设置成全局变量&#xff0c;再与Bearer拼接。 第一步&#xff1a;使用提取器将token值提取出来&#xff0c;使用setProperty函数将提取的token值设置成全局变量&#xff0c;在登录请求后面添加BeanShell取样器 或者 BeanShell后…

嘉立创EDA学习笔记

嘉立创EDA学习笔记 PCB引线一、设计规则间距安全间距其他间距 物理导线网络长度差分对过孔尺寸 平面铺铜 PCB布线 作为一个嵌入式开发潜力工程师&#xff0c;咱们必须得学会如何绘制开发板以满足顾客各种功能的需求&#xff0c;因此小编去学习了一下嘉立创&#xff0c;写这篇文…

配网行波故障预警与定位装置:配电线路安全性与可靠性的保障

配网行波故障预警与定位装置&#xff1a;配电线路安全性与可靠性的保障 一、传统配网故障排查的困境 1. 巡检效率低下&#xff1a;在二十世纪80年代及以前&#xff0c;电力线路故障的排查主要依赖于人工巡检&#xff0c;这种方式效率低下&#xff0c;特别是在故障区间较大的情…

Seata解决分布式事务

我举的例子是&#xff1a;在网上购物时&#xff0c;我们支付后&#xff0c;订单微服务会更新订单状态&#xff0c;同时会远程调用购物车微服务清空购物车&#xff0c;和调用商品微服务完成商品库存减一。 我们曾经说的事务是只能在本微服务完成回滚&#xff0c;意思就是如果过…

PHP全域旅游景区导览系统源码小程序

&#x1f30d;【探索无界&#xff0c;畅游无忧】全域旅游景区导览系统小程序全攻略 &#x1f4f1;【一键启动&#xff0c;智能导览在手】 告别纸质地图的繁琐&#xff0c;迎接全域旅游景区导览系统小程序的便捷时代&#xff01;只需轻轻一点&#xff0c;手机瞬间变身私人导游…

如何快速将Excel定义的表结构转换为MySQL的建表语句

目录 引言 方法一&#xff1a;使用Python编程 步骤一&#xff1a;安装必要的库 步骤二&#xff1a;读取Excel文件 步骤三&#xff1a;编写函数生成建表语句 注意事项 方法二&#xff1a;使用Excel VBA 步骤一&#xff1a;启用VBA编辑器 步骤二&#xff1a;编写VBA代码…

通过git将文件push到github 远程仓库

1.先git clone 代码地址 git clone htttp://github.com/用户名/test.git 2. 添加文件 例如&#xff1a;touch 1.txt 3.将文件添加到暂存区 git add 1.txt 4.提交 git commit -m "commit 1.txt" 5.与远程仓库建立关联 git remote add 远程仓库名 远程仓库…

文件操作和IO流(Java版)

前言 我们无时无刻不在操作文件。可以说&#xff0c;我们在电脑上能看到的图片、视频、音频、文档都是一个又一个的文件&#xff0c;我们需要从文件中读取我们需要的数据&#xff0c;将数据运算后也需要将结果写入文件中长期保存。可见文件的重要性&#xff0c;今天我们就来简…

泛微E-Cology getFileViewUrl SSRF漏洞复现

0x01 产品简介 泛微协同管理应用平台e-cology是一套兼具企业信息门户、知识文档管理、工作流程管理、人力资源管理、客户关系管理、项目管理、财务管理、资产管理、供应链管理、数据中心功能的企业大型协同管理平台。 0x02 漏洞概述 泛微E-Cology getFileViewUrl 接口处存在…

[安洵杯 2019]easy_serialize_php

源码&#xff1a; <?php$function $_GET[f];function filter($img){$filter_arr array(php,flag,php5,php4,fl1g);$filter /.implode(|,$filter_arr)./i;return preg_replace($filter,,$img); }if($_SESSION){unset($_SESSION); }$_SESSION["user"] guest; …

0010基于免疫遗传算法的配送中心选址

免疫优化算法&#xff08;Immune Optimization Algorithm, IOA&#xff09;在物流配送中心选址中的应用是通过模拟免疫系统的进化过程来解决选址优化问题。物流配送中心选址问题涉及到如何在给定区域内选择最优的位置&#xff0c;以最大化服务覆盖并最小化运输成本。 免疫优化…

神经网络设计过程

1.可根据Iris特征直接判断 2.神经网络方法&#xff0c;采集大量的Iris特征&#xff0c;分类对应标签&#xff0c;构成数据集。 将数据集喂入搭好的神经网络结构&#xff0c;网络通过反向传播优化参数得到模型。 有新的网络送入到模型里&#xff0c;模型会给出识别结果。 3.…

PHP7.4安装使用rabbitMQ教程(windows)

&#xff08;1&#xff09;&#xff0c;安装rabbitMQ客户端erlang语言 一&#xff0c;erlang语言安装 下载地址1—— 下载地址2——https://www.erlang.org/patches/otp-27.0 二&#xff0c;rabbitMQ客户端安装 https://www.rabbitmq.com/docs/install-windows &#xff08…

【JavaEE】 简单认识CPU

&#x1f435;本篇文章将对cpu的相关知识进行讲解 一、认识CPU 下图是简略的冯诺依曼体系结构图 上图中&#xff0c;存储器用来存储数据&#xff0c;注意在存储器中都是以二进制的形式存储数据的&#xff0c;CPU就是中央处理器&#xff0c;其功能主要是进行各种算术运算和各种…

【保姆级教程】CenterNet的目标检测、3D检测、关键点检测使用教程

一、代码下载 仓库地址:https://github.com/xingyizhou/CenterNet?tab=readme-ov-file 二、目标检测 2.1 下载预训练权重 下载预训练权重ctdet_coco_dla_2x.pth放到models文件夹下 下载链接:https://drive.google.com/file/d/18Q3fzzAsha_3Qid6mn4jcIFPeOGUaj1d/edit …

基于 sftp 的 NAS (局域网文件存储服务器)

局域网 NAS (文件存储服务器) 的基本功能有: 能够存储文件, 同时能够通过多个设备访问 (上传/下载) 文件. 这些功能通过 sftp 可以实现. sftp 是基于 SSH 的文件传输协议, SSH 全程加密传输, 使用 公钥 认证 (不使用密码/口令), 能够提供很高的安全性. 上文说到, 在 LVM 和 bt…

存储产品选型策略 OSS生命周期管理与运维

最近在看阿里云的 云存储通关实践认证训练营这个课程还是不错的。 存储产品选型策略、对象存储OSS入门、基于对象存储OSS快速搭建网盘、 如何做好权限控制、如何做好数据安全、如何做好数据管理、涉及对象存储OSS的权限控制、使用OSS完成静态网站托管、对OSS中存储的数据进行分…

《植物大战僵尸杂交版》2.2版本:全新内容与下载指南

《植物大战僵尸杂交版》2.2版本已经火热更新&#xff0c;带来了一系列令人兴奋的新玩法和调整&#xff0c;为这款经典的塔防游戏注入了新的活力。如果你是《植物大战僵尸》系列的忠实粉丝&#xff0c;那么这个版本绝对值得你一探究竟。 2.2版本更新亮点 新增看星星玩法 这个新…

QT学习日记一

创建QT文件步骤 这是创建之后widget.cpp和widget.h文件的具体代码解释&#xff0c;也是主要操作的文件&#xff0c;其中main.cpp不用操作&#xff0c;ui则是图形化操作界面&#xff0c;综合使用时&#xff0c;添加一个元件要注意重编名和编译一下&#xff0c;才能在widget这类…

tomcat 项目迁移,无法将项目作为服务service启动

背景 测试服务器需要迁移到正式服务器上&#xff0c;为了方便省事&#xff0c;将测试服务器上的一些文件直接复制到正式服务器 问题 使用startup启动项目之后&#xff0c;可以直接使用使用tomcat9w启动&#xff0c;或者作为服务service启动的时候&#xff0c;显示无法访问到资源…