Instructions to use itsalissonsilva/QuantumCoder-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use itsalissonsilva/QuantumCoder-9B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-9B") model = PeftModel.from_pretrained(base_model, "itsalissonsilva/QuantumCoder-9B") - Notebooks
- Google Colab
- Kaggle
Stage bounded offline public re-scoring script for a clean execution check before release
Browse files
release_candidate/reproduce_execution.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Offline re-scoring of frozen programs; Linux/root/libseccomp are required.
|
| 2 |
+
|
| 3 |
+
Never replace the sandbox with direct exec. All generated programs run only in
|
| 4 |
+
its credential-cleared nobody workers with filesystem/network denial.
|
| 5 |
+
"""
|
| 6 |
+
import ast
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
from collections import defaultdict
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
import numpy as np
|
| 13 |
+
import quantum_sandbox_v2 as sandbox
|
| 14 |
+
|
| 15 |
+
ROOT=Path(__file__).resolve().parent
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def score(program,row):
|
| 19 |
+
wrapped=re.fullmatch(r"\s*```(?:python)?\s*\n(.*?)\n```\s*",program,flags=re.S)
|
| 20 |
+
clean=wrapped.group(1) if wrapped else program
|
| 21 |
+
imports=set()
|
| 22 |
+
try:
|
| 23 |
+
for node in ast.walk(ast.parse(clean)):
|
| 24 |
+
if isinstance(node,ast.Import):imports.update(a.name.split(".")[0] for a in node.names)
|
| 25 |
+
elif isinstance(node,ast.ImportFrom):imports.add((node.module or "").split(".")[0])
|
| 26 |
+
except SyntaxError:
|
| 27 |
+
pass
|
| 28 |
+
result=sandbox.run(clean,row["qubits"])
|
| 29 |
+
passed=False
|
| 30 |
+
if result.get("status")=="executed":
|
| 31 |
+
actual=np.array(result["real"])+1j*np.array(result["imag"])
|
| 32 |
+
target=np.array(row["state_real"])+1j*np.array(row["state_imag"])
|
| 33 |
+
passed=abs(result["norm"]-1)<1e-6 and abs(np.vdot(target,actual))**2>1-1e-6 and row["framework"] in imports
|
| 34 |
+
return bool(passed)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def main():
|
| 38 |
+
frozen=json.loads((ROOT/"v2_execution/execution.json").read_text())
|
| 39 |
+
preflight=json.loads((ROOT/"v2_executor_preflight/preflight.json").read_text())
|
| 40 |
+
assert preflight["all_passed"] and len(preflight["reference_checks"])==1368
|
| 41 |
+
assert hashlib.sha256(Path(sandbox.__file__).read_bytes()).hexdigest()==frozen["executor_sha256"]==preflight["executor_sha256"]
|
| 42 |
+
file=ROOT/"curriculum_v2/rows.json"
|
| 43 |
+
assert hashlib.sha256(file.read_bytes()).hexdigest()==preflight["manifest"]["rows_sha256"]
|
| 44 |
+
rows={r["id"]:r for r in json.loads(file.read_text()) if r["split"]!="train"}
|
| 45 |
+
assert len(rows)==720
|
| 46 |
+
versions=sandbox.initialize()
|
| 47 |
+
assert versions==frozen["versions"]
|
| 48 |
+
assert sandbox.run("",1,mode="isolation_check")==preflight["isolation"]
|
| 49 |
+
for row in rows.values():
|
| 50 |
+
assert score(row["program"],row),"Reference failed; stop before scoring generated programs"
|
| 51 |
+
outputs=json.loads((ROOT/"curriculum_v2_run/generation_report.json").read_text())["conditions"]
|
| 52 |
+
totals=defaultdict(lambda:dict(n=0,passed=0))
|
| 53 |
+
for condition in ["base","adapted"]:
|
| 54 |
+
assert len(outputs[condition])==720 and {r["id"] for r in outputs[condition]}==set(rows)
|
| 55 |
+
for output in outputs[condition]:
|
| 56 |
+
row=rows[output["id"]];passed=score(output["program"],row)
|
| 57 |
+
for framework in ["all",row["framework"]]:
|
| 58 |
+
key=condition+"/"+row["split"]+"/"+framework
|
| 59 |
+
totals[key]["n"]+=1;totals[key]["passed"]+=passed
|
| 60 |
+
for key,value in totals.items():
|
| 61 |
+
condition,split,framework=key.split("/")
|
| 62 |
+
original=frozen["summary"][condition][split+"/"+framework]
|
| 63 |
+
assert value==dict(n=original["n"],passed=original["passed"]),(key,value,original)
|
| 64 |
+
result=dict(versions=versions,all_counts_reproduced=True,summary=dict(totals))
|
| 65 |
+
(ROOT/"reproduced_counts.json").write_text(json.dumps(result,indent=2)+"\n")
|
| 66 |
+
print(json.dumps(result,indent=2))
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
if __name__=="__main__":main()
|