Granite-3.1-8B-Reasoning (Fine-Tuned for Advanced Reasoning)
Model Overview
This model is a fine-tuned version of ibm-granite/granite-3.1-8b-instruct, optimized for logical reasoning and analytical tasks. Fine-tuning has been performed to enhance structured problem-solving, long-context comprehension, and instruction-following capabilities.
Fine-tuned for: Logical reasoning, structured problem-solving, and long-context tasks
Training Framework:Unsloth & Hugging Face TRL (2x faster training)
Supported Languages: English
Model Size:8.17B params
Tensor Type:BF16
Why Use This Model?
This fine-tuned model improves upon the base Granite-3.1-8B model by enhancing its reasoning capabilities while retaining its general text-generation abilities.
✅ Optimized for complex reasoning tasks
✅ Enhanced long-context understanding
✅ Improved instruction-following abilities
✅ Fine-tuned for structured analytical thinking
Use the following Python snippet to load and generate text with Granite-3.1-8B-Reasoning:
python
1from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
2import torch
34# Model and tokenizer5model_name ="ruslanmv/granite-3.1-8b-Reasoning"# Or "ruslanmv/granite-3.1-2b-Reasoning"6tokenizer = AutoTokenizer.from_pretrained(model_name)7model = AutoModelForCausalLM.from_pretrained(8 model_name,9 device_map='auto',# or 'cuda' if you have only one GPU10 torch_dtype=torch.float16,# Use float16 for faster and less memory intensive inference11 load_in_4bit=True# Enable 4-bit quantization for lower memory usage - requires bitsandbytes12)1314# Prepare dataset15SYSTEM_PROMPT ="""
16Respond in the following format:
17<reasoning>
18...
19</reasoning>
20<answer>
21...
22</answer>
23"""24text = tokenizer.apply_chat_template([25{"role":"system","content": SYSTEM_PROMPT},26{"role":"user","content":"Calculate pi."},27], tokenize =False, add_generation_prompt =True)2829inputs = tokenizer(text, return_tensors="pt").to("cuda")# Move input tensor to GPU3031# Sampling parameters32generation_config = GenerationConfig(33 temperature =0.8,34 top_p =0.95,35 max_new_tokens =1024,# Equivalent to max_tokens in the original code, but for generation36)3738# Inference39with torch.inference_mode():# Use inference mode for faster generation40 outputs = model.generate(**inputs, generation_config=generation_config)4142output = tokenizer.decode(outputs[0], skip_special_tokens=True)4344# Find the start of the actual response45start_index = output.find("assistant")46if start_index !=-1:47# Remove the initial part including "assistant"48 output = output[start_index +len("assistant"):].strip()4950print(output)
You will get something like:
<reasoning>
Pi is an irrational number, which means it cannot be exactly calculated as it has an infinite number of decimal places. However, we can approximate pi using various mathematical formulas. One of the simplest methods is the Leibniz formula for pi, which is an infinite series:
pi = 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 +...)
This series converges to pi as more terms are added.
</reasoning>
<answer>
The exact value of pi cannot be calculated due to its infinite decimal places. However, using the Leibniz formula, we can approximate pi to a certain number of decimal places. For example, after calculating the first 500 terms of the series, we get an approximation of pi as 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679.
</answer>
Intended Use
Granite-3.1-8B-Reasoning is designed for tasks requiring structured and logical reasoning, including:
Logical and analytical problem-solving
Text-based reasoning tasks
Mathematical and symbolic reasoning
Advanced instruction-following
Conversational AI with a focus on structured responses
This model is particularly useful for enterprise AI applications, research, and large-scale NLP tasks.
License & Acknowledgments
This model is released under the Apache 2.0 license. It is fine-tuned from IBM’s Granite 3.1-8B-Instruct model. Special thanks to the IBM Granite Team for developing the base model.