HQDE - Hierarchical Quantum-Distributed Ensemble Learning
HQDE is a PyTorch research framework for scalable ensemble learning. It provides a common training API for multiple model replicas, optional Ray-backed workers, epoch-level FedAvg-style synchronization, adaptive delta quantization, and quantum-inspired aggregation utilities.
The project is intended for experimentation and thesis research. Reported accuracy, runtime, and memory numbers should come from your own executed benchmark logs or notebooks; this README does not claim fixed benchmark results.
What Works Today
| Area | Current status |
|---|---|
| Vision/CNN models | Supported through HQDESystem with standard (data, target) PyTorch dataloaders. |
| Ensemble training | independent mode for diverse workers, fedavg mode for epoch-level weight averaging. |
| Prediction aggregation | Mean or efficiency-weighted logit aggregation across workers. |
| Quantized communication | Available during fedavg aggregation through AdaptiveQuantizer. |
| Ray execution | Used when Ray is installed and available; otherwise HQDE falls back to local workers. |
| Transformer modules | Built-in transformer model classes and text utilities exist. Core HQDESystem currently expects tensor or tuple batches, not dict batches. |
| DeBERTa CBT notebook | Standalone Kaggle notebook with custom worker code that handles input_ids, attention_mask, and labels. |
Installation
From PyPI:
pip install hqde
From source:
git clone https://github.com/Prathmesh333/HQDE-PyPI.git
cd HQDE-PyPI
pip install -e .
For development tests, install the dev extras or install pytest separately:
pip install -e ".[dev]"
Quick Start: Vision Ensemble
from hqde import SmallImageResNet18, create_hqde_system, make_cifar_training_config
training_config = make_cifar_training_config(
ensemble_mode="independent",
batch_assignment="replicate",
prediction_aggregation="mean",
use_amp=True,
)
hqde_system = create_hqde_system(
model_class=SmallImageResNet18,
model_kwargs={"num_classes": 10},
num_workers=4,
training_config=training_config,
)
metrics = hqde_system.train(
train_loader,
num_epochs=20,
validation_loader=test_loader,
)
eval_metrics = hqde_system.evaluate(test_loader)
predictions = hqde_system.predict(test_loader)
hqde_system.cleanup()
The dataloader must yield either (data, targets) or a compatible list/tuple. Current core training does not consume dict batches.
Training Modes
Independent Ensemble
training_config = {
"ensemble_mode": "independent",
"batch_assignment": "replicate",
"prediction_aggregation": "mean",
}
Each worker receives the same batch and trains its own model copy. Workers remain diverse during training, and predictions are aggregated at inference time.
FedAvg-Style Epoch Aggregation
training_config = {
"ensemble_mode": "fedavg",
"batch_assignment": "split",
"training_aggregation": "sample_weighted",
"server_optimizer": "fedadam",
"federated_normalization": "local_bn",
}
Each batch is split across workers. At the end of each epoch, HQDE aggregates model deltas and broadcasts the server state back to workers. This is local-SGD/FedAvg-style training, not PyTorch DDP.
Quantization
Quantization is applied to model deltas during fedavg aggregation when a quantization_config is supplied.
quantization_config = {
"base_bits": 12,
"min_bits": 8,
"max_bits": 16,
"block_size": 1024,
"warmup_rounds": 5,
"skip_bias": True,
"skip_norm": True,
"error_feedback": True,
}
Small tensors, bias tensors, normalization tensors, and non-floating tensors are skipped by default. Compression ratios depend on model size, selected bit widths, and how many tensors are skipped.
Transformer Status
HQDE ships these transformer classes:
| Model | File | Purpose |
|---|---|---|
LightweightTransformerClassifier |
hqde/models/transformers.py |
Small text-classification experiments. |
TransformerTextClassifier |
hqde/models/transformers.py |
General encoder-based text classification. |
CBTTransformerClassifier |
hqde/models/transformers.py |
CBT-themed classifier with optional domain adapter. |
Important current limitation:
TextDataLoaderreturns dict batches withinput_ids,attention_mask, andlabels.HQDESystem.train()currently expects tuple/list batches and calls models asmodel(data).- Therefore the documented dict-batch text utility path is not yet fully plug-and-play with core
HQDESystem.
Working options today:
- Use the transformer classes directly outside
HQDESystem. - Use tuple-style dataloaders such as
(input_ids, labels)for simple built-in transformer experiments whereattention_maskcan be omitted. - Use the DeBERTa Kaggle notebook for masked HuggingFace-style transformer training; it has custom worker code for dict batches.
- Add dict-batch support to
HQDESystembefore presenting transformer support as fully plug-and-play.
See docs/TRANSFORMER_EXTENSION.md for details.
Kaggle DeBERTa CBT Notebook
The notebook examples/cbt_deberta_hqde_kaggle.ipynb is a standalone demonstration for CBT cognitive-distortion classification using DeBERTa workers.
It now supports:
- 2x T4 Kaggle GPU execution.
- Single-GPU and CPU smoke-test execution.
- Dynamic device selection instead of hard-coded
cuda:0andcuda:1. - Safe AMP usage only on CUDA.
HQDE_QUICK_TEST=1for short smoke runs.
The notebook uses a generated 100-sample toy dataset. Treat its metrics as demonstration output, not clinical evidence or a benchmark.
Project Layout
hqde/
core/
hqde_system.py # HQDESystem, workers, FedAvg, quantization
models/
vision.py # SmallImageResNet18
transformers.py # Built-in transformer classifiers
quantum/
quantum_aggregator.py # Quantum-inspired aggregation utilities
quantum_noise.py
quantum_optimization.py
distributed/
mapreduce_ensemble.py
hierarchical_aggregator.py
fault_tolerance.py
load_balancer.py
utils/
data_utils.py
text_data_utils.py
training_presets.py
transformer_presets.py
performance_monitor.py
Common Commands
python examples/quick_start.py
python test_imports.py
python test_transformer_integration.py
python validate_notebook.py
If pytest is installed:
python -m pytest -q
Documentation
- HOW_TO_RUN.md - Installation and usage guide.
- docs/TECHNICAL_DOCUMENTATION.md - Technical architecture notes.
- docs/TRANSFORMER_EXTENSION.md - Transformer support status and usage.
- README_KAGGLE_NOTEBOOKS.md - Kaggle notebook overview.
- QUICK_START_KAGGLE.md - Kaggle notebook run instructions.
Results Policy
Do not cite placeholder accuracy, runtime, memory, or compression numbers as thesis results. For thesis reporting:
- Run the exact script or notebook.
- Save the command, hardware, seed, package versions, and output files.
- Report mean and variance across repeated runs where possible.
- Distinguish synthetic toy data from real datasets.
Citation
@software{hqde2026,
title={HQDE: Hierarchical Quantum-Distributed Ensemble Learning},
author={Prathamesh Nikam},
year={2026},
url={https://github.com/Prathmesh333/HQDE-PyPI}
}
License
MIT License. See LICENSE.
Metadata
Release files for hqde 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hqde-0.1.12.tar.gz | 63.5 kB | Without provenance | Details for hqde-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hqde-0.1.12-py3-none-any.whl | Python 3 | none | any | Details for hqde-0.1.12-py3-none-any.whl |
Total release size: 130.1 kB
Release files / hqde-0.1.12.tar.gz
| Download URL | hqde-0.1.12.tar.gz |
|---|---|
| Size | 63.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
401ed24f0d6ce07f143e12725147947bafcc2eb48c95f6c971330c1a1ad3fb56
|
|
BLAKE2b-256 checksum How to use checksums |
07c6f292acc56f5eee2ddc27769526a98d6ab47eb712c786048d6dc2eaa8de01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / hqde-0.1.12-py3-none-any.whl
| Download URL | hqde-0.1.12-py3-none-any.whl |
|---|---|
| Size | 66.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fbcf3e46dd217adf07b14f7681251d3b06d351b9e4468a2a5e4e17c294ce74e6
|
|
BLAKE2b-256 checksum How to use checksums |
e8cc473ff2fbe1bc7cff00f7db7f963b305723e3cc1c7aea0938f65df9c41c0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Security for hqde 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.