Sagify ให้อินเทอร์เฟซที่ง่ายขึ้นในการจัดการเวิร์กโฟลว์การเรียนรู้ของเครื่องบน AWS Sagemaker ช่วยให้คุณมุ่งเน้นไปที่การสร้างโมเดล ML มากกว่าโครงสร้างพื้นฐาน สถาปัตยกรรมแบบแยกส่วนของมันรวมถึงโมดูล LLM Gateway เพื่อให้อินเทอร์เฟซแบบครบวงจรสำหรับการใช้ประโยชน์จากแบบจำลองภาษาโอเพนซอร์สและโมเดลขนาดใหญ่ที่เป็นกรรมสิทธิ์ LLM Gateway ให้การเข้าถึง LLMs ต่างๆผ่าน API ที่เรียบง่ายช่วยให้คุณรวมเข้ากับเวิร์กโฟลว์ของคุณได้อย่างง่ายดาย
สำหรับการอ้างอิงโดยละเอียดเพื่อ 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-devคุณสามารถเปลี่ยนค่าสำหรับประเภท EC2 (-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-turbo | https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo |
สำหรับการสร้างภาพคุณสามารถพึ่งพารุ่นต่อไปนี้:
| ชื่อนางแบบ | url |
|---|---|
| Dall-e-3 | https://platform.openai.com/docs/models/dall-e |
| Dall-e-2 | https://platform.openai.com/docs/models/dall-e |
และสำหรับการฝัง:
| ชื่อนางแบบ | url |
|---|---|
| Text-Embedding-3 ใหญ่ | https://platform.openai.com/docs/models/embeddings |
| Text-Embedding-3-small | https://platform.openai.com/docs/models/embeddings |
| Text-Embedding-ADA-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 |
|---|---|
| เสถียรภาพ-เสถียร -Tiffusion-V2 | https://huggingface.co/stabilityai/stable-diffusion-2 |
| เสถียรภาพความเสถียร -Tiffusion-V2-1-base | https://huggingface.co/stabilityai/stable-diffusion-2-1-base |
| เสถียรภาพความเสถียร -Tiffusion-V2-FP16 | https://huggingface.co/stabilityai/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 |
| ขนาดใหญ่ | https://huggingface.co/thenlper/gte-large |
| ฐาน GTE | https://huggingface.co/thenlper/gte-base |
| E5 ขนาดใหญ่ -v2 | https://huggingface.co/intfloat/e5-large-v2 |
| BGE-SMALL-EN | https://huggingface.co/baai/bge-small-en |
| E5-base-V2 | https://huggingface.co/intfloat/e5-base-v2 |
| หลายภาษา-E5 ขนาดใหญ่ | https://huggingface.co/intfloat/multilingual-e5-large |
| E5 ขนาดใหญ่ | https://huggingface.co/intfloat/e5-large |
| Gte-small | https://huggingface.co/thenlper/gte-small |
| E5-base | https://huggingface.co/intfloat/e5-base |
| E5-SMALL-V2 | https://huggingface.co/intfloat/e5-small-v2 |
| หลายภาษา-E5-base | https://huggingface.co/intfloat/multilingual-e5-base |
| All-Minilm-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 ตามลำดับ
คุณต้องกำหนดตัวแปร Env ต่อไปนี้ก่อนที่จะเริ่มเซิร์ฟเวอร์ LLM Gateway:
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
ใช้เวลา 15 ถึง 30 นาทีในการปรับใช้บริการแบ็กเอนด์ทั้งหมดเป็นจุดสิ้นสุดของ Sagemaker
ชื่อโมเดลที่ปรับใช้ซึ่งเป็นชื่อจุดสิ้นสุดของ Sagemaker ถูกพิมพ์ออกมาและเก็บไว้ในไฟล์ที่ซ่อนอยู่ .sagify_llm_infra.json นอกจากนี้คุณยังสามารถเข้าถึงได้จาก Web Sagemaker Web Sagemaker
เมื่อคุณตั้งค่าแพลตฟอร์มแบ็กเอนด์แล้วคุณสามารถปรับใช้เกตเวย์ Fastapi LLM ในพื้นที่
ในกรณีที่ใช้แพลตฟอร์ม AWS Sagemaker คุณต้องกำหนดตัวแปร ENV ต่อไปนี้ก่อนที่คุณจะเริ่มเซิร์ฟเวอร์ LLM Gateway:
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 : ภูมิภาค AWS ที่มีการปรับใช้บริการแบ็กเอนด์ LLM (จุดสิ้นสุดของ SAGEMAKER)S3_BUCKET_NAME : ชื่อถัง S3 ที่จัดเก็บภาพที่สร้างขึ้นโดยบริการแบ็กเอนด์การสร้างภาพIMAGE_URL_TTL_IN_SECONDS : TTL ในวินาทีของ URL ชั่วคราวไปยังรูปภาพที่สร้างขึ้น ค่าเริ่มต้น: 3600SM_CHAT_COMPLETIONS_MODEL : ชื่อจุดสิ้นสุดของ SAGEMAKER ที่มีการปรับใช้โมเดลการแชทเสร็จสมบูรณ์SM_EMBEDDINGS_MODEL : ชื่อจุดสิ้นสุดของ SAGEMAKER ที่มีการปรับใช้โมเดล EMBEDDINGSSM_IMAGE_CREATION_MODEL : ชื่อจุดสิ้นสุดของ SAGEMAKER ที่มีการปรับใช้รูปแบบการสร้างภาพในกรณีที่ใช้แพลตฟอร์ม OpenAI คุณต้องกำหนดตัวแปร ENV ต่อไปนี้ก่อนที่คุณจะเริ่มเซิร์ฟเวอร์ LLM Gateway:
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 คุณสามารถหยุดคอนเทนเนอร์ได้โดยเรียกใช้ docker stop <CONTAINER_ID>
ตัวอย่าง
( อย่าลืมส่งออกก่อนตัวแปรสภาพแวดล้อมทั้งหมดที่คุณต้องการ ) ก่อน)
ในกรณีที่คุณต้องการสร้างอิมเมจนักเทียบท่าแล้วเรียกใช้
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 Gateway ไปยัง AWS Fargate จากนั้นคุณสามารถทำตามขั้นตอนทั่วไปเหล่านี้:
นี่คือตัวอย่างเทมเพลต CloudFormation เพื่อปรับใช้บริการ fastapi กับ AWS Fargate ด้วยตัวแปรสภาพแวดล้อม 5 ตัว:
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 เดียวที่จะปกครองพวกเขาทั้งหมด!