SAGIFY는 AWS SAGEMAKER의 기계 학습 워크 플로를 관리하기위한 단순화 된 인터페이스를 제공하여 인프라가 아닌 ML 모델 구축에 집중할 수 있도록 도와줍니다. 모듈 식 아키텍처에는 LLM 게이트웨이 모듈이 포함되어있어 오픈 소스 및 독점적 인 대형 언어 모델을 모두 활용하기위한 통합 인터페이스를 제공합니다. LLM 게이트웨이는 간단한 API를 통해 다양한 LLM에 액세스하여 워크 플로에 쉽게 통합 할 수 있습니다.
Sagify에 대한 자세한 내용은 다음을 참조하십시오 : 문서 읽기
Sagify에는 다음이 필요합니다.
명령 줄에서 :
pip install sagify
섹션 구성 AWS 계정의 지침에 따라 AWS 계정을 구성하십시오.
마지막으로 다음 명령을 실행하십시오.
sagify cloud foundation-model-deploy --model-id model-txt2img-stabilityai-stable-diffusion-v2-1-base --model-version 1. * -n 1 -e ml.p3.2xlarge --aws-region us-east-1 --aws-profile sagemaker-devEC2 유형 (-e), AWS 영역 및 AWS 프로파일의 값을 선호하는 값으로 변경할 수 있습니다.
안정적인 확산 모델이 배포되면 생성 된 코드 스 니펫을 사용하여 쿼리 할 수 있습니다. 즐기다!
채팅 완료를 위해 다음 모델이 제공됩니다.
| 모델 이름 | URL |
|---|---|
| GPT-4 | https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo |
| GPT-4-32K | https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo |
| GPT-3.5 터보 | https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo |
이미지 생성의 경우 다음 모델에 의존 할 수 있습니다.
| 모델 이름 | URL |
|---|---|
| 달 -E-3 | https://platform.openai.com/docs/models/dall-e |
| Dall-E-2 | https://platform.openai.com/docs/models/dall-e |
그리고 임베딩을 위해 :
| 모델 이름 | URL |
|---|---|
| 텍스트-엠 베딩 -3- 레이지 | https://platform.openai.com/docs/models/embeddings |
| 텍스트 엠 베딩 -3 스몰 | https://platform.openai.com/docs/models/embeddings |
| 텍스트-엠 베딩-아다 -002 | https://platform.openai.com/docs/models/embeddings |
OpenAI에서 지원되는 모든 모델 목록은 sagify llm models --all --provider openai 실행하여 검색 할 수 있습니다. 채팅 완료 모델에만 집중하려면 sagify llm models --chat-completions --provider openai 실행하십시오. 이미지 창작물 및 임베딩의 경우 sagify llm models --image-creations --provider openai 및 sagify llm models --embeddings --provider openai .
채팅 완료를 위해 다음과 같은 오픈 소스 모델이 제공됩니다.
| 모델 이름 | URL |
|---|---|
| llama-2-7b | https://huggingface.co/meta-llama/llama-2-7b |
| LLAMA-2-13B | https://huggingface.co/meta-llama/llama-2-13b |
| LLAMA-2-70B | https://huggingface.co/meta-llama/llama-2-70b |
이미지 생성의 경우 다음 오픈 소스 모델에 의존 할 수 있습니다.
| 모델 이름 | URL |
|---|---|
| 안정성-안정성-확산 -V2 | https://huggingface.co/stability/stable-diffusion-2 |
| 안정성-안정된 확산 -V2-1-베이스 | https://huggingface.co/stableai/stable-diffusion-2-1-Base |
| 안정성-안정-확산 -V2-FP16 | https://huggingface.co/stability/stable-diffusion-2/tree/fp16 |
그리고 임베딩을 위해 :
| 모델 이름 | URL |
|---|---|
| BGE-LARGE-EN | https://huggingface.co/baai/bge-large-en |
| BGE-Base-en | https://huggingface.co/baai/bge-base-en |
| GTE-LARGE | https://huggingface.co/thenlper/gte-large |
| GTE 기반 | https://huggingface.co/thenlper/gte-base |
| E5-LARGE-V2 | https://huggingface.co/intfloat/e5-large-v2 |
| bge-small-en | https://huggingface.co/baai/bge-small-en |
| E5-베이스 -V2 | https://huggingface.co/intfloat/e5-base-v2 |
| 다국어 -E5-Large | https://huggingface.co/intfloat/multingal-e5-large |
| E5-LARGE | https://huggingface.co/intfloat/e5-large |
| gte-small | https://huggingface.co/thenlper/gte-small |
| E5-베이스 | https://huggingface.co/intfloat/e5-base |
| E5-Small-V2 | https://huggingface.co/intfloat/e5-small-v2 |
| 다국어 -E5-베이스 | https://huggingface.co/intfloat/multingal-e5-base |
| 올 미성 L6-V2 | https://huggingface.co/sentence-transformers/all-minilm-l6-v2 |
지원되는 오픈 소스 모델의 모든 목록은 AWS Sagemaker에서 지원되며 명령 sagify llm models --all --provider sagemaker 실행하여 검색 할 수 있습니다. 채팅 완료 모델에만 집중하려면 sagify llm models --chat-completions --provider sagemaker 실행하십시오. 이미지 창작물 및 임베딩의 경우 sagify llm models --image-creations --provider sagemaker 및 sagify llm models --embeddings --provider sagemaker .
LLM 게이트웨이 서버를 시작하기 전에 다음 ENV 변수를 정의해야합니다.
OPENAI_API_KEY : OpenAI API 키. 예 : export OPENAI_API_KEY=... .OPENAI_CHAT_COMPLETIONS_MODEL : 여기 또는 여기에 값 중 하나가 있어야합니다.OPENAI_EMBEDDINGS_MODEL : 여기에는 값 중 하나가 있어야합니다.OPENAI_IMAGE_CREATION_MODEL : 여기에는 값 중 하나가 있어야합니다. 첫 번째 단계는 LLM 모델을 배포하는 것입니다. 모든 백엔드 서비스 (채팅 완료, 이미지 작품, 임베딩) 또는 그 중 일부를 배포하도록 선택할 수 있습니다.
모든 배치를 배포하려면 sagify llm start --all 실행하십시오. 이 명령은 다음 구성으로 모든 백엔드 서비스 (채팅 완료, 이미지 크레오 션, 임베드)를 배포합니다.
{
"chat_completions" : {
"model" : " llama-2-7b " ,
"instance_type" : " ml.g5.2xlarge " ,
"num_instances" : 1 ,
},
"image_creations" : {
"model" : " stabilityai-stable-diffusion-v2-1-base " ,
"instance_type" : " ml.p3.2xlarge " ,
"num_instances" : 1 ,
},
"embeddings" : {
"model" : " gte-small " ,
"instance_type" : " ml.g5.2xlarge " ,
"num_instances" : 1 ,
},
} 자체 구성 파일을 제공 하여이 구성을 변경하면 sagify llm start -all --config YOUR_CONFIG_FILE.json 을 실행할 수 있습니다.
모든 백엔드 서비스를 Sagemaker 엔드 포인트로 배포하는 데 15 ~ 30 분이 걸립니다.
Sagemaker 엔드 포인트 이름 인 배포 된 모델 이름은 인쇄되어 숨겨진 파일 .sagify_llm_infra.json 에 저장됩니다. AWS Sagemaker 웹 콘솔에서 액세스 할 수도 있습니다.
백엔드 플랫폼을 설정하면 FastApi LLM 게이트웨이를 로컬로 배포 할 수 있습니다.
AWS SAGEMAKER 플랫폼을 사용하는 경우 LLM 게이트웨이 서버를 시작하기 전에 다음 ENV 변수를 정의해야합니다.
AWS_ACCESS_KEY_ID : sagify에 로컬로 사용하는 것과 동일 할 수 있습니다. Sagemaker와 S3에 액세스해야합니다. 예 : export AWS_ACCESS_KEY_ID=... .AWS_SECRET_ACCESS_KEY : SAGIFY에 로컬로 사용하는 것과 동일 할 수 있습니다. Sagemaker와 S3에 액세스해야합니다. 예 : export AWS_ACCESS_KEY_ID=... .AWS_REGION_NAME : LLM 백엔드 서비스 (SAGEMAKER 엔드 포인트)가 배포되는 AWS 영역.S3_BUCKET_NAME : S3 버킷 이름 이미지 생성 백엔드 서비스에 의해 생성 된 이미지가 저장됩니다.IMAGE_URL_TTL_IN_SECONDS : 생성 된 이미지에 대한 임시 URL의 초 만에 TTL. 기본값 : 3600.SM_CHAT_COMPLETIONS_MODEL : 채팅 완료 모델이 배포되는 SAGEMAKER 엔드 포인트 이름.SM_EMBEDDINGS_MODEL : Embeddings 모델이 배포되는 Sagemaker 엔드 포인트 이름.SM_IMAGE_CREATION_MODEL : 이미지 생성 모델이 배포되는 SageMaker 엔드 포인트 이름.OpenAI 플랫폼을 사용하는 경우 LLM 게이트웨이 서버를 시작하기 전에 다음 ENV 변수를 정의해야합니다.
OPENAI_API_KEY : OpenAI API 키. 예 : export OPENAI_API_KEY=... .OPENAI_CHAT_COMPLETIONS_MODEL : 여기 또는 여기에 값 중 하나가 있어야합니다.OPENAI_EMBEDDINGS_MODEL : 여기에는 값 중 하나가 있어야합니다.OPENAI_IMAGE_CREATION_MODEL : 여기에는 값 중 하나가 있어야합니다. 이제 sagify llm gateway --image sagify-llm-gateway:v0.1.0 --start-local LLM 게이트웨이를 로컬로 시작할 수 있습니다. --image 인수를 통해 이미지의 이름을 변경할 수 있습니다.
이 명령은 Docker 컨테이너 ID를 출력합니다. docker stop <CONTAINER_ID> 실행하여 컨테이너를 중지 할 수 있습니다.
예
( 먼저 필요한 모든 환경 변수를 먼저 내보내십시오 )
Docker 이미지를 만들고 실행하려는 경우
sagify llm gateway --image sagify-llm-gateway:v0.1.0 --start-local
사용하려면 이미지를 작성하십시오
sagify llm gateway --image sagify-llm-gateway:v0.1.0
두 플랫폼 (OpenAI 및 AWS Sagemaker)을 모두 지원하려면 두 플랫폼의 모든 ENV 변수를 전달하십시오.
LLM 게이트웨이를 AWS Fargate에 배치하려는 경우 다음과 같은 일반 단계를 수행 할 수 있습니다.
다음은 5 가지 환경 변수를 가진 AWS Fargate에 FastApi 서비스를 배포하기위한 CloudFormation 템플릿의 예입니다.
Resources :
MyFargateTaskDefinition :
Type : AWS::ECS::TaskDefinition
Properties :
Family : my-fargate-task
ContainerDefinitions :
- Name : fastapi-container
Image : <YOUR_ECR_REPOSITORY_URI>
Memory : 512
PortMappings :
- ContainerPort : 80
Environment :
- Name : AWS_ACCESS_KEY_ID
Value : " value1 "
- Name : AWS_SECRET_ACCESS_KEY
Value : " value2 "
- Name : AWS_REGION_NAME
Value : " value3 "
- Name : S3_BUCKET_NAME
Value : " value4 "
- Name : IMAGE_URL_TTL_IN_SECONDS
Value : " value5 "
- Name : SM_CHAT_COMPLETIONS_MODEL
Value : " value6 "
- Name : SM_EMBEDDINGS_MODEL
Value : " value7 "
- Name : SM_IMAGE_CREATION_MODEL
Value : " value8 "
- Name : OPENAI_CHAT_COMPLETIONS_MODEL
Value : " value9 "
- Name : OPENAI_EMBEDDINGS_MODEL
Value : " value10 "
- Name : OPENAI_IMAGE_CREATION_MODEL
Value : " value11 "
MyFargateService :
Type : AWS::ECS::Service
Properties :
Cluster : default
TaskDefinition : !Ref MyFargateTaskDefinition
DesiredCount : 2
LaunchType : FARGATE
NetworkConfiguration :
AwsvpcConfiguration :
Subnets :
- <YOUR_SUBNET_ID>
SecurityGroups :
- <YOUR_SECURITY_GROUP_ID> LLM 게이트웨이가 배포되면 HOST_NAME/docs 에서 액세스 할 수 있습니다.
curl --location --request POST ' /v1/chat/completions '
--header ' Content-Type: application/json '
--data-raw ' {
"provider": "sagemaker",
"messages": [
{
"role": "system",
"content": "you are a cook"
},
{
"role": "user",
"content": "what is the recipe of mayonnaise"
}
],
"temperature": 0,
"max_tokens": 600,
"top_p": 0.9,
"seed": 32
} '예제 응답
200 응답
{
"id" : " chatcmpl-8167b99c-f22b-4e04-8e26-4ca06d58dc86 " ,
"object" : " chat.completion " ,
"created" : 1708765682 ,
"provider" : " sagemaker " ,
"model" : " meta-textgeneration-llama-2-7b-f-2024-02-24-08-49-32-123 " ,
"choices" : [
{
"index" : 0 ,
"message" : {
"role" : " assistant " ,
"content": " Ah, a fellow foodie! Mayonnaise is a classic condiment that's easy to make and can elevate any dish. Here's my trusty recipe for homemade mayonnaise:nnIngredients:nn* 2 egg yolksn* 1/2 cup (120 ml) neutral-tasting oil, such as canola or grapeseedn* 1 tablespoon lemon juice or vinegarn* Salt and pepper to tastennInstructions:nn1. In a small bowl, whisk together the egg yolks and lemon juice or vinegar until well combined.n2. Slowly pour in the oil while continuously whisking the mixture. You can do this by hand with a whisk or use an electric mixer on low speed.n3. Continue whisking until the mixture thickens and emulsifies, which should take about 5-7 minutes. You'll know it's ready when it reaches a thick, creamy consistency.n4. Taste and adjust the seasoning as needed. You can add more salt, pepper, or lemon juice to taste.n5. Transfer the mayonnaise to a jar or airtight container and store it in the fridge for up to 1 week.nnThat's it! Homemade mayonnaise is a great way to control the ingredients and flavor, and it's also a fun kitchen experiment. Enjoy!"
}
}
]
}curl --location --request POST ' /v1/embeddings '
--header ' Content-Type: application/json '
--data-raw ' {
"provider": "sagemaker",
"input": [
"The mayonnaise was delicious"
]
} '예제 응답
200 응답
{
"data" : [
{
"object" : " embedding " ,
"embedding" : [
-0.04274585098028183 ,
0.021814687177538872 ,
-0.004705613013356924 ,
...
-0.07548460364341736 ,
0.036427777260541916 ,
0.016453085467219353 ,
0.004641987383365631 ,
-0.0072729517705738544 ,
0.02343473769724369 ,
-0.002924458822235465 ,
0.0339619480073452 ,
0.005262510851025581 ,
-0.06709178537130356 ,
-0.015170316211879253 ,
-0.04612169787287712 ,
-0.012380547821521759 ,
-0.006663458421826363 ,
-0.0573800653219223 ,
0.007938326336443424 ,
0.03486081212759018 ,
0.021514462307095528
],
"index" : 0
}
],
"provider" : " sagemaker " ,
"model" : " hf-sentencesimilarity-gte-small-2024-02-24-09-24-27-341 " ,
"object" : " list "
}curl --location --request POST ' /v1/images/generations '
--header ' Content-Type: application/json '
--data-raw ' {
"provider": "sagemaker",
"prompt":
"A baby sea otter"
,
"n": 1,
"width": 512,
"height": 512,
"seed": 32,
"response_format": "url"
} '예제 응답
200 응답
{
"provider" : " sagemaker " ,
"model" : " stable-diffusion-v2-1-base-2024-02-24-11-43-32-177 " ,
"created" : 1708775601 ,
"data" : [
{
"url" : " https://your-bucket.s3.amazonaws.com/31cedd17-ccd7-4cba-8dea-cb7e8b915782.png?AWSAccessKeyId=AKIAUKEQBDHITP26MLXH&Signature=%2Fd1J%2FUjOWbRnP5cwtkSzYUVoEoo%3D&Expires=1708779204 "
}
]
}이메일 : [email protected]
우리는 그들 모두를 지배 할 단일 LLM이 없다는 것을 깨달았습니다!