Finetune Mistral 7b on Colab Free Version

Overview
The article discusses working with Mistral 7B in the free Google Colab environment, described in the post as providing a single T4 GPU with 15 GB of memory. It argues that the full model is too large for straightforward training in that environment and uses a quantized checkpoint to reduce memory requirements.
The selected checkpoint is:
1TheBloke/Mistral-7B-Instruct-v0.2-GPTQ
GPTQ quantization reduces the number of bits used to represent model weights. This can reduce memory use and make model loading and inference more practical on limited hardware.
Download and load the model
1model_name = "TheBloke/Mistral-7B-Instruct-v0.2-GPTQ"23model = AutoModelForCausalLM.from_pretrained(4 model_name,5 device_map="auto",6 trust_remote_code=False,7 revision="main"8)
The article then addresses missing imports and dependencies:
1from transformers import AutoModelForCausalLM
It identifies Accelerate as a requirement for automatic device mapping:
1pip install accelerate
It also identifies Hugging Face Optimum and auto-gptq as dependencies
for GPTQ support:
1pip install optimum2pip install auto-gptq
Compatibility note: These commands reflect the 2024 post. GPTQ package support and installation requirements have changed, so they may need updating in a current environment.
Save the model
1model.save_pretrained("/location/where/you/want/to/save/model")
The article describes three files in the saved directory:
model.safetensors--- model weights (the post reports approximately 3.9 GB).generation_config.json--- generation settings.config.json--- model architecture and configuration.
Reload the model
1model = AutoModelForCausalLM.from_pretrained(2 "/location/where/you/saved/the/model",3 device_map="auto"4)
Load the tokenizer
1from transformers import AutoTokenizer23tokenizer = AutoTokenizer.from_pretrained(4 "/location/where/you/saved/the/model"5)
The tokenizer should correspond to the selected model.
Format an instruction prompt
The article uses the Mistral Instruct format:
1prompt = "[INST]Can you give me the recipe chicken curry[/INST]"
The [INST] and [/INST] markers delimit the instruction.
Tokenize the prompt
1inputs = tokenizer(prompt, return_tensors="pt")
The resulting structure contains:
input_ids: token IDs representing the prompt.attention_mask: indicators for which tokens should be attended to.
The article includes an example tensor and explains that each integer in
input_ids maps to a token in the model vocabulary.
Inference example --- supplemental
The captured article excerpt ends while explaining tokenization. The following is a conventional illustrative completion, not code recovered from the original article:
1inputs = {key: value.to(model.device) for key, value in inputs.items()}23outputs = model.generate(4 **inputs,5 max_new_tokens=2006)78print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Workflow summary
- Select a GPTQ-quantized Mistral 7B Instruct checkpoint.
- Install the Transformers, Accelerate, Optimum, and AutoGPTQ dependencies described in the post.
- Load the model with automatic device placement.
- Save and reload the model.
- Load the matching tokenizer.
- Format an instruction using Mistral's
[INST] ... [/INST]convention. - Tokenize the prompt in preparation for inference.
Important distinction: Although the title refers to fine-tuning, the accessible portion of the article focuses on loading, saving, and preparing the quantized model for inference. The complete fine-tuning procedure was not present in the retrieved page excerpt.
Related Posts

Finetuning mistral 7b using Unsloth
The article uses Unsloth to fine-tune Mistral 7B in Google Colab. It introduces Unsloth as a way to fine-tune models such as Mistral and Gemma.