A LoRA adapter for microsoft/bitnet-b1.58-2B-4T-bf16 that recommends a quantum,
hybrid, or classical algorithm for a computational problem given hardware
constraints, and explains the choice in a fixed format.
Research prototype. Read the Limitations section before using or citing
this. Reported accuracy is not a measure of quantum-computing correctness.
⚠️ This model is not standalone
The adapter was trained on prompts that already contain a precomputed
resource-requirements block. Prompted without it, the model fabricates
requirements — measured: it claimed Grover's Algorithm needs ~2057 qubits for
a 20-bit search space (the correct value is 21), then reasoned validly from
its own false premise to the wrong recommendation.
QARE is therefore a hybrid system:
Component
Role
knowledge_base.py
Deterministic resource estimation + feasibility — makes the decision
BitNet + this LoRA
Ranking, reasoning, natural-language explanation — narrates the decision
Always use qare_engine.py (included in this repo). It builds the required
prompt. Prompting the weights directly is a misuse.
Usage
python
1# files ship with this repo2from qare_engine import QAREEngine
34eng = QAREEngine(5 base="microsoft/bitnet-b1.58-2B-4T-bf16",6 adapter="USERNAME/qare-bitnet-lora",7)89out = eng.recommend(10 problem_type="unstructured_search",11 size=20,# log2 of the database size12 available_qubits=1000,13 noise="none",14 max_depth=100000,15 hardware="simulator",16 desired_accuracy=0.9,17)18print(out["text"])# model's explanation19print(out["kb_reference"])# deterministic KB answer (audit trail)
The engine constructs prompts of this form:
Problem: unstructured search on a 20-item database (log2) instance.
Hardware: simulator
Available qubits: 1000
Noise level: none
Max circuit depth: 100000
Desired accuracy: 0.9
Computed resource requirements (from a resource estimator):
Grover's Algorithm: needs 21 qubits, depth 805 -> FITS
Quantum Walk Search: needs 10 qubits, depth 121 -> FITS
Classical algorithm: 0 qubits, no circuit -> always available
Completion-only masking (loss on the answer, not the templated prompt)
Hardware
~26 min on a single A100
Dataset
No public problem→quantum-algorithm recommendation dataset exists. Data is
synthetic, generated by sampling problem/hardware configurations and
labeling them with a deterministic rule-based knowledge base encoding standard
complexity and NISQ-era hardware facts (Shor 1994; Grover 1996; Farhi et al.
2014; Peruzzo et al. 2014; Harrow–Hassidim–Lloyd 2009; Preskill 2018; Nielsen &
Chuang). No copyrighted text is reproduced — only structured facts. ~60% of
labels are "use a classical algorithm," which reflects genuine NISQ-era
practicality.
Evaluation — read this carefully
Top-1 accuracy on 30 held-out test examples, vs the untrained base model:
Prompt variant
Zero-shot
Fine-tuned
Δ
McNemar p
95% CI
v1 — no computed requirements
0.233
0.133
−0.10
0.51
[−0.30, +0.10]
v3 — requirements + FITS/BLOCKED verdict
0.700
1.000
+0.30
0.0039
[+0.13, +0.47]
v3 fixed 9 examples and broke 0. The improvement is statistically significant.
🚨 The headline number is inflated by label leakage
The v3 prompt includes the knowledge base's own feasibility verdict
(-> FITS / -> BLOCKED). That is the decision. The task partly collapses to
"pick the first item marked FITS," solvable without any quantum knowledge —
which is exactly why the zero-shot score jumped from 0.233 to 0.700 for a
model that knows nothing about QARE.
Do not read 1.00 as quantum-algorithm competence. A cleaner ablation
(numbers supplied, verdict withheld, forcing the model to compare rather than
derive) is the correct next experiment and has not been run.
The interesting finding
Training loss reached 0.09 while test top-1 was 0.133 — near-perfect loss
alongside near-total task failure. Two causes, both instructive:
Loss originally included the highly templated prompt, so it was dominated by
trivially predictable tokens (fixed via completion-only masking).
The model learned the form of technical reasoning long before the
content — it produced correctly-structured justifications built on
fabricated numbers.
Takeaway: a 2B instruction-tuned model can learn a technical schema without
learning the underlying quantitative constraints. Low loss on templated output
can mask complete failure. Inspecting raw generations caught what the metric hid.
Limitations
Not standalone — requires qare_engine.py; otherwise it invents requirements.
Leaked evaluation — the 1.00 reflects a partly-given answer (see above).
Circular ground truth — test labels come from the same KB as training data.
This measures learning the KB, not objective correctness. A real accuracy
claim needs an expert-reviewed test set.
Small eval — n=30 (BitNet generation in transformers is slow). Wide CIs.
Order-of-magnitude KB — qubit/depth formulas are approximations, not
compiler-exact. Swap in Qiskit / Azure QRE for hardened estimates.
Not ternary at runtime — this is the BF16 master-weights path, a dense
~2.4B model. transformers has no optimized BitNet kernels; 1.58-bit
efficiency requires bitnet.cpp with
the packed repo.
Not hardware-validated — no recommendation here has been checked against a
real quantum device. Do not use for research or procurement decisions.
Intended use
Research and educational demonstration of (a) instruction-tuning a 1.58-bit
model with LoRA, and (b) hybrid symbolic + LM system design where a
deterministic engine owns correctness and the LM owns explanation.
Out of scope: production quantum-algorithm selection, hardware procurement,
or any decision where a wrong recommendation carries cost.
Reproducing
Full pipeline (data generation → training → evaluation → significance testing →
inference) is in the project's all-in-one Colab notebook.
Citation
bibtex
1@software{qare_bitnet_2026,
2 title = {QARE: A Quantum Algorithm Recommendation Engine via LoRA
3 Fine-Tuning of BitNet b1.58},
4 year = {2026},
5 note = {Research prototype. Reported accuracy is affected by
6 evaluation label leakage; see model card.}
7}
License
MIT (inherited from microsoft/bitnet-b1.58-2B-4T).