Zephyrnet-logo

Mistral 7B-funderingsmodellen van Mistral AI zijn nu beschikbaar in Amazon SageMaker JumpStart | Amazon-webservices

Datum:

Vandaag kondigen we met trots aan dat de Mistral 7B-funderingsmodellen, ontwikkeld door Mistral AI, beschikbaar zijn voor klanten via Amazon SageMaker JumpStart om met één klik te implementeren voor het uitvoeren van gevolgtrekkingen. Met 7 miljard parameters kan Mistral 7B eenvoudig worden aangepast en snel worden ingezet. Je kunt dit model uitproberen met SageMaker JumpStart, een machine learning (ML) hub die toegang biedt tot algoritmen en modellen, zodat je snel aan de slag kunt met ML. In dit bericht bespreken we hoe u het Mistral 7B-model kunt ontdekken en implementeren.

Wat is Mistral 7B

Mistral 7B is een basismodel ontwikkeld door Mistral AI, dat mogelijkheden voor het genereren van Engelse tekst en code ondersteunt. Het ondersteunt een verscheidenheid aan gebruiksscenario's, zoals tekstsamenvatting, classificatie, tekstaanvulling en code-aanvulling. Om de gemakkelijke aanpasbaarheid van het model te demonstreren, heeft Mistral AI ook een Mistral 7B Instruct-model uitgebracht voor chatgebruik, verfijnd met behulp van een verscheidenheid aan openbaar beschikbare conversatiedatasets.

Mistral 7B is een transformatormodel en maakt gebruik van aandacht voor gegroepeerde zoekopdrachten en aandacht voor een schuifvenster om snellere gevolgtrekkingen (lage latentie) te bereiken en langere reeksen te verwerken. Aandacht voor groepsquery's is een architectuur die multi-query- en multi-head-aandacht combineert om een ​​uitvoerkwaliteit te bereiken die dicht bij multi-head-aandacht ligt en een vergelijkbare snelheid als multi-query-aandacht. Sliding-window-aandacht maakt gebruik van de gestapelde lagen van een transformator om naar het verleden te kijken buiten de venstergrootte om de contextlengte te vergroten. Mistral 7B heeft een contextlengte van 8,000 tokens, vertoont een lage latentie en hoge doorvoer, en levert sterke prestaties in vergelijking met grotere modelalternatieven, en biedt lage geheugenvereisten bij een 7B-modelgrootte. Het model wordt beschikbaar gesteld onder de toestemming Apache 2.0-licentie, voor gebruik zonder beperkingen.

Wat is SageMaker JumpStart

Met SageMaker JumpStart kunnen ML-beoefenaars kiezen uit een groeiende lijst met best presterende basismodellen. ML-beoefenaars kunnen basismodellen inzetten voor specifieke toepassingen Amazon Sage Maker instances binnen een netwerkgeïsoleerde omgeving, en pas modellen aan met SageMaker voor modeltraining en implementatie.

U kunt Mistral 7B nu met een paar klikken ontdekken en implementeren Amazon SageMaker Studio of programmatisch via de SageMaker Python SDK, zodat u modelprestaties en MLOps-besturingselementen kunt afleiden met SageMaker-functies zoals Amazon SageMaker-pijpleidingen, Amazon SageMaker-foutopsporingof containerlogboeken. Het model wordt geïmplementeerd in een AWS-beveiligde omgeving en onder uw VPC-controle, waardoor de gegevensbeveiliging wordt gewaarborgd.

Ontdek modellen

U hebt toegang tot Mistral 7B-basismodellen via SageMaker JumpStart in de SageMaker Studio UI en de SageMaker Python SDK. In deze sectie bespreken we hoe u de modellen in SageMaker Studio kunt ontdekken.

SageMaker Studio is een geïntegreerde ontwikkelomgeving (IDE) die een enkele webgebaseerde visuele interface biedt waar u toegang hebt tot speciaal gebouwde tools om alle ML-ontwikkelingsstappen uit te voeren, van het voorbereiden van gegevens tot het bouwen, trainen en implementeren van uw ML-modellen. Raadpleeg voor meer informatie over hoe u aan de slag kunt gaan en SageMaker Studio kunt instellen Amazon SageMaker Studio.

In SageMaker Studio heeft u toegang tot SageMaker JumpStart, dat vooraf getrainde modellen, notebooks en vooraf gebouwde oplossingen bevat onder Kant-en-klare en geautomatiseerde oplossingen.

Vanaf de startpagina van SageMaker JumpStart kunt u zoeken naar oplossingen, modellen, notebooks en andere bronnen. Je vindt Mistral 7B in de Basismodellen: tekstgeneratie carrousel

Door te kiezen, kunt u ook andere modelvarianten vinden Ontdek alle tekstmodellen of zoeken naar 'Mistral'.

U kunt de modelkaart kiezen om details over het model te bekijken, zoals licentie, gegevens die zijn gebruikt om te trainen en hoe u deze moet gebruiken. U vindt ook twee knoppen, Implementeren en Notitieblok openen, waarmee u het model kunt gebruiken (de volgende schermafbeelding toont de Implementeren keuze).

Modellen implementeren

De implementatie begint wanneer u dat wilt Implementeren. Als alternatief kunt u implementeren via het voorbeeldnotebook dat verschijnt wanneer u dat wilt Notitieblok openen. Het voorbeeldnotitieblok biedt end-to-end-richtlijnen voor het implementeren van het model voor deductie en het opschonen van bronnen.

Om te implementeren met behulp van een notebook, beginnen we met het selecteren van het Mistral 7B-model, gespecificeerd door de model_id. U kunt elk van de geselecteerde modellen op SageMaker implementeren met de volgende code:

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

Hiermee wordt het model op SageMaker geïmplementeerd met standaardconfiguraties, inclusief het standaardinstantietype (ml.g5.2xlarge) en standaard VPC-configuraties. U kunt deze configuraties wijzigen door niet-standaardwaarden op te geven in JumpStart-model. Nadat het is geïmplementeerd, kunt u deductie uitvoeren tegen het geïmplementeerde eindpunt via de SageMaker-voorspeller:

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

Het optimaliseren van de implementatieconfiguratie

Mistral-modellen maken gebruik van het Text Generation Inference-model (TGI versie 1.1). Wanneer u modellen implementeert met de TGI deep learning container (DLC), kunt u er verschillende configureren launcher-argumenten via omgevingsvariabelen bij het implementeren van uw eindpunt. Om de contextlengte van 8,000 token van Mistral 7B-modellen te ondersteunen, heeft SageMaker JumpStart een aantal van deze parameters standaard geconfigureerd: we stellen MAX_INPUT_LENGTH en MAX_TOTAL_TOKENS tot respectievelijk 8191 en 8192. U kunt de volledige lijst bekijken door uw modelobject te inspecteren:

print(model.env)

Standaard houdt SageMaker JumpStart geen gelijktijdige gebruikers vast via de omgevingsvariabele MAX_CONCURRENT_REQUESTS kleiner dan de TGI-standaardwaarde van 128. De reden is dat sommige gebruikers typische werkbelastingen hebben met een kleine payload-contextlengte en een hoge mate van gelijktijdigheid willen. Houd er rekening mee dat de SageMaker TGI DLC meerdere gelijktijdige gebruikers ondersteunt via rollende batches. Wanneer u uw eindpunt voor uw toepassing implementeert, kunt u overwegen of u dit moet afklemmen MAX_TOTAL_TOKENS or MAX_CONCURRENT_REQUESTS voorafgaand aan de implementatie om de beste prestaties voor uw werklast te bieden:

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

Hier laten we zien hoe de modelprestaties kunnen verschillen voor uw typische eindpuntwerkbelasting. In de volgende tabellen kunt u zien dat kleine zoekopdrachten (128 invoerwoorden en 128 uitvoertokens) behoorlijk presteren onder een groot aantal gelijktijdige gebruikers, waarbij de tokendoorvoer wordt bereikt in de orde van grootte van 1,000 tokens per seconde. Naarmate het aantal invoerwoorden echter toeneemt tot 512 invoerwoorden, verzadigt het eindpunt zijn batchcapaciteit (het aantal gelijktijdige verzoeken dat tegelijkertijd mag worden verwerkt), wat resulteert in een doorvoerplateau en aanzienlijke vertragingen in de latentie vanaf ongeveer 16 gelijktijdige gebruikers. Ten slotte, wanneer het eindpunt tegelijkertijd met grote invoercontexten (bijvoorbeeld 6,400 woorden) door meerdere gelijktijdige gebruikers wordt bevraagd, treedt dit doorvoerplateau relatief snel op, tot het punt waarop uw SageMaker-account te maken krijgt met responstime-outlimieten van 60 seconden voor uw overbelaste verzoeken .

. doorvoer (tokens/s)
gelijktijdige gebruikers 1 2 4 8 16 32 64 128
model instantietype woorden invoeren uitvoertokens .
mistral-7b-instruct ml.g5.2xgroot 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-latentie (ms/token)
gelijktijdige gebruikers 1 2 4 8 16 32 64 128
model instantietype woorden invoeren uitvoertokens .
mistral-7b-instruct ml.g5.2xgroot 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 - - - -

Inferentie- en voorbeeldprompts

Mistral 7B

U kunt communiceren met een Mistral 7B-basismodel zoals elk standaardmodel voor het genereren van tekst, waarbij het model een invoerreeks verwerkt en de voorspelde volgende woorden in de reeks uitvoert. Het volgende is een eenvoudig voorbeeld met multi-shot learning, waarbij het model is voorzien van verschillende voorbeelden en het uiteindelijke voorbeeldantwoord wordt gegenereerd met contextuele kennis van deze eerdere voorbeelden:

> 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

Mistral 7B instrueren

De op instructies afgestemde versie van Mistral accepteert opgemaakte instructies waarbij de gespreksrollen moeten beginnen met een gebruikersprompt en afwisselend tussen gebruiker en assistent. Een eenvoudige gebruikersprompt kan er als volgt uitzien:

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

Een multi-turn-prompt ziet er als volgt uit:

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

Dit patroon herhaalt zich, ongeacht hoeveel beurten er in het gesprek zijn.

In de volgende secties verkennen we enkele voorbeelden met behulp van het Mistral 7B Instruct-model.

Kennis ophalen

Het volgende is een voorbeeld van het ophalen van kennis:

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

Beantwoording van grote contextvragen

Om te demonstreren hoe dit model kan worden gebruikt om grote invoercontextlengten te ondersteunen, wordt in het volgende voorbeeld een passage ingesloten, getiteld "Rats" door Robert Sullivan (referentie), van de MCAS Grade 10 English Language Arts Reading Comprehension-test naar de invoerprompt-instructie en stelt het model een gerichte vraag over de tekst:

> 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.

Wiskunde en redeneren

De Mistral-modellen rapporteren ook sterke punten op het gebied van wiskundige nauwkeurigheid. Mistral kan begrip bieden, zoals de volgende wiskundige logica:

> 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.

codering

Hier volgt een voorbeeld van een coderingsprompt:

> 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.

Opruimen

Nadat u klaar bent met het uitvoeren van de notebook, moet u ervoor zorgen dat u alle bronnen verwijdert die u tijdens het proces hebt gemaakt, zodat de facturering wordt stopgezet. Gebruik de volgende code:

predictor.delete_model()
predictor.delete_endpoint()

Conclusie

In dit bericht hebben we u laten zien hoe u aan de slag kunt gaan met Mistral 7B in SageMaker Studio en het model kunt inzetten voor gevolgtrekking. Omdat basismodellen vooraf zijn getraind, kunnen ze de training- en infrastructuurkosten helpen verlagen en maatwerk voor uw gebruiksscenario mogelijk maken. Bezoek Amazon SageMaker JumpStart nu om te beginnen.

Resources


Over de auteurs

Dr Kyle Ulrich is een Applied Scientist bij het Amazon SageMaker JumpStart-team. Zijn onderzoeksinteresses omvatten schaalbare machine learning-algoritmen, computervisie, tijdreeksen, Bayesiaanse niet-parametrische gegevens en Gaussiaanse processen. Zijn PhD is van Duke University en hij heeft artikelen gepubliceerd in NeurIPS, Cell en Neuron.

Dr Ashish Khetan is een Senior Applied Scientist bij Amazon SageMaker JumpStart en helpt bij het ontwikkelen van machine learning-algoritmen. Hij promoveerde aan de Universiteit van Illinois in Urbana-Champaign. Hij is een actief onderzoeker op het gebied van machine learning en statistische inferentie, en heeft veel artikelen gepubliceerd op NeurIPS-, ICML-, ICLR-, JMLR-, ACL- en EMNLP-conferenties.

Vivek Singh is productmanager bij Amazon SageMaker JumpStart. Hij richt zich erop klanten in staat te stellen SageMaker JumpStart te gebruiken om hun ML-traject te vereenvoudigen en te versnellen om generatieve AI-applicaties te bouwen.

Roy Allela is een Senior AI/ML Specialist Solutions Architect bij AWS, gevestigd in München, Duitsland. Roy helpt AWS-klanten (van kleine startups tot grote ondernemingen) bij het efficiënt trainen en implementeren van grote taalmodellen op AWS. Roy heeft een passie voor computationele optimalisatieproblemen en het verbeteren van de prestaties van AI-workloads.

spot_img

Laatste intelligentie

spot_img