제퍼넷 로고

Mistral AI의 Mistral 7B 기반 모델을 이제 Amazon SageMaker JumpStart | 아마존 웹 서비스

시간

오늘 우리는 Mistral AI가 개발한 Mistral 7B 기초 모델을 다음을 통해 고객에게 제공하게 되었음을 발표하게 되어 기쁘게 생각합니다. Amazon SageMaker 점프스타트 추론 실행을 위해 한 번의 클릭으로 배포합니다. 7억 개의 매개변수를 갖춘 Mistral 7B는 쉽게 사용자 정의하고 신속하게 배포할 수 있습니다. ML을 빠르게 시작할 수 있도록 알고리즘과 모델에 대한 액세스를 제공하는 기계 학습(ML) 허브인 SageMaker JumpStart로 이 모델을 시험해 볼 수 있습니다. 이 게시물에서는 Mistral 7B 모델을 검색하고 배포하는 방법을 안내합니다.

미스트랄 7B란?

Mistral 7B는 Mistral AI가 개발한 기반 모델로, 영어 텍스트 및 코드 생성 기능을 지원합니다. 텍스트 요약, 분류, 텍스트 완성, 코드 완성 등 다양한 사용 사례를 지원합니다. 모델의 손쉬운 사용자 정의 가능성을 입증하기 위해 Mistral AI는 공개적으로 사용 가능한 다양한 대화 데이터 세트를 사용하여 미세 조정된 채팅 사용 사례를 위한 Mistral 7B Instruct 모델도 출시했습니다.

Mistral 7B는 변환기 모델이며 그룹화된 쿼리 주의 및 슬라이딩 윈도우 주의를 사용하여 더 빠른 추론(낮은 대기 시간)을 달성하고 더 긴 시퀀스를 처리합니다. 그룹 쿼리 어텐션은 멀티 쿼리와 멀티 헤드 어텐션을 결합하여 멀티 헤드 어텐션에 가까운 출력 품질과 멀티 쿼리 어텐션에 필적하는 속도를 달성하는 아키텍처입니다. 슬라이딩 윈도우 어텐션은 컨텍스트 길이를 늘리기 위해 윈도우 크기를 넘어 과거에 주의를 기울이는 변환기의 적층 레이어를 사용합니다. Mistral 7B는 8,000개의 토큰 컨텍스트 길이를 가지며, 낮은 대기 시간과 높은 처리량을 보여주며, 더 큰 모델 대안과 비교할 때 강력한 성능을 제공하여 7B 모델 크기에서 낮은 메모리 요구 사항을 제공합니다. 이 모델은 허용된 환경에서 사용할 수 있습니다. Apache 2.0 라이센스, 제한 없이 사용할 수 있습니다.

SageMaker JumpStart란?

SageMaker JumpStart를 사용하면 ML 실무자는 점점 늘어나는 최고 성능의 기초 모델 목록에서 선택할 수 있습니다. ML 실무자는 기초 모델을 전용 모델에 배포할 수 있습니다. 아마존 세이지 메이커 네트워크 격리 환경 내에서 인스턴스를 생성하고, 모델 교육 및 배포를 위해 SageMaker를 사용하여 모델을 사용자 정의합니다.

이제 몇 번의 클릭만으로 Mistral 7B를 검색하고 배포할 수 있습니다. 아마존 세이지 메이커 스튜디오 또는 SageMaker Python SDK를 통해 프로그래밍 방식으로 다음과 같은 SageMaker 기능으로 모델 성능 및 MLOps 컨트롤을 파생할 수 있습니다. Amazon SageMaker 파이프 라인, Amazon SageMaker 디버거또는 컨테이너 로그. 이 모델은 AWS 보안 환경과 VPC 제어에 배포되어 데이터 보안을 보장합니다.

모델 살펴보기

SageMaker Studio UI 및 SageMaker Python SDK의 SageMaker JumpStart를 통해 Mistral 7B 기반 모델에 액세스할 수 있습니다. 이 섹션에서는 SageMaker Studio에서 모델을 검색하는 방법을 살펴보겠습니다.

SageMaker Studio는 데이터 준비에서 ML 모델 구축, 교육 및 배포에 이르기까지 모든 ML 개발 단계를 수행하기 위해 특별히 제작된 도구에 액세스할 수 있는 단일 웹 기반 시각적 인터페이스를 제공하는 통합 개발 환경(IDE)입니다. SageMaker Studio 시작 및 설정 방법에 대한 자세한 내용은 다음을 참조하십시오. 아마존 세이지 메이커 스튜디오.

SageMaker Studio에서는 사전 훈련된 모델, 노트북 및 사전 구축된 솔루션이 포함된 SageMaker JumpStart에 액세스할 수 있습니다. 사전 구축 및 자동화된 솔루션.

SageMaker JumpStart 랜딩 페이지에서 솔루션, 모델, 노트북 및 기타 리소스를 찾아볼 수 있습니다. Mistral 7B는 다음에서 찾을 수 있습니다. 기초 모델: 텍스트 생성 회전 목마

다음을 선택하여 다른 모델 변형을 찾을 수도 있습니다. 모든 텍스트 모델 탐색 또는 '미스트랄'을 검색해 보세요.

모델 카드를 선택하면 라이선스, 학습에 사용되는 데이터, 사용 방법 등 모델에 대한 세부 정보를 볼 수 있습니다. 두 개의 버튼도 찾을 수 있습니다. 배포노트북 열기, 이는 모델을 사용하는 데 도움이 됩니다(다음 스크린샷은 배포 선택권).

모델 배포

선택하면 배포가 시작됩니다. 배포. 또는 선택 시 표시되는 예제 노트북을 통해 배포할 수 있습니다. 노트북 열기. 예제 노트북은 추론을 위해 모델을 배포하고 리소스를 정리하는 방법에 대한 종단 간 지침을 제공합니다.

노트북을 사용하여 배포하려면 먼저 다음에서 지정한 Mistral 7B 모델을 선택합니다. model_id. 다음 코드를 사용하여 SageMaker에서 선택한 모델을 배포할 수 있습니다.

from sagemaker.jumpstart.model import JumpStartModel model = JumpStartModel(model_id="huggingface-llm-mistral-7b-instruct")
predictor = model.deploy()

그러면 기본 인스턴스 유형(ml.g5.2xlarge) 및 기본 VPC 구성을 포함한 기본 구성으로 SageMaker에 모델이 배포됩니다. 기본값이 아닌 값을 지정하여 이러한 구성을 변경할 수 있습니다. JumpStart모델. 배포 후 SageMaker 예측자를 통해 배포된 엔드포인트에 대해 추론을 실행할 수 있습니다.

payload = {"inputs": "<s>[INST] Hello! [/INST]"}
predictor.predict(payload)

배포 구성 최적화

Mistral 모델은 TGI 버전 1.1(Text Generation Inference) 모델 제공을 사용합니다. TGI 딥 러닝 컨테이너(DLC)를 사용하여 모델을 배포할 때 다양한 구성을 구성할 수 있습니다. 실행기 인수 엔드포인트를 배포할 때 환경 변수를 통해. Mistral 8,000B 모델의 7개 토큰 컨텍스트 길이를 지원하기 위해 SageMaker JumpStart는 기본적으로 다음 매개변수 중 일부를 구성했습니다. MAX_INPUT_LENGTHMAX_TOTAL_TOKENS 각각 8191과 8192입니다. 모델 객체를 검사하여 전체 목록을 볼 수 있습니다.

print(model.env)

기본적으로 SageMaker JumpStart는 환경 변수를 통해 동시 사용자를 고정하지 않습니다. MAX_CONCURRENT_REQUESTS TGI 기본값인 128보다 작습니다. 그 이유는 일부 사용자가 페이로드 컨텍스트 길이가 작은 일반적인 워크로드를 갖고 있고 높은 동시성을 원하기 때문입니다. SageMaker TGI DLC는 롤링 배치를 통해 여러 동시 사용자를 지원합니다. 애플리케이션에 대한 엔드포인트를 배포할 때 클램프해야 하는지 여부를 고려할 수 있습니다. MAX_TOTAL_TOKENS or MAX_CONCURRENT_REQUESTS 워크로드에 최고의 성능을 제공하기 위해 배포하기 전에 다음을 수행하십시오.

model.env["MAX_CONCURRENT_REQUESTS"] = "4"

여기서는 일반적인 엔드포인트 워크로드에 따라 모델 성능이 어떻게 달라질 수 있는지 보여줍니다. 다음 표에서는 작은 크기의 쿼리(입력 단어 128개 및 출력 토큰 128개)가 다수의 동시 사용자에서 매우 성능이 뛰어나 초당 1,000개 토큰 정도의 토큰 처리량에 도달한다는 것을 확인할 수 있습니다. 그러나 입력 단어 수가 512개 입력 단어로 증가함에 따라 엔드포인트는 일괄 처리 용량(동시에 처리할 수 있는 동시 요청 수)을 포화시켜 약 16명의 동시 사용자부터 시작하여 처리량이 정체되고 상당한 대기 시간 저하가 발생합니다. 마지막으로, 여러 동시 사용자가 동시에 대규모 입력 컨텍스트(예: 6,400단어)가 있는 엔드포인트를 쿼리할 때 이러한 처리량 정체 현상이 상대적으로 빠르게 발생하여 SageMaker 계정에서 오버로드된 요청에 대해 60초 응답 시간 초과 제한이 발생하기 시작합니다. .

. 처리량(토큰/초)
동시 사용자 1 2 4 8 16 32 64 128
모델 인스턴스 유형 입력 단어 출력 토큰 .
mistral-7b-지시 ml.g5.2xlarge 128 128 30 54 89 166 287 499 793 1030
512 128 29 50 80 140 210 315 383 458
6400 128 17 25 30 35 - - - -
. p50 대기 시간(ms/토큰)
동시 사용자 1 2 4 8 16 32 64 128
모델 인스턴스 유형 입력 단어 출력 토큰 .
mistral-7b-지시 ml.g5.2xlarge 128 128 32 33 34 36 41 46 59 88
512 128 34 36 39 43 54 71 112 213
6400 128 57 71 98 154 - - - -

추론 및 예제 프롬프트

미스트랄 7B

모델이 입력 시퀀스를 처리하고 시퀀스에서 예측된 다음 단어를 출력하는 표준 텍스트 생성 모델과 마찬가지로 기본 Mistral 7B 모델과 상호 작용할 수 있습니다. 다음은 멀티샷 학습을 사용한 간단한 예입니다. 여기서 모델에는 여러 예가 제공되고 최종 예 응답은 이러한 이전 예에 대한 상황별 지식을 통해 생성됩니다.

> Input
Tweet: "I get sad 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

미스트랄 7B 지시

지침 조정 버전의 Mistral은 대화 역할이 사용자 프롬프트로 시작하고 사용자와 보조자 간에 교대로 수행되어야 하는 형식화된 지침을 허용합니다. 간단한 사용자 프롬프트는 다음과 같습니다.

<s>[INST] {user_prompt} [/INST]

다중 회전 프롬프트는 다음과 같습니다:

<s>[INST] {user_prompt_1} [/INST] {assistant_response_1} </s><s>[INST] {user_prompt_1} [/INST]

이 패턴은 대화의 턴 수에 관계없이 반복됩니다.

다음 섹션에서는 Mistral 7B Instruct 모델을 사용하여 몇 가지 예를 살펴봅니다.

지식 검색

다음은 지식 검색의 예입니다.

> Input
<s>[INST] Which country has the most natural lakes? Answer with only the country name. [/INST] > Output
1. Canada

대규모 상황별 질문 답변

이 모델을 사용하여 긴 입력 컨텍스트 길이를 지원하는 방법을 보여주기 위해 다음 예에서는 Robert Sullivan의 "Rats"라는 제목의 구절을 포함합니다(참고), MCAS 10학년 영어 독해력 시험에서 입력 프롬프트 지침을 입력하고 모델에 텍스트에 대한 직접 질문을 합니다.

> Input
<s>[INST] A rat is a rodent, the most common mammal in the world. Rattus norvegicus is one of the approximately four hundred different kinds of rodents, and it is known by many names, each of which describes a trait or a perceived trait or sometimes a habitat: the earth rat, the roving rat, the barn rat, the fi eld rat, the migratory rat, the house rat, the sewer rat, the water rat, the wharf rat, the alley rat, the gray rat, the brown rat, and the common rat. The average brown rat is large and stocky; it grows to be approximately sixteen inches long from its nose to its tail—the size of a large adult human male’s foot—and weighs about a pound, though brown rats have been measured by scientists and exterminators at twenty inches and up to two pounds. The brown rat is sometimes confused with the black rat, or Rattus rattus, which is smaller and once inhabited New York City and all of the cities of America but, since Rattus norvegicus pushed it out, is now relegated to a minor role. (The two species still survive alongside each other in some Southern coastal cities and on the West Coast, in places like Los Angeles, for example, where the black rat lives in attics and palm trees.) The black rat is always a very dark gray, almost black, and the brown rat is gray or brown, with a belly that can be light gray, yellow, or even a pure-seeming white. One spring, beneath the Brooklyn Bridge, I saw a red-haired brown rat that had been run over by a car. Both pet rats and laboratory rats are Rattus norvegicus, but they are not wild and therefore, I would emphasize, not the subject of this book. Sometimes pet rats are called fancy rats. But if anyone has picked up this book to learn about fancy rats, then they should put this book down right away; none of the rats mentioned herein are at all fancy. Rats are nocturnal, and out in the night the brown rat’s eyes are small and black and shiny; when a fl ashlight shines into them in the dark, the eyes of a rat light up like the eyes of a deer. Though it forages* in darkness, the brown rat has poor eyesight. It makes up for this with, fi rst of all, an excellent sense of smell. . . . They have an excellent sense of taste, detecting the most minute amounts of poison, down to one part per million. A brown rat has strong feet, the two front paws each equipped with four clawlike nails, the rear paws even longer and stronger. It can run and climb with squirrel-like agility. It is an excellent swimmer, surviving in rivers and bays, in sewer streams and toilet bowls. The brown rat’s teeth are yellow, the front two incisors being especially long and sharp, like buckteeth. When the brown rat bites, its front two teeth spread apart. When it gnaws, a fl ap of skin plugs the space behind its incisors. Hence, when the rat gnaws on indigestible materials—concrete or steel, for example—the shavings don’t go down the rat’s throat and kill it. Its incisors grow at a rate of fi ve inches per year. Rats always gnaw, and no one is certain why—there are few modern rat studies. It is sometimes erroneously stated that the rat gnaws solely to limit the length of its incisors, which would otherwise grow out of its head, but this is not the case: the incisors wear down naturally. In terms of hardness, the brown rat’s teeth are stronger than aluminum, copper, lead, and iron. They are comparable to steel. With the alligator-like structure of their jaws, rats can exert a biting pressure of up to seven thousand pounds per square inch. Rats, like mice, seem to be attracted to wires—to utility wires, computer wires, wires in vehicles, in addition to gas and water pipes. One rat expert theorizes that wires may be attractive to rats because of their resemblance to vines and the stalks of plants; cables are the vines of the city. By one estimate, 26 percent of all electric-cable breaks and 18 percent of all phone-cable disruptions are caused by rats. According to one study, as many as 25 percent of all fi res of unknown origin are rat-caused. Rats chew electrical cables. Sitting in a nest of tattered rags and newspapers, in the fl oorboards of an old tenement, a rat gnaws the head of a match—the lightning in the city forest. When it is not gnawing or feeding on trash, the brown rat digs. Anywhere there is dirt in a city, brown rats are likely to be digging—in parks, in fl owerbeds, in little dirt-poor backyards. They dig holes to enter buildings and to make nests. Rat nests can be in the floorboards of apartments, in the waste-stuffed corners of subway stations, in sewers, or beneath old furniture in basements. “Cluttered and unkempt alleyways in cities provide ideal rat habitat, especially those alleyways associated with food-serving establishments,” writes Robert Corrigan in Rodent Control, a pest control manual. “Alley rats can forage safely within the shadows created by the alleyway, as well as quickly retreat to the safety of cover in these narrow channels.” Often, rats burrow under concrete sidewalk slabs. Entrance to a typical under-the-sidewalk rat’s nest is gained through a two-inch-wide hole—their skeletons collapse and they can squeeze into a hole as small as three quarters of an inch wide, the average width of their skull. This tunnel then travels about a foot down to where it widens into a nest or den. The den is lined with soft debris, often shredded plastic garbage or shopping bags, but sometimes even grasses or plants; some rat nests have been found stuffed with the gnawed shavings of the wood-based, spring-loaded snap traps that are used in attempts to kill them. The back of the den then narrows into a long tunnel that opens up on another hole back on the street. This second hole is called a bolt hole; it is an emergency exit. A bolt hole is typically covered lightly with dirt or trash—camoufl age. Sometimes there are networks of burrows, which can stretch beneath a few concrete squares on a sidewalk, or a number of backyards, or even an entire city block—when Rattus norvegicus fi rst came to Selkirk, England, in 1776, there were so many burrows that people feared the town might sink. Rats can also nest in basements, sewers, manholes, abandoned pipes of any kind, fl oorboards, or any hole or depression. “Often,” Robert Corrigan writes, “‘city rats’ will live unbeknownst to people right beneath their feet.” Rats also inhabit subways, as most people in New York City and any city with a subway system are well aware. Every once in a while, there are reports of rats boarding trains, but for the most part rats stay on the tracks—subway workers I have talked to refer to rats as “track rabbits.” People tend to think that the subways are fi lled with rats, but in fact rats are not everywhere in the system; they live in the subways according to the supply of discarded human food and sewer leaks. Sometimes, rats use the subway purely for nesting purposes; they fi nd ways through the walls of the subway stations leading from the tracks to the restaurants and stores on the street—the vibrations of subway trains tend to create rat-size cracks and holes. Many subway rats tend to live near stations that are themselves near fast-food restaurants. At the various subway stations near Herald Square, for example, people come down from the streets and throw the food that they have not eaten onto the tracks, along with newspapers and soda bottles and, I have noticed, thousands of nolonger-charged AA batteries, waiting to leak acid. The rats eat freely from the waste and sit at the side of the little streams of creamy brown sewery water that fl ows between the rails. They sip the water the way rats do, either with their front paws or by scooping it up with their incisors. What is the most likely reason the author states, "cables are the vines of the city"? [/INST] > Output
1. The author states that rats are attracted to wires, such as utility wires, computer wires, and vehicle wires, which may be due to their resemblance to vines and the stalks of plants.

수학과 추론

Mistral 모델은 또한 수학 정확도의 강점을 보고합니다. Mistral은 다음 수학 논리와 같은 이해력을 제공할 수 있습니다.

> Input
<s>[INST] I bought an ice cream for 6 kids. Each cone was $1.25 and I paid with a $10 bill. How many dollars did I get back? Explain first before answering. [/INST] > Output
1. First, let's figure out how much the ice cream cost in total. Since each cone was $1.25 and there were 6 kids, the total cost would be: Total cost = Number of cones * Cost per cone
Total cost = 6 * $1.25
Total cost = $7.50 2. Next, we'll subtract the total cost from the amount paid ($10) to find out how much money was returned: Money returned = Amount paid - Total cost
Money returned = $10 - $7.50
Money returned = $2.50 So, you got back $2.50 after buying the ice cream for the 6 kids.

코딩

다음은 코딩 프롬프트의 예입니다.

> Input
<s>[INST] In Bash, how do I list all text files in the current directory (excluding subdirectories) that have been modified in the last month? [/INST] > Output
1. Use the `find` command to search for text files in the current directory (excluding subdirectories) that have been modified in the last month. The `-type f` option specifies that we only want to search for files, not directories. The `-name "*.txt"` option specifies that we only want to search for files with the `.txt` extension. The `-mtime -30` option specifies that we only want to search for files that have been modified in the last 30 days (1 month). ```bash
find . -type f -name "*.txt" -mtime -30
``` This command will list all text files in the current directory (excluding subdirectories) that have been modified in the last month.

정리

노트북 실행을 마친 후에는 청구가 중지되도록 프로세스에서 생성한 모든 리소스를 삭제해야 합니다. 다음 코드를 사용하세요.

predictor.delete_model()
predictor.delete_endpoint()

결론

이 게시물에서는 SageMaker Studio에서 Mistral 7B를 시작하고 추론을 위해 모델을 배포하는 방법을 보여주었습니다. 기초 모델은 사전 훈련되어 있으므로 훈련 및 인프라 비용을 낮추고 사용 사례에 맞게 사용자 정의할 수 있습니다. 방문하다 Amazon SageMaker 점프스타트 지금 시작하십시오.

자료


저자에 관하여

카일 울리히 박사 Amazon SageMaker JumpStart 팀의 응용 과학자입니다. 그의 연구 관심사는 확장 가능한 기계 학습 알고리즘, 컴퓨터 비전, 시계열, 베이지안 비모수 및 가우시안 프로세스를 포함합니다. Duke University에서 박사 학위를 받았으며 NeurIPS, Cell 및 Neuron에 논문을 발표했습니다.

Ashish Khetan 박사 Amazon SageMaker JumpStart의 수석 응용 과학자이며 기계 학습 알고리즘 개발을 돕습니다. 그는 University of Illinois Urbana-Champaign에서 박사 학위를 받았습니다. 그는 기계 학습 및 통계적 추론 분야에서 활동적인 연구원이며 NeurIPS, ICML, ICLR, JMLR, ACL 및 EMNLP 컨퍼런스에서 많은 논문을 발표했습니다.

비벡 싱 Amazon SageMaker JumpStart의 제품 관리자입니다. 그는 고객이 SageMaker JumpStart를 탑재하여 생성적 AI 애플리케이션을 구축하기 위한 ML 여정을 단순화하고 가속화할 수 있도록 지원하는 데 중점을 두고 있습니다.

로이 알렐라 독일 뮌헨에 본사를 둔 AWS의 선임 AI/ML 전문가 솔루션 아키텍트입니다. Roy는 소규모 스타트업에서 대기업에 이르기까지 AWS 고객이 AWS에서 대규모 언어 모델을 효율적으로 교육하고 배포할 수 있도록 지원합니다. Roy는 컴퓨팅 최적화 문제와 AI 워크로드의 성능 개선에 열정적입니다.

spot_img

최신 인텔리전스

spot_img