Text Generation
Transformers
Safetensors
PyTorch
English
qtensorformer
q-tensorformer
tensor-train
tensor-networks
adaptive-computation
kv-cache
kv-cache-quantization
attention-sinks
pid-control
edge-ai
edge-inference
on-device-ai
model-compression
grouped-query-attention
rotary-position-embeddings
custom_code
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
Premchandyadav369
Complete 16-phase scientific hardening, strict checkpoint audit, empirical benchmarks, and documentation
7aefd9e |
Download reports/SOURCE_API_AUDIT.md from Premchan369/Q-TensorFormer: direct link, hf CLI and curl.
- Browser
- Download file 3.69 kB
-
https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/reports/SOURCE_API_AUDIT.md
- Command line
-
hf download hf://Premchan369/Q-TensorFormer/reports/SOURCE_API_AUDIT.md
-
curl -L -o SOURCE_API_AUDIT.md https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/reports/SOURCE_API_AUDIT.md
3.69 kB
Phase One — Source API & Execution Path Audit
1. Canonical Research API (src/)
1.1 src.config.ModelConfig
- File:
src/config.py - Fields:
d_model: int = 128n_heads: int = 4n_layers: int = 2ff_multiplier: int = 4max_seq_len: int = 128vocab_size: int = 10000dropout: float = 0.1tt_rank: int = 8tt_min_rank: int = 2use_tensor_ffn: bool = Truen_qubits: int = 4n_quantum_layers: int = 2quantum_sparsity: float = 0.3use_quantum: bool = Truerank_alpha: float = 2.0rank_smoothing: float = 0.9
- Validation:
ModelConfig.validate()assertsd_model % n_heads == 0,1 <= tt_min_rank <= tt_rank,n_qubits <= 8, and0 <= quantum_sparsity <= 1.validate_model_config(config, model_class)checks all required fields without inventing defaults.
1.2 src.models.QTensorFormer
- File:
src/models.py - Constructor:
QTensorFormer(config: ModelConfig, preset: str = "QTF_BALANCED") - Supported Presets:
QTF_FULL,QTF_BALANCED,QTF_LATENCY,QTF_MEMORY,QTF_ENERGY,QTF_EDGE,QTF_CLASSICAL_ONLY. - Execution Path (
forward):- Embeds
input_ids(nn.Embedding) + sinusoidalPositionalEncoding. - Iterates over
self.blocks(nn.ModuleListofHybridBlock):HybridBlockcallsself.info_engine(hidden_states=x)$\rightarrow z_t \in [0, 1]^{B \times T \times 8}$.HybridBlockcallsself.allocator(z_t, budget=budget, preset=preset, force_classical=...)$\rightarrow$ selectsrank,token_ranks,attn_mode_idx,depth_mode,kv_precision,is_quantum_token.- If
depth_mode == "skip", returns residualximmediately. - Updates
kv_cache.set_precision(kv_precision)ifkv_cacheis supplied. - Runs
self.attention(normed_x, mask=mask, kv_cache=kv_cache, use_quantum=has_quantum_attn and not force_classical). - Checks optional
early_exit_headifenable_early_exit=True. - If
depth_mode == "partial", skips FFN and returnsx. - Sets
self.tt_ffn.set_rank(chosen_rank)and executesself.tt_ffn(normed_ffn_in, token_ranks=token_ranks). - If
is_quantum_token.any()and notforce_classical, appliesself.quantum_backend(normed_ffn_in)masked byis_quantum_token.
- Applies final
self.ln_fand weight-tiedself.lm_head.
- Embeds
2. Canonical Hugging Face API (configuration_qtensorformer.py & modeling_qtensorformer.py)
2.1 configuration_qtensorformer.QTensorFormerConfig
- Inherits from:
transformers.PretrainedConfig(model_type = "qtensorformer") - Strict Loading Policy:
keys_to_ignore_at_loading = [](repaired in Phase Two so no missing weights are ignored). - Bridge Properties: Exposes
.d_model,.n_layers,.n_heads,.n_kv_heads,.max_seq_lenand accepts legacy keyword arguments (d_model,n_layers,n_heads,ff_multiplier,tt_rank) in__init__.
2.2 modeling_qtensorformer.QTensorFormerForCausalLM
- Inherits from:
transformers.PreTrainedModel - Submodules:
model.embed_tokens(nn.Embedding)model.layers(nn.ModuleListofQTensorFormerDecoderLayer, each containingQTensorFormerAttentionwithTensorTrainLinearprojections,QTensorFormerMLPwithTensorTrainLineargate_proj/up_proj/down_proj,QTensorFormerRMSNorm, andPIDResourceController)model.norm(QTensorFormerRMSNorm)lm_head(nn.Linear)
- Execution Path (
forward&generate):- Fully compatible with Hugging Face
CausalLMOutputWithPastandmodel.generate(). - Uses
AdaptiveKVCache(Cache)whenuse_cache=True.
- Fully compatible with Hugging Face