Q-Transformers: Quantum-Enhanced NLP
v0.1.0 - Library implementing quantum-inspired attention mechanisms for transformer models.
Table of contents
Key Features
- Drop-in PyTorch compatibility - Use with existing transformer code
- Multi-GPU distributed training - Quantum-aware gradient synchronization
- Docker/Kubernetes deployment - Containerized deployment
- Real quantum hardware support - IBM Quantum integration via Qiskit
- Comprehensive benchmarking - GLUE/SuperGLUE validation with 19 NLP tasks
Benchmarks
Benchmarks and evaluation scripts are provided under the benchmarks/ directory. Results depend on hardware, backend configuration, and random seeds; reproduce experiments using the provided scripts rather than relying on summarized claims in the README.
Developer Quick Start
The repository includes a Makefile with common developer tasks. Use the Makefile targets from the project root to build, run checks, and execute tests. The targets orchestrate the toolchain (Python, Rust) and ensure consistent environments across machines.
Common tasks:
- Build development image and prepare environment:
- Open an interactive shell with the repository mounted:
- Run Python unit tests:
- Run Rust tests:
- Run the full test suite (Python + Rust + integration):
If you need or prefer a local Python virtual environment, a local install is supported but may require system toolchains for some dependencies:
Basic Usage
# Drop-in replacement for nn.MultiheadAttention
=
# Use exactly like PyTorch MultiheadAttention
= # seq_len, batch, embed_dim
=
=
, =
Documentation
- Core Architecture - Technical overview and benchmarks
- Advanced Features - Quantum hardware integration
- Mathematical Foundations - Theory and algorithms
Benchmarking and Evaluation
# Run comprehensive NLP benchmarks
=
=
# Verify quantum supremacy
=
=
Technical Overview
Core Components
- Quantum-Inspired Attention: Sampling-based attention approximation with O(n·S) complexity where S << n
- Multi-GPU Training: Distributed training support with quantum-aware gradient synchronization
- Benchmark Suite: GLUE/SuperGLUE evaluation framework for reproducible experiments
Technical Approach
- Sampling-Based Approximation: Reduces full O(n²) attention to sparse sampling, trading exactness for efficiency
- Variance Reduction: Stratified sampling and control variates improve approximation quality (42% error reduction in internal benchmarks)
- Memory Efficiency: Sparse attention patterns reduce memory footprint
Note: Performance claims are based on internal benchmarks. Results may vary by hardware, configuration, and task. See
benchmarks/for reproduction scripts.
License
This project is licensed under the MIT License - see the LICENSE file for details.