Skip to content
Quantum Inspired Fine Tuning

Quantum Inspired Fine Tuning

github.com • November 18, 2026

Code of the paper "Quantum-inspired orthogonal adapters for certifiably robust medical image classification" ( arXiv:2611.18775 ). A pretrained network is adapted to a new task as R(θ)·W , with R(θ) an orthogonal butterfly of Givens rotations (RBS gates). R keeps every singular value of W, so the Lipschitz constant of a certified network, and with it its certified radius, survives the adaptation; LoRA and full fine-tuning do not keep it. The main example is trichoscopy, on the data of Caposiena Caro et al., "Analysis of trichoscopic images using deep neural networks for the diagnosis and activity assessment of alopecia areata", JDDG 2026;24:44–55 (DOI 10.1111/ddg.15847).

Each folder has its own README with every command and output. Data and every output live outside the repository.

Python 3.12 and an NVIDIA GPU with a CUDA 12 driver. The results were produced on an NVIDIA RTX 4070 Laptop GPU (8 GB) under Windows 11; some reproduction runs used an AWS machine with a Tesla T4.

requirements.txt pins every package and its dependencies (torch 2.5.1+cu121, torchvision 0.20.1+cu121, numpy 2.4.4, scipy 1.15.3, pillow 10.4.0, ...). The orthogonal layers, the certificate and the losses come from eigenkit 1.2.2, installed from PyPI. BRONet and its ImageNet checkpoint:

(ntuaislab/BRONet at commit 9d59c9b; checkpoint imagenet-14x588_399.pth , its sha256 is checked).

Set by environment variables, or by the same keys in paths.toml in the repository root (copy paths.example.toml ; not in git):

python -m repro.where (with PYTHONPATH=trichoscopy/src ) prints what is used. All python -m experiments... commands run from the repository root.

Reproducing the paper

The trichoscopy pipeline, per step (1 = diagnosis, 5 classes; 2 = alopecia areata activity, 3 classes); every stage is resumable:

Step 2 uses --n-images 240 (the whole test set) for the attacks. The figures and LaTeX tables of the paper are drawn from these files by the paper's plotting scripts, which are not part of this repository.

Controlled experiments

The MNIST, BloodMNIST → DermaMNIST, eps* (six seeds) and transform experiments of the paper (Fig. 2–5, 10, Table I) are in experiments/robustness , with its committed results/ . experiments.py --experiment ... writes most of the result files and the scripts in reproduce/ the rest; the folder's README gives every command and the environment the results were made in. Its core.py also holds the butterfly layer that the trichoscopy experiments import.

Seeds. Every run is seeded (python, numpy, torch, CUDA). The data order, the validation split, the adapter initialisation, the test subsets of the attacks and every random perturbation draw from their own seeded generators, so they do not depend on batch composition, worker count or a resume (checkpoints store the RNG state).

Deterministic kernels. Training sets torch.backends.cudnn.deterministic , disables cuDNN benchmarking, enables torch.use_deterministic_algorithms and sets CUBLAS_WORKSPACE_CONFIG=:4096:8 (when repro is imported); the trichoscopy experiments also disable TF32. --no-deterministic turns this off.

What is bit-identical. Training, tuning and evaluation repeat bit for bit on the same GPU model with the same driver and the builds of requirements.txt : repeated short trainings of every mode give identical weights, logits, radii and predictions, and python -m repro.selftest checks the repro training (repeat, resume, worker count). Across GPU generations or library versions the numbers agree to 1e-5, not bitwise (kernel choice; TF32 defaults of the repro CNNs).

Not bitwise. Feature caches re-extracted with another batch size or GPU agree to 1e-5. Attack gradients on the GPU are not forced to be deterministic, so success counts can differ in rare borderline cases; every reported success is re-evaluated exactly in float32 and checked against the certificate. JPEG results depend on the Pillow build (its version is recorded). The controlled experiments ( experiments/robustness ) are seeded but set no deterministic-kernel switches (their results were made on Apple MPS). Timings and absolute paths in config.json and provenance fields differ between machines.

Provenance. Every run records the code hash, the git commit and dirty flag, the package versions, the device, and the sha256 of the checkpoint, the feature cache and the data lists.

Run one suite per command: the bronet_mlp and resnet_adapt tests each import their own conftest by name, so two suites in one pytest call collide. Tests that need the data or BRONet skip themselves when those locations are not set (see "Locations"), so the suites also pass on a fresh clone. The slow tests of bronet_mlp need the data, the BRONet checkpoint and a GPU; those of resnet_adapt take minutes on the CPU. The robustness tests download MNIST into ./data of the working folder (ignored by git).

Two classification tasks:

Layout under DERMA_DATA_ROOT :

Labels are the sub-folder names ( 0 , 1 , ...); the mapping to class names is CLASS_NAMES in trichoscopy/src/repro/config.py and must not be reordered.

File names: P _ _ _ [-aug ].jpg , e.g. P0001_00001_aga_act.jpg .

P — anonymised patient code ( P0001 , P0002 , ...);

— acquisition id, normally 5 digits, occasionally with a trailing letter (e.g. 00002v ); P _ identifies the photograph;

_ — the clinical label suffix (e.g. aga_act ), already folded into the folder label; some photos were relabelled after the shoot, and the file names carry the final labels;

-aug — offline-augmented copy (rotation, colour jitter); absent on originals.

The split is by photograph, not by patient. The paper's step-1 test set (641 images, CHP 205) is a different split from the delivered one; step-2 matches it image for image.

Reference numbers of Caposiena Caro et al.

The test results of the paper (Tables 5 and 6). ImageNet-pretrained networks, head replaced by Linear(→256) → ReLU → Dropout → Linear(→K) , whole network fine-tuned:

Apache-2.0, see LICENSE .

Extracted Entities

Companies (1)

Platforms (1)