Text Generation
Transformers
English
qtensorformer
tensor-networks
model-compression
adaptive-computation
kv-cache-compression
hardware-aware
energy-aware
quantum-machine-learning
green-ai
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")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Premchan369/Q-TensorFormer", 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
File size: 2,130 Bytes
0b7ee79 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # SOURCE API FINAL: Standard Model & Configuration Interfaces
**Date**: September 17, 2026
**Repository**: `Premchan369/Q-TensorFormer`
---
## 1. Canonical Model Configuration Interface
```python
from src.config import ModelConfig, validate_model_config
# Canonical ModelConfig hyperparameter signature
config = ModelConfig(
vocab_size=10000, # Vocabulary size
d_model=128, # Model embedding dimension
n_heads=4, # Number of attention heads
n_layers=2, # Number of transformer blocks
ff_multiplier=4, # Feed-forward expansion factor (D_ff = d_model * ff_multiplier)
max_seq_len=128, # Maximum sequence context length
dropout=0.1, # Dropout rate
tt_rank=8, # Maximum Tensor-Train rank
tt_min_rank=2, # Minimum Tensor-Train rank
use_tensor_ffn=True, # Enable TT-FFN
n_qubits=4, # Number of quantum simulation wires
n_quantum_layers=2, # Number of variational circuit layers
quantum_sparsity=0.3, # Target quantum routing sparsity
use_quantum=True, # Enable quantum pathway
rank_alpha=2.0, # Rank allocation slope
rank_smoothing=0.9, # EMA rank smoothing factor
)
# Validate config against model requirements
validate_model_config(config, QTensorFormer)
```
---
## 2. Canonical Model Instantiation & Forward Pass
```python
from src.models import QTensorFormer, DenseBaseline
# Instantiate Q-TensorFormer
qtf = QTensorFormer(config, preset="QTF_BALANCED")
# Instantiate Apples-to-Apples Dense Baseline
dense = DenseBaseline(config)
# Forward pass
import torch
input_ids = torch.randint(0, config.vocab_size, (1, 32), dtype=torch.long)
logits_qtf = qtf(input_ids) # Shape: [1, 32, 10000]
logits_dense = dense(input_ids) # Shape: [1, 32, 10000]
```
---
## 3. Legacy Module Interoperability
Both `q_tensor_former.py` and `q_tensor_former_v2.py` accept the canonical `ModelConfig` directly:
```python
import q_tensor_former as qtf1
import q_tensor_former_v2 as qtf2
m1 = qtf1.QTensorFormer(config)
m2 = qtf2.QTensorFormer(config)
```
|