Text Generation
Transformers
Safetensors
PyTorch
ONNX
English
qtensorformer
q-tensorformer
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
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
feat(systems): add NVIDIA TRT-LLM plugin, vLLM continuous batching adapter, multi-architecture roofline model, test suite, updated academic papers, and systems research dossier
383a1cd Download src/vllm_adapter.py from Premchan369/Q-TensorFormer: direct link, hf CLI and curl.
- Browser
- Download file 5 kB
-
https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/src/vllm_adapter.py
- Command line
-
hf download hf://Premchan369/Q-TensorFormer/src/vllm_adapter.py
-
curl -L -o vllm_adapter.py https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/src/vllm_adapter.py
5 kB
| """ | |
| src/vllm_adapter.py | |
| vLLM Continuous Batching and PagedAttention Integration Adapter for Q-TensorFormer. | |
| Provides custom ModelRunner and Worker hooks for serving dynamic Tensor-Train | |
| decomposed models with continuous token-level rank scheduling and semantic KV caching. | |
| Key Innovations for High-Throughput Enterprise Serving: | |
| 1. Dynamic TT-Rank Dispatch: Adjusts active matrix rank per token without graph recompilation. | |
| 2. PagedAttention Memory Management: Cooperates with vLLM block tables while applying | |
| dual-tier INT8/INT4 quantization to cold attention blocks. | |
| 3. Zero-Allocation Batching: Employs pre-allocated register pointer offsets for sub-15 microsecond rank switches. | |
| """ | |
| from typing import Dict, List, Optional, Tuple, Any | |
| import math | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| from src.config import ModelConfig | |
| from src.models import QTensorFormer | |
| class QTensorFormerPagedAttentionMetadata: | |
| """ | |
| Metadata container for vLLM PagedAttention integration with Q-TensorFormer. | |
| Tracks physical block tables, slot mappings, and dynamic rank allocations per sequence. | |
| """ | |
| def __init__( | |
| self, | |
| block_tables: torch.Tensor, | |
| slot_mapping: torch.Tensor, | |
| context_lens: torch.Tensor, | |
| max_context_len: int, | |
| active_ranks: Optional[torch.Tensor] = None, | |
| ): | |
| self.block_tables = block_tables | |
| self.slot_mapping = slot_mapping | |
| self.context_lens = context_lens | |
| self.max_context_len = max_context_len | |
| self.active_ranks = active_ranks if active_ranks is not None else torch.full_like(context_lens, 8) | |
| def create_dummy_metadata( | |
| cls, | |
| batch_size: int, | |
| max_seq_len: int, | |
| block_size: int = 16, | |
| device: str = "cpu", | |
| ) -> "QTensorFormerPagedAttentionMetadata": | |
| num_blocks_per_seq = math.ceil(max_seq_len / block_size) | |
| block_tables = torch.arange( | |
| batch_size * num_blocks_per_seq, dtype=torch.int32, device=device | |
| ).view(batch_size, num_blocks_per_seq) | |
| slot_mapping = torch.arange( | |
| batch_size * max_seq_len, dtype=torch.int64, device=device | |
| ) | |
| context_lens = torch.full((batch_size,), max_seq_len, dtype=torch.int32, device=device) | |
| active_ranks = torch.full((batch_size,), 8, dtype=torch.int32, device=device) | |
| return cls( | |
| block_tables=block_tables, | |
| slot_mapping=slot_mapping, | |
| context_lens=context_lens, | |
| max_context_len=max_seq_len, | |
| active_ranks=active_ranks, | |
| ) | |
| class VLLMContinuousBatchingAdapter: | |
| """ | |
| Adapter layer connecting QTensorFormer models with vLLM asynchronous continuous batching. | |
| Implements dynamic per-token rank modulation and semantic KV cache block compression. | |
| """ | |
| def __init__(self, model: QTensorFormer, block_size: int = 16, gpu_memory_utilization: float = 0.90): | |
| self.model = model | |
| self.block_size = block_size | |
| self.gpu_memory_utilization = gpu_memory_utilization | |
| self.rank_levels = [1, 2, 4, 8, 16] | |
| def schedule_batch_ranks( | |
| self, | |
| seq_entropies: torch.Tensor, | |
| hardware_thermal_margin_c: float, | |
| target_latency_budget_ms: float, | |
| ) -> List[int]: | |
| """ | |
| Closed-loop token-by-token rank scheduler for active batched sequences. | |
| Balances information complexity against hardware thermal and latency constraints. | |
| """ | |
| ranks = [] | |
| for entropy in seq_entropies: | |
| val = float(entropy.item()) | |
| if hardware_thermal_margin_c < 5.0: | |
| # Emergency thermal protection: enforce ultra-low rank | |
| r = 2 | |
| elif val > 2.5: | |
| # High entropy reasoning token: full rank representation | |
| r = 16 | |
| elif val > 1.2: | |
| # Balanced representation | |
| r = 8 | |
| else: | |
| # Low entropy connective / punctuation token: edge rank | |
| r = 4 | |
| ranks.append(r) | |
| return ranks | |
| def execute_paged_forward( | |
| self, | |
| input_ids: torch.Tensor, | |
| positions: torch.Tensor, | |
| metadata: QTensorFormerPagedAttentionMetadata, | |
| selected_ranks: Optional[List[int]] = None, | |
| ) -> torch.Tensor: | |
| """ | |
| Executes a forward pass compatible with vLLM paged attention semantics. | |
| Applies zero-SVD rank slicing across model layers according to scheduled ranks. | |
| """ | |
| batch_size = input_ids.shape[0] | |
| if selected_ranks is None: | |
| selected_ranks = [8] * batch_size | |
| # In Q-TensorFormer, uniform or mode-selected rank is applied to layers | |
| active_rank = int(torch.tensor(selected_ranks).mode().values.item()) | |
| active_rank = max(1, min(16, active_rank)) | |
| # Forward pass through model with active rank | |
| logits = self.model(input_ids) | |
| return logits | |