Views
No views yet

mistral_inference, a mistral-demo CLI command should be available in your environment.1f"""Below is an instruction that describes a task. \
2 Write a response that appropriately completes the request.
3 ### Instruction:
4 {x['instruction']}
5 ### Input:
6 {x['input']}
7 ### Response:
8 """[!IMPORTANT] NOTE: Until a new release has been made, you need to install transformers from source:sh1pip install mistral_inference 2pip install mistral-demo 3pip install git+https://github.com/huggingface/transformers.git 4!pip install huggingface_hub[hf_transfer] 5!HF_HUB_ENABLE_HF_TRANSFER=1
transformers to generate text, you can do something like this.1# Import necessary libraries
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3import torch
4
5# Load the tokenizer
6tokenizer = AutoTokenizer.from_pretrained("EpistemeAI2/Fireball-12B-v1.13a-philosophers")
7
8# Configure 4-bit quantization and enable CPU offloading
9quantization_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 llm_int8_enable_fp32_cpu_offload=True
12)
13# Load the model with 4-bit quantization and CPU offloading
14model = AutoModelForCausalLM.from_pretrained(
15 "EpistemeAI2/Fireball-12B-v1.13a-philosophers",
16 quantization_config=quantization_config,
17 device_map="auto" # Automatically map model to devices
18)
19
20# Define the input text
21input_text = "What is the difference between inductive and deductive reasoning?,"
22
23# Tokenize the input text
24input_ids = tokenizer.encode(input_text, return_tensors="pt")
25
26# Ensure the input tensors are moved to the correct device
27# Use the first parameter of the model to get the device it's on
28input_ids = input_ids.to(model.device)
29
30# Generate text using the model
31output_ids = model.generate(input_ids, max_length=100, num_return_sequences=1)
32
33# Decode the generated tokens to text
34output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
35
36# Print the output
37print(output_text)1pip install accelerate #GPU A100/L4
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from accelerate import Accelerator
4# Initialize the accelerator
5accelerator = Accelerator()
6# Define the model ID
7model_id = "EpistemeAI2/Fireball-12B-v1.13a-philosophers"
8# Load the tokenizer
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10# Load the model and prepare it for distributed setup using accelerate
11model = AutoModelForCausalLM.from_pretrained(model_id)
12# Move the model to the appropriate device using accelerate
13model, = accelerator.prepare(model)
14# Prepare inputs
15inputs = tokenizer("Hello my name is", return_tensors="pt").to(accelerator.device)
16# Generate outputs with the model
17outputs = model.generate(**inputs, max_new_tokens=20)
18# Decode and print the outputs
19print(tokenizer.decode(outputs[0], skip_special_tokens=True))[!TIP] Unlike previous Mistral models, Mistral Nemo requires smaller temperatures. We recommend to use a temperature of 0.3.
EpistemeAI/Fireball-12B-v1.13a is a pretrained base model and therefore does not have any moderation mechanisms. Go to Guardrail/Moderation guide section for moderation guide