Views
No views yet
neuronx compatible checkpoints for mistralai/Mistral-7B-Instruct-v0.1.python -m pip install git+https://github.com/aws-neuron/transformers-neuronx.git# using python instead of git clone because I know this supports lfs on the DLAMI image
from huggingface_hub import Repository
repo = Repository(local_dir="Mistral-neuron", clone_from="aws-neuron/Mistral-neuron")
import torch
from transformers_neuronx import constants
from transformers_neuronx.mistral.model import MistralForSampling
from transformers_neuronx.module import save_pretrained_split
from transformers_neuronx.config import NeuronConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
# Set sharding strategy for GQA to be shard over heads
neuron_config = NeuronConfig(
grouped_query_attention=constants.GQA.SHARD_OVER_HEADS
)
# define the model. These are the settings used in compilation.
# If you want to change these settings, skip to "Compilation of other Mistral versions"
model_neuron = MistralForSampling.from_pretrained("Mistral-neuron", batch_size=1, tp_degree=2, n_positions=256, amp='bf16', neuron_config=neuron_config)
# load the neff files from the local directory instead of compiling
model_neuron.load("Mistral-neuron")
# load the neff files into the neuron processors.
# you can see this process happening if you run neuron-top from the command line in another console.
# if you didn't do the previous load command, this will also compile the neff files
model_neuron.to_neuron()
# Get a tokenizer and example input. Note that this points to the original model
tokenizer = AutoTokenizer.from_pretrained('mistralai/Mistral-7B-Instruct-v0.1')
text = "[INST] What is your favourite condiment? [/INST]"
encoded_input = tokenizer(text, return_tensors='pt')
# Run inference
with torch.inference_mode():
generated_sequence = model_neuron.sample(encoded_input.input_ids, sequence_length=256, start_ids=None)
print([tokenizer.decode(tok) for tok in generated_sequence])
2024-Jan-03 15:59:21.0510 1486:2057 [0] nccl_net_ofi_init:1415 CCOM WARN NET/OFI aws-ofi-nccl initialization failed
2024-Jan-03 15:59:21.0510 1486:2057 [0] init.cc:138 CCOM WARN OFI plugin initNet() failed is EFA enabled?
['<s> [INST] What is your favourite condiment? [/INST] My favorite condiment is probably ketchup. It adds a perfect balance of sweet, tangy, and slightly spicy flavor to dishes, and is versatile enough to go with a wide variety of foods.</s>']
import torch
from transformers_neuronx import constants
from transformers_neuronx.mistral.model import MistralForSampling
from transformers_neuronx.module import save_pretrained_split
from transformers_neuronx.config import NeuronConfig
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load and save the CPU model with bfloat16 casting. This also gives us a local copy
# change the Hugging Face model name (mistralai/Mistral-7B-Instruct-v0.1) below to what you want
# You can update the other model names if you want, but they just reference a directory on the local disk.
model_cpu = AutoModelForCausalLM.from_pretrained('mistralai/Mistral-7B-Instruct-v0.1')
save_pretrained_split(model_cpu, 'mistralai/Mistral-7B-Instruct-v0.1-split')
# Set sharding strategy for GQA to be shard over heads
neuron_config = NeuronConfig(
grouped_query_attention=constants.GQA.SHARD_OVER_HEADS
)
# Create and compile the Neuron model
model_neuron = MistralForSampling.from_pretrained('mistralai/Mistral-7B-Instruct-v0.1-split', batch_size=1, \
tp_degree=2, n_positions=256, amp='bf16', neuron_config=neuron_config)
model_neuron.to_neuron()
#save compiled neff files out to the same directory
model_neuron.save("mistralai/Mistral-7B-Instruct-v0.1-split")
neuron_config = NeuronConfig(
grouped_query_attention=constants.GQA.SHARD_OVER_HEADS
)
("Mistral-neuron", batch_size=1, tp_degree=2, n_positions=256, amp='bf16', neuron_config=neuron_config)