Run this model with HF Jobs
Run itsalissonsilva/QuantumCoder-9B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/itsalissonsilva/QuantumCoder-9B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/itsalissonsilva/QuantumCoder-9B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/itsalissonsilva/QuantumCoder-9B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/itsalissonsilva/QuantumCoder-9B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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
Preserve all-framework quantum adapter and paired baseline before final generation; no release claim
Browse filesFiles changed (5)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207---base_model: Qwen/Qwen3.5-9Blibrary_name: peftpipeline_tag: text-generationtags:- base_model:adapter:Qwen/Qwen3.5-9B- lora- transformers---
# Model Card for Model ID
<!-- Provide a quick summary of what the model is/does. -->
## Model Details
### Model Description
<!-- Provide a longer summary of what this model is. -->
- **Developed by:** [More Information Needed]- **Funded by [optional]:** [More Information Needed]- **Shared by [optional]:** [More Information Needed]- **Model type:** [More Information Needed]- **Language(s) (NLP):** [More Information Needed]- **License:** [More Information Needed]- **Finetuned from model [optional]:** [More Information Needed]
### Model Sources [optional]
<!-- Provide the basic links for the model. -->
- **Repository:** [More Information Needed]- **Paper [optional]:** [More Information Needed]- **Demo [optional]:** [More Information Needed]
## Uses
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
### Direct Use
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
[More Information Needed]
### Downstream Use [optional]
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
[More Information Needed]
### Out-of-Scope Use
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
[More Information Needed]
## Bias, Risks, and Limitations
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
[More Information Needed]
### Recommendations
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
## How to Get Started with the Model
Use the code below to get started with the model.
[More Information Needed]
## Training Details
### Training Data
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
[More Information Needed]
### Training Procedure
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
#### Preprocessing [optional]
[More Information Needed]
#### Training Hyperparameters
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
#### Speeds, Sizes, Times [optional]
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
[More Information Needed]
## Evaluation
<!-- This section describes the evaluation protocols and provides the results. -->
### Testing Data, Factors & Metrics
#### Testing Data
<!-- This should link to a Dataset Card if possible. -->
[More Information Needed]
#### Factors
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
[More Information Needed]
#### Metrics
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
[More Information Needed]
### Results
[More Information Needed]
#### Summary
## Model Examination [optional]
<!-- Relevant interpretability work for the model goes here -->
[More Information Needed]
## Environmental Impact
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
- **Hardware Type:** [More Information Needed]- **Hours used:** [More Information Needed]- **Cloud Provider:** [More Information Needed]- **Compute Region:** [More Information Needed]- **Carbon Emitted:** [More Information Needed]
## Technical Specifications [optional]
### Model Architecture and Objective
[More Information Needed]
### Compute Infrastructure
[More Information Needed]
#### Hardware
[More Information Needed]
#### Software
[More Information Needed]
## Citation [optional]
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
**BibTeX:**
[More Information Needed]
**APA:**
[More Information Needed]
## Glossary [optional]
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
[More Information Needed]
## More Information [optional]
[More Information Needed]
## Model Card Authors [optional]
[More Information Needed]
## Model Card Contact
[More Information Needed]### Framework versions
- PEFT 0.18.1123456789101112131415161718192021222324252627282930313233343536373839404142{ "alora_invocation_tokens": null, "alpha_pattern": {}, "arrow_config": null, "auto_mapping": null, "base_model_name_or_path": "Qwen/Qwen3.5-9B", "bias": "none", "corda_config": null, "ensure_weight_tying": false, "eva_config": null, "exclude_modules": null, "fan_in_fan_out": false, "inference_mode": true, "init_lora_weights": true, "layer_replication": null, "layers_pattern": null, "layers_to_transform": null, "loftq_config": {}, "lora_alpha": 32, "lora_bias": false, "lora_dropout": 0.0, "megatron_config": null, "megatron_core": "megatron.core", "modules_to_save": null, "peft_type": "LORA", "peft_version": "0.18.1", "qalora_group_size": 16, "r": 16, "rank_pattern": {}, "revision": null, "target_modules": [ "in_proj_qkv", "q_proj", "v_proj" ], "target_parameters": null, "task_type": "CAUSAL_LM", "trainable_token_indices": null, "use_dora": false, "use_qalora": false, "use_rslora": false}123version https://git-lfs.github.com/spec/v1oid sha256:0261aa5f75e7966692383136ec7d5ac7fc9ab9caaeb94483ceba5bcbda932823size 27799552123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201"""Fresh all-framework quantum-program SFT with separate circuit/size stress holdouts."""
import hashlibimport jsonimport randomimport timefrom pathlib import Pathimport torchfrom huggingface_hub import HfApi, hf_hub_downloadfrom peft import LoraConfig, get_peft_modelfrom transformers import AutoTokenizer, Qwen3_5ForConditionalGeneration
REPO = "itsalissonsilva/QuantumCoder-9B"BASE = "Qwen/Qwen3.5-9B"
def main(): start = time.monotonic() torch.manual_seed(20261101) torch.set_num_threads(4) api = HfApi() data_rev = api.model_info(REPO).sha assert api.model_info(REPO).private file = Path(hf_hub_download(REPO, "curriculum_v2/rows.json", revision=data_rev)) manifest = json.loads( Path(hf_hub_download(REPO, "curriculum_v2/manifest.json", revision=data_rev)).read_text() ) assert hashlib.sha256(file.read_bytes()).hexdigest() == manifest["rows_sha256"] all_rows = json.loads(file.read_text()) rows = { s: [r for r in all_rows if r["split"] == s] for s in ["train", "validation", "test_iid", "test_stress"] } groups = {s: {r["group_id"] for r in rs} for s, rs in rows.items()} assert all( not groups[a] & groups[b] for i, a in enumerate(groups) for b in list(groups)[i + 1 :] ) original = json.loads( Path( hf_hub_download(REPO, "hf_pilot/generation_report.json", revision=data_rev) ).read_text() ) revision = original["base_revision"] tokenizer = AutoTokenizer.from_pretrained(BASE, revision=revision) tokenizer.padding_side = "left" model = Qwen3_5ForConditionalGeneration.from_pretrained( BASE, revision=revision, dtype=torch.bfloat16, device_map="cuda", attn_implementation="sdpa" )
def messages(row): return [ dict( role="system", content="Return only Python source code using the requested quantum framework. No prose or markdown.", ), dict( role="user", content=f"Write a {row['framework']} program preparing this circuit from zero on {row['qubits']} qubits. Operations [gate,qubits,angle]: {row['operations_json']}. Angles are radians. Store the final statevector in a variable named state. Use little-endian qubit order.", ), ]
def prompt(row): return tokenizer.apply_chat_template( messages(row), tokenize=False, add_generation_prompt=True, enable_thinking=False )
report = dict( base_model=BASE, base_revision=revision, data_revision=data_rev, manifest=manifest, seed=20261101, conditions={}, protocol="Distinct follow-up to the failed zero-shot-Cirq experiment. Fresh circuit groups, all three frameworks trained, RZ included; unseen angles and separate five/six-qubit longer/nonlocal stress. One fixed epoch from the base model, no original-test reuse or test checkpoint selection.", training=dict(epochs=1, rank=16, alpha=32, learning_rate=2e-5, gradient_accumulation=8), generation=dict(do_sample=False, max_new_tokens=768, batch_size=8, thinking=False), ) eos = model.generation_config.eos_token_id eos = set(eos if isinstance(eos, list) else [eos])
@torch.no_grad() def evaluate(condition): model.eval() outputs = [] for split in ["validation", "test_iid", "test_stress"]: for begin in range(0, len(rows[split]), 8): batch = rows[split][begin : begin + 8] inputs = tokenizer( [prompt(r) for r in batch], padding=True, return_tensors="pt" ).to("cuda") generated = model.generate( **inputs, max_new_tokens=768, do_sample=False, pad_token_id=tokenizer.pad_token_id, ) for row, tokens in zip( batch, generated[:, inputs["input_ids"].shape[1] :], strict=True ): ids = tokens.tolist() stop = next((i for i, t in enumerate(ids) if t in eos), None) used = ids if stop is None else ids[: stop + 1] outputs.append( dict( id=row["id"], group_id=row["group_id"], split=split, framework=row["framework"], qubits=row["qubits"], program=tokenizer.decode(used, skip_special_tokens=True), generated_tokens=len(used), eos_observed=stop is not None, at_token_cap=stop is None and len(used) >= 768, ) ) print( json.dumps( dict(stage="generated", condition=condition, split=split, n=len(rows[split])) ), flush=True, ) return outputs
report["conditions"]["base"] = evaluate("base") model = get_peft_model( model, LoraConfig( r=16, lora_alpha=32, lora_dropout=0.0, target_modules=["q_proj", "v_proj", "in_proj_qkv"], bias="none", task_type="CAUSAL_LM", ), ) model.gradient_checkpointing_enable() model.enable_input_require_grads() model.config.use_cache = False optimizer = torch.optim.AdamW([p for p in model.parameters() if p.requires_grad], lr=2e-5) train = list(rows["train"]) random.Random(20261101).shuffle(train) optimizer.zero_grad() losses = [] model.train() for i, row in enumerate(train): prefix = tokenizer(prompt(row), add_special_tokens=False)["input_ids"] answer = tokenizer(row["program"] + tokenizer.eos_token, add_special_tokens=False)[ "input_ids" ] assert len(prefix) + len(answer) <= 2048 ids = torch.tensor([prefix + answer], device="cuda") labels = torch.tensor([[-100] * len(prefix) + answer], device="cuda") loss = model(input_ids=ids, attention_mask=torch.ones_like(ids), labels=labels).loss assert torch.isfinite(loss) (loss / 8).backward() losses.append(float(loss.detach())) if (i + 1) % 8 == 0 or i + 1 == len(train): torch.nn.utils.clip_grad_norm_([p for p in model.parameters() if p.requires_grad], 1) optimizer.step() optimizer.zero_grad() if (i + 1) % 64 == 0: print( json.dumps( dict( stage="training", examples=i + 1, mean_last_loss=sum(losses[-64:]) / len(losses[-64:]), ) ), flush=True, ) folder = Path("quantum_v2_run") folder.mkdir(exist_ok=True) model.save_pretrained(folder / "adapter") report["train_loss"] = losses (folder / "generation_report.json").write_text(json.dumps(report, indent=2)) (folder / "train_quantum_v2_pilot.py").write_bytes(Path(__file__).read_bytes()) api.upload_folder( repo_id=REPO, folder_path=str(folder), path_in_repo="curriculum_v2_run", commit_message="Preserve all-framework quantum adapter and paired baseline before final generation; no release claim", ) model.config.use_cache = True model.gradient_checkpointing_disable() report["conditions"]["adapted"] = evaluate("adapted") report["elapsed_seconds"] = time.monotonic() - start report["gate"] = ( "Independent reference-validated execution, held-out circuit/state fidelity and base comparison are required before publication. A perfect deterministic renderer exists for this structured input; no quantum algorithm-discovery claim." ) (folder / "generation_report.json").write_text(json.dumps(report, indent=2)) api.upload_folder( repo_id=REPO, folder_path=str(folder), path_in_repo="curriculum_v2_run", commit_message="Freeze base/adapted quantum programs on fresh circuit and larger/nonlocal stress holdouts for independent execution", )
if __name__ == "__main__": main()curriculum_v2_run/adapter/README.mdAdded+207
curriculum_v2_run/adapter/adapter_config.jsonAdded+42
curriculum_v2_run/adapter/adapter_model.safetensorsAdded+3
curriculum_v2_run/generation_report.jsonAdded
curriculum_v2_run/train_quantum_v2_pilot.pyAdded+201