Downloads · 30 days
0
ibm-granite/granite-3.3-8b-alora-uncertainty
granite-3.3-8b-alora-uncertainty is a text generation model from ibm-granite. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Aug 8, 2025
Repo size
94.4 MB
Likes
1
Public
Click a slice to open those files.
.safetensors94.4 MB · 100%
From the Hugging Face model README
Welcome to Granite Experiments!
Think of Experiments as a preview of what's to come. These projects are still under development, but we wanted to let the open-source community take them for spin! Use them, break them, and help us build what's next for Granite – we'll keep an eye out for feedback and questions in the Community section. Happy exploring!
Granite 3.3 8b Instruct - Uncertainty is an Activated LoRA (aLoRA) adapter for ibm-granite/granite-3.3-8b-instruct, adding the capability to provide calibrated certainty scores when answering questions when prompted, in addition to retaining the full abilities of the ibm-granite/granite-3.3-8b-instruct model.
Activated LoRA (aLoRA) is a new low rank adapter architecture that allows for reusing existing base model KV cache for more efficient inference.
Github - needed to run inference
This is an experimental LoRA testing new functionality being developed for IBM's Granite LLM family. We are welcoming the community to test it out and give us feedback, but we are NOT recommending this model be used for real deployments at this time. Stay tuned for more updates on the Granite roadmap.
Certainty score definition The model will respond with a certainty percentage, quantized to 10 possible values (i.e. 5%, 15%, 25%,...95%). This percentage is calibrated in the following sense: given a set of answers assigned a certainty score of X%, approximately X% of these answers should be correct. See the eval experiment below for out-of-distribution verification of this behavior.
Certainty score interpretation Certainty scores calibrated as defined above may at times seem biased towards moderate certainty scores for the following reasons. Firstly, as humans we tend to be overconfident in our evaluation of what we know and don't know - in contrast, a calibrated model is less likely to output very high or very low confidence scores, as these imply certainty of correctness or incorrectness. Examples where you might see very low confidence scores might be on answers where the model's response was something to the effect of "I don't know", which is easy to evaluate as not being the correct answer to the question (though it is the appropriate one). Secondly, remember that the model is evaluating itself - correctness/incorrectness that may be obvious to us or to larger models may be less obvious to an 8b model. Finally, teaching a model every fact it knows and doesn't know is not possible, hence it must generalize to questions of wildly varying difficulty (some of which may be trick questions!) and to settings where it has not had its outputs judged. Intuitively, it does this by extrapolating based on related questions it has been evaluated on in training - this is an inherently inexact process and leads to some hedging.
Possible downstream use cases (not implemented)
Important note Certainty is inherently an intrinsic property of a model and its abilitities. Granite Uncertainty 3.3 8b is not intended to predict the certainty of responses generated by any other models besides itself or ibm-granite/granite-3.3-8b-instruct. Additionally, certainty scores are distributional quantities, and so will do well on realistic questions in aggregate, but in principle may have surprising scores on individual red-teamed examples.
Usage steps There are two supported usage scenarios.
Scenario 1. Answering a question and obtaining a certainty score proceeds as follows. Given a user query written in the user role:
assistant role).certainty role (use "certainty" as the role in the chat template, or simply append <|start_of_role|>certainty<|end_of_role|> and continue generating), see examples below.Scenario 2. Predicting the certainty score from the question only, prior to generating an answer. Given a user query written in the user role:
certainty role (use "certainty" as the role in the chat template, or simply append <|start_of_role|>certainty<|end_of_role|> and continue generating), see examples below.assistant role).The following code describes how to use the Granite Uncertainty model to answer questions and obtain intrinsic calibrated certainty scores. Note that no system prompt is used.
The code required for Activated LoRA is on Github
Prior to running the code below, either clone the repo or install as
pip install git+ssh://[email protected]:IBM/activated-lora.git
Note that two generation options are shown - one illustrating the KV cache reuse ability of aLoRA (faster), and another showing the simplest generation call (slower).
import torch,os
from transformers import AutoTokenizer, AutoModelForCausalLM, DynamicCache
from alora.peft_model_alora import aLoRAPeftModelForCausalLM
from alora.config import aLoraConfig
from alora.tokenize_alora import tokenize_alora
REUSE_CACHE = False
token = os.getenv("HF_MISTRAL_TOKEN")
BASE_NAME = "ibm-granite/granite-3.3-8b-instruct"
LORA_NAME = "ibm-granite/granite-3.3-8b-alora-uncertainty"
device=torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Load model
tokenizer = AutoTokenizer.from_pretrained(BASE_NAME,padding_side='left',trust_remote_code=True, token=token)
model_base = AutoModelForCausalLM.from_pretrained(BASE_NAME,device_map="auto")
model_UQ = aLoRAPeftModelForCausalLM.from_pretrained(model_base, LORA_NAME)
question = "What is IBM Research?"
print("Question:" + question)
question_chat = [
{
"role": "user",
"content": question
},
]
# Generate answer with base model
input_text = tokenizer.apply_chat_template(question_chat,tokenize=False,add_generation_prompt=True)
# Remove default system prompt
len_sys = len(input_text.split("<|start_of_role|>user")[0])
input_text = input_text[len_sys:]
#tokenize
inputs = tokenizer(input_text, return_tensors="pt")
if REUSE_CACHE: #save KV cache for future aLoRA call
prompt_cache = DynamicCache()
with model_UQ.disable_adapter():
output_dict = model_base.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=600,past_key_values = prompt_cache, return_dict_in_generate=True)
answer_cache = output_dict.past_key_values
output = output_dict.sequences
else: #simplest call
with model_UQ.disable_adapter():
output = model_UQ.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=600)
output_text = tokenizer.decode(output[0])
answer = output_text.split("assistant<|end_of_role|>")[1]
print("Answer: " + answer)
# Generate certainty score
uq_generation_prompt = "<|start_of_role|>certainty<|end_of_role|>"
uq_chat = question_chat + [
{
"role": "assistant",
"content": answer
},
]
uq_text = tokenizer.apply_chat_template(uq_chat,tokenize=False)
uq_text = uq_text[len_sys:]
# tokenize and generate
inputs, alora_offsets = tokenize_alora(tokenizer,uq_text, uq_generation_prompt)
if REUSE_CACHE: #reuse KV cache from earlier answer generation
output = model_UQ.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=1,alora_offsets=alora_offsets,past_key_values=answer_cache)
else: #simplest call
output = model_UQ.generate(inputs["input_ids"].to(device), attention_mask=inputs["attention_mask"].to(device), max_new_tokens=1,alora_offsets=alora_offsets)
output_text = tokenizer.decode(output[0])
# Extract score
uq_score = int(output_text[-1])
print("Certainty: " + str(5 + uq_score * 10) + "%")
The model was evaluated on the MMLU datasets (not used in training). Shown are the Expected Calibration Error (ECE) for each task, for the base model (Granite-3.2-8b-instruct) and Granite-Uncertainty-3.2-8b. The average ECE across tasks for our method is 0.064 (out of 1) and is consistently low across tasks (maximum task ECE 0.10), compared to the base model average ECE of 0.20 and maximum task ECE of 0.60. Note that our ECE of 0.064 is smaller than the gap between the quantized certainty outputs (10% quantization steps). Additionally, the zero-shot performance on the MMLU tasks does not degrade, averaging at 89%.
<!-- This section describes the evaluation protocols and provides the results. -->
The Granite Uncertainty 3.3 8b model is an aLoRA adapter finetuned to provide certainty scores mimicking the output of a calibrator trained via the method in [Shen et al. ICML 2024] Thermometer: Towards Universal Calibration for Large Language Models.
The following datasets were used for calibration and/or finetuning.
Kristjan Greenewald