Q-TensorFormer / README.md
Premchan369's picture
Upload README.md
ea80a93 verified
|
Raw
History Blame
1.99 kB

Q-TensorFormer: Quantum-Enhanced Tensor Network LLM Compression Engine

A hybrid quantum-tensor transformer that adaptively compresses FFN layers using Tensor-Train decomposition and quantum feature encoding, guided by entanglement entropy.

Key Innovation

rank = r_min + α × S(ρ)

Where S(ρ) is the entanglement entropy (estimated from attention patterns). Higher entropy → higher tensor rank needed; lower entropy → more compression.

Architecture

Component Technology
FFN Layers Pure-PyTorch Tensor-Train (TT) decomposition
Feature Encoding PennyLane quantum angle embedding (4 qubits)
Attention Classical multi-head attention (stable)
Rank Scheduler Entanglement-guided adaptive rank
Quantum Router Selective: only "hard" tokens → quantum circuit

Benchmark Results

Config: d_model=64, 2 layers, 4 heads, TT-rank=8, 4 qubits

Metric Q-TensorFormer Baseline
Parameters 115,292 167,808
Val Perplexity 925.7 923.5
Model Size (MB) 0.4 0.6
Compression 1.5× fewer params
PPL Ratio 1.00×

✅ 31.3% parameter reduction with identical perplexity!

File Structure

q_tensor_former.py    — Full self-contained implementation (480+ lines)
                      — PureTTLinear, QuantumEmbed, TTFFN, RankScheduler,
                        QuantumRouter, MHA, HybridBlock, QTensorFormer,
                        Baseline, training + evaluation pipeline

Dependencies

pip install torch pennylane

Quick Start

python q_tensor_former.py

Runs a full benchmark: trains Q-TensorFormer and Baseline, evaluates both, and prints the comparison.

Citation

@software{q_tensorformer,
  title = {Q-TensorFormer: Quantum-Enhanced Tensor Network LLM Compression},
  year = {2026},
  url = {https://huggingface.co/Premchan369/q-tensorformer}
}