Text Generation
Transformers
Safetensors
PyTorch
ONNX
English
qtensorformer
qtf
q-tensorformer
qtensor
high-throughput-inference
tensor-train
tensor-networks
tensorrt-llm
vllm
continuous-batching
paged-attention
speculative-decoding
zero-svd
adaptive-computation
dynamic-neural-networks
kv-cache
kv-cache-quantization
attention-sinks
lyapunov-stability
control-theory
contextual-bandits
edge-ai
edge-inference
on-device-ai
model-compression
hopper-h100
blackwell-b200
jetson-orin
jetson-thor
grouped-query-attention
rotary-position-embeddings
custom_code
academic-paper
ieee
neurips
vit-ap-university
deepseek
deepseek-r1
reasoning
chain-of-thought
gsm8k
openai-compatible
fastapi
rest-api
sse-streaming
onnx-runtime
embedded-ai
hardware-telemetry
power-efficiency
green-ai
raspberry-pi
smollm2
qwen2.5
llama-3.2
apple-silicon
Run this model with HF Jobs
Run Premchan369/Q-TensorFormer 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 and TRL to fine-tune https://huggingface.co/Premchan369/Q-TensorFormer. 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/Premchan369/Q-TensorFormer 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/Premchan369/Q-TensorFormer. 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/Premchan369/Q-TensorFormer. 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 Premchan369/Q-TensorFormer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Premchan369/Q-TensorFormer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Premchan369/Q-TensorFormer", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Premchan369/Q-TensorFormer", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Premchan369/Q-TensorFormer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Premchan369/Q-TensorFormer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Premchan369/Q-TensorFormer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Premchan369/Q-TensorFormer
- SGLang
How to use Premchan369/Q-TensorFormer with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Premchan369/Q-TensorFormer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Premchan369/Q-TensorFormer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Premchan369/Q-TensorFormer" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Premchan369/Q-TensorFormer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Premchan369/Q-TensorFormer with Docker Model Runner:
docker model run hf.co/Premchan369/Q-TensorFormer
Update README.md
Browse files149 unmodified lines150151152149 unmodified linesRange : 0.855 to 1.666Mean : 1.340 (Std: 0.185)149 unmodified lines150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293149 unmodified linesRange : 0.855 to 1.666Mean : 1.340 (Std: 0.185)The model isn't guessing; it is *measuring* complexity at runtime.---## ๐๏ธ Architecture Flowchart```textTOKENS -> Embedding + Positional Encoding|+-----------v------------+| QUANTUM ENCODER | Angle encode -> entangle -> measure Z| S(rho) = -Tr(rho*log) | Von Neumann entropy computed per token+-----------+------------+|+-----------v------------+| SELECTIVE ROUTER | h_t = S(rho_t) / S_max| ~20% quantum path | h_t > theta -> quantum path| ~80% classical path | h_t <= theta -> classical fast-track+------+----------+------+quantum | | classical+------v------+ +-v------------------+| QKSAM | | Classical MHA ||K=|<pq|pk>|^2| | QK^T / sqrt(d) |+------+------+ +--+-----------------++-----+-----+|+------------v-----------+| TT-FFN / HQKAN | W = G1ยทG2...Gk (tensor-train)| DARUAN activation | harmonic feedback loop (learned)| r_t = r_min + a*S(rho) | rank adapts live per token+------------+-----------+| x N layersvLM HEAD -> LOGITS```---## ๐ Real-World Deployment Scenarios| Domain | The Problem | Q-TensorFormer Solution || :--- | :--- | :--- || ๐ฑ **Smartphones** | ChatGPT requires cloud servers and internet. | **5 MB model**, fully offline, zero data leaves the device. || ๐ **Autonomous Vehicles** | Edge GPU has 4 GB for everything. | **8ร compressed**, processes road scenes in <50 ms on car CPUs. || ๐ญ **Factory IoT** | 10,000 sensors, $10/GB satellite uplink. | **1.3M-param model** fits on a $5 chip per sensor. || ๐ **Rural Translation** | Satellite internet costs $10/GB. | Swahili โ English on Raspberry Pi, works forever offline. || ๐ฎ **Game NPCs** | Real AI NPCs kill the rendering GPU budget. | **500 unique NPCs** run simultaneously on background CPU threads. || ๐ก๏ธ **Finance Fraud** | Transaction data cannot leave the firewall. | Runs inside the local firewall, clearing 99% of transactions <1ms. |---## ๐ง Systems Engineering Features* **โก Budget-Constrained Training:** Set hard upper limits on parameter count, latency, or energy. The model automatically adjusts its routing threshold and tensor ranks during training to meet constraints.* **๐ Pareto Frontier Tracking:** Logs every accuracy-vs-efficiency tradeoff. Choose any point on the frontier matching your deployment target post-training.* **๐ 7 Hardware Profiles Built-in:** Model estimates energy consumption natively for Intel Xeon, Apple M2, NVIDIA A100/T4, Google Edge TPU, Mobile CPU, and IBM Quantum simulators.* **๐ง Straight-Through Gradient:** Quantum routing is a hard binary decision during inference, but uses a sigmoid approximation in the backward pass. The routing is entirely learnable end-to-end.* **โ๏ธ SVD-Based Rank Truncation:** Tensor cores are initialized via dominant singular vectors, preserving critical structural data instead of random projections.* **๐ QKAN to KAN Distillation:** DARUAN activations can be distilled into purely classical B-spline KANs for deployment on hardware with zero quantum simulation capabilities.---## โก Quick Start: Python Usage```pythonfrom src import ModelConfig, QTensorFormerfrom src.energy_v4 import EnergyEstimatorV4, estimate_model_energy# 1. Initialize the ultra-compressed modelconfig = ModelConfig(vocab_size=10000,d_model=128,n_layers=3,tt_rank=4,n_qubits=4,use_qkan=True)model = QTensorFormer(config)# 2. Run inferencelogits = model(input_ids) # shape: (batch, seq_len, vocab_size)# 3. Real-time Energy and Carbon Trackingestimator = EnergyEstimatorV4("edge_mobile")metrics = estimate_model_energy(model, estimator, seq_len=128)print(metrics)# Output:# {# "energy_uj": 60,# "carbon_per_query_ug": 0.007,# "latency_ms": 32,# "flops": 203000000,# "hardware": "edge_mobile"# }```### Available Hardware Cost Profiles```pythonEnergyEstimatorV4("edge_mobile") # 100 fJ/FLOP (Worst case, realistic for edge)EnergyEstimatorV4("cpu_xeon") # 10 fJ/FLOPEnergyEstimatorV4("apple_m2") # 2 fJ/FLOPEnergyEstimatorV4("gpu_a100") # 0.5 fJ/FLOPEnergyEstimatorV4("edge_tpu") # 0.3 fJ/FLOPEnergyEstimatorV4("quantum_sim") # Full PennyLane simulation overheadEnergyEstimatorV4("ibm_quantum") # Projected real hardware cost model```---## ๐ Novelty & Referenced Papers| Paper | ArXiv ID | Core Contribution & Q-TensorFormer Advance || :--- | :--- | :--- || **QKSAN** | `2308.13422` | Quantum kernel self-attention. *Advance: First NLP implementation (QKSAN was MNIST-only).* || **Quixer** | `2406.04305` | LCU & QSVT quantum transformers. *Advance: Simpler, faster kernel attention approach.* || **QKAN** | `2509.14026` | DARUAN activations. *Advance: First integration with adaptive tensor-train compression.* || **PennyLane** | `1811.04968` | Differentiable quantum circuits as PyTorch layers. || **HQLMs** | `2512.12710` | First quantum LM on real IBM hardware. *Advance: Q-TensorFormer works classically right now.* |---## โ ๏ธ Current Limitations* **Tokenizer:** Currently relies on a custom 10K vocab. Not yet fully integrated with the Hugging Face `transformers` ecosystem (AutoTokenizer).* **Scale Limits:** Tested up to 1.55M parameters. Scaling to billions of parameters requires distributed Tensor-Train core handlers.* **Quantum Simulation Overhead:** Testing on standard CPUs shows a +104% latency penalty due to PennyLane's matrix simulations. Native Quantum/Classical hybrid execution is required to realize the latency benefits.---<div align="center">**v4.0.0** ยท Apache-2.0 ยท Built by [Premchan369](https://huggingface.co/Premchan369)[๐ค Model Weights](https://huggingface.co/Premchan369/Q-TensorFormer) ยท[๐ Live Demo](https://huggingface.co/spaces/Premchan369/alphaforge-k2think) ยท [๐ Energy Source Code](https://huggingface.co/Premchan369/Q-TensorFormer/blob/main/src/energy_v4.py)</div>
README.md+141