Text Generation
Transformers
Safetensors
granite
code
qiskit
conversational
File size: 8,533 Bytes
3f13c0e
 
 
 
 
ca54cc3
 
3f13c0e
ca54cc3
3f13c0e
 
ca54cc3
 
 
 
 
3f13c0e
 
dccef41
 
3f13c0e
 
 
 
a7e67e0
fe4fe9a
3f13c0e
 
 
 
a7e67e0
 
3f13c0e
 
 
 
 
 
 
 
 
a7e67e0
3f13c0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c26a811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2eeafd3
c26a811
 
2eeafd3
c26a811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f13c0e
 
 
 
a7e67e0
3f13c0e
 
 
 
 
 
 
ca54cc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
pipeline_tag: text-generation
inference: false
license: apache-2.0
datasets:
- public-qiskit
- synthetic-qiskit
metrics:
- code_eval
library_name: transformers
tags:
- code
- granite
- qiskit
base_model:
- ibm-granite/granite-3.2-8b-instruct
---

![image/png](https://cdn-uploads.huggingface.co/production/uploads/66376b02dd21d441c54d57c6/1oXnXbn088yLgAgHs0aZE.png)

# granite-3.2-8b-qiskit

## Model Summary

**granite-3.2-8b-qiskit** is a 8B parameter model extend pretrained and fine tuned on top of granite3.1-8b-base using Qiskit code and instruction data to improve capabilities at writing high-quality and non-deprecated Qiskit code. We used only data with the following licenses: Apache 2.0, MIT, the Unlicense, Mulan PSL Version 2, BSD-2, BSD-3, and Creative Commons Attribution 4.0. 
The model has been trained with **Qiskit version 2.0**, ensuring compatibility with its APIs and syntax.
- **Developers:** IBM Quantum & IBM Research
- **GitHub Repository:** Pending
- **Related Papers:** [Qiskit Code Assistant: Training LLMs for
generating Quantum Computing Code](https://arxiv.org/abs/2405.19495) and [Qiskit HumanEval: An Evaluation Benchmark For Quantum Code Generative Models](https://arxiv.org/abs/2406.14712)
- **Release Date**: 06-03-2025
- **License:** apache-2.0

## Usage

### Intended use

This model is designed for generating quantum computing code using Qiskit. Both quantum computing practitionners and new Qiskit users can use this model as an assistant for building Qiskit code or responding to Qiskit coding related instructions and questions. 

### Generation

This is a simple example of how to use **granite-3.2-8b-qiskit** model.

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # or "cpu"
model_path = "qiskit/granite-3.2-8b-qiskit"
tokenizer = AutoTokenizer.from_pretrained(model_path)
# drop device_map if running on CPU
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
# change input text as desired
chat = [
    { "role": "user", "content": "Build a random circuit with 5 qubits" },
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
# tokenize the text
input_tokens = tokenizer(input_text, return_tensors="pt")
# move tokenized inputs to device
for i in input_tokens:
    input_tokens[i] = input_tokens[i].to(device)
# generate output tokens
output = model.generate(**input_tokens, max_new_tokens=128)
# decode output tokens into text
output = tokenizer.batch_decode(output)
# loop over the batch to print, in this example the batch size is 1
for i in output:
    print(i)
```

### Comparison of Qiskit models across benchmarks

  <table
    style="
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    font-family: Inter, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    box-shadow: 0 6px 18px rgba(12, 20, 29, 0.06);
    border-radius: 12px;
    overflow: hidden;
    table-layout: auto;
    box-sizing: border-box;
    margin: 16px 0;
    "
  >
    <thead>
      <tr>
        <th style="text-align:left; padding:12px 16px; background:linear-gradient(90deg,#f6f8fb,#eef3f9); color:#0b1220; font-weight:700; border-bottom:1px solid rgba(15,23,42,0.06);">
          Model
        </th>
        <th style="text-align:center; padding:12px 16px; background:linear-gradient(90deg,#f6f8fb,#eef3f9); color:#0b1220; font-weight:700; border-bottom:1px solid rgba(15,23,42,0.06);">
          QiskitHumanEval-Hard
        </th>
        <th style="text-align:center; padding:12px 16px; background:linear-gradient(90deg,#f6f8fb,#eef3f9); color:#0b1220; font-weight:700; border-bottom:1px solid rgba(15,23,42,0.06);">
          QiskitHumanEval
        </th>
        <th style="text-align:center; padding:12px 16px; background:linear-gradient(90deg,#f6f8fb,#eef3f9); color:#0b1220; font-weight:700; border-bottom:1px solid rgba(15,23,42,0.06);">
          HumanEval
        </th>
      </tr>
    </thead>
    <tbody>
      <tr style="background:#f7fafc;">
        <td style="padding:12px 16px; font-weight:700; color:#07102a;">Qwen2.5-Coder-14B-Qiskit</td>
        <td style="padding:12px 16px; text-align:center; font-weight:700; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">25.16</td>
        <td style="padding:12px 16px; text-align:center; font-weight:700; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">49.01</td>
        <td style="padding:12px 16px; text-align:center; font-weight:700; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">91.46</td>
      </tr>
      <tr style="background:#ffffff;">
        <td style="padding:12px 16px; color:#0f172a;">mistral-small-3.2-24b-qiskit</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">20.53</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">40.39</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">77.49</td>
      </tr>
      <tr style="background:#ffffff;">
        <td style="padding:12px 16px; color:#0f172a;">granite-3.3-8b-qiskit</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">14.56</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">27.15</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">62.80</td>
      </tr>
      <tr style="background:#fbfdff;">
        <td style="padding:12px 16px; color:#0f172a;">granite-3.2-8b-qiskit</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">9.93</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">24.50</td>
        <td style="padding:12px 16px; text-align:center; font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;">57.31</td>
      </tr>
    </tbody>
  </table>


## Training Data

- **Data Collection and Filtering:** Our code data is sourced from a combination of publicly available datasets (e.g., Code available on <https://github.com>), and additional synthetic data generated at IBM Quantum. We exclude code that is older than 2023.
- **Exact and Fuzzy Deduplication:** We use both exact and fuzzy deduplication to remove documents having (near) identical code content.
- **HAP, PII, Malware Filtering:** We rely on the base model ibm-granite/granite-3.1-8b-code-base for HAP and malware filtering from the initial datasets used in the context of the base model. We also make sure to redact Personally Identifiable Information (PII) in our datasets by replacing PII content (e.g., names, email addresses, keys, passwords) with corresponding tokens (e.g., ⟨NAME⟩, ⟨EMAIL⟩, ⟨KEY⟩, ⟨PASSWORD⟩).

## Infrastructure

We train granite-3.2-8b-qiskit using IBM's super computing cluster (Vela) using NVIDIA A100 GPUs. The cluster provides a scalable and efficient infrastructure for training.

## Ethical Considerations and Limitations

The use of Large Language Models involves risks and ethical considerations people must be aware of. Regarding code generation, caution is urged against complete reliance on specific code models for crucial decisions or impactful information as the generated code is not guaranteed to work as intended. **granite-3.2-8b-qiskit** model is not the exception in this regard. Even though this model is suited for multiple code-related tasks, it has not undergone any safety alignment, there it may produce problematic outputs. Additionally, it remains uncertain whether smaller models might exhibit increased susceptibility to hallucination in generation scenarios by copying source code verbatim from the training dataset due to their reduced sizes and memorization capacities. This aspect is currently an active area of research, and we anticipate more rigorous exploration, comprehension, and mitigations in this domain. Regarding ethics, a latent risk associated with all Large Language Models is their malicious utilization. We urge the community to use **granite-3.2-8b-qiskit** model with ethical intentions and in a responsible way.