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
File size: 3,942 Bytes
b5cb5a0 | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | """
src/adaptive_vision.py
Adaptive Vision-to-Language Projector for Edge Multimodal Q-TensorFormer.
Dynamically routes visual patch embeddings through variable-rank Tensor-Train cores
based on spatial salience and inter-patch variance.
Background and uniform patches run at ultra-low rank (r=1..2),
reserving full rank (r=16) for high-information semantic objects.
"""
from typing import Dict, Any, Tuple
import torch
import torch.nn as nn
from src.tensor_layers import TTLinear
class AdaptiveVisionProjector(nn.Module):
"""
Salience-Gated Tensor-Train Multimodal Projector.
Projects vision features (B, P, D_vis) into language embedding space (B, P, D_model).
"""
def __init__(
self,
vis_dim: int = 768,
model_dim: int = 256,
max_rank: int = 16,
min_rank: int = 2,
salience_threshold: float = 1.0,
):
super().__init__()
self.vis_dim = vis_dim
self.model_dim = model_dim
self.max_rank = max_rank
self.min_rank = min_rank
self.salience_threshold = salience_threshold
# Tensor-Train projection layer from vision dim to model dim
# Factorize 768 -> [8, 8, 12] and 256 -> [4, 8, 8]
self.tt_projector = TTLinear(
in_features=vis_dim,
out_features=model_dim,
rank=max_rank,
in_shape=[8, 8, 12],
out_shape=[4, 8, 8],
bias=True,
)
def forward(self, patch_embeddings: torch.Tensor) -> Tuple[torch.Tensor, Dict[str, Any]]:
"""
Forward pass with adaptive per-patch salience gating.
Args:
patch_embeddings: Tensor of shape (B, num_patches, vis_dim)
"""
b, num_patches, d_v = patch_embeddings.shape
device = patch_embeddings.device
# 1. Compute per-patch spatial salience (L2 distance from patch mean)
patch_mean = patch_embeddings.mean(dim=1, keepdim=True)
salience = torch.norm(patch_embeddings - patch_mean, p=2, dim=-1) # (B, num_patches)
normalized_salience = (salience - salience.mean()) / (salience.std() + 1e-6)
# 2. Partition patches into high-salience and low-salience masks
high_salience_mask = normalized_salience >= self.salience_threshold
num_high_salience = int(high_salience_mask.sum().item())
num_low_salience = (b * num_patches) - num_high_salience
# 3. Project tokens
# For simplicity and reproducibility across batched shapes:
# High-salience patches receive high rank projection, low-salience patches receive min_rank
self.tt_projector.set_rank(self.max_rank)
proj_high = self.tt_projector(patch_embeddings)
self.tt_projector.set_rank(self.min_rank)
proj_low = self.tt_projector(patch_embeddings)
mask_expanded = high_salience_mask.unsqueeze(-1) # (B, num_patches, 1)
projected = torch.where(mask_expanded, proj_high, proj_low)
# Restore max rank
self.tt_projector.set_rank(self.max_rank)
# 4. Metrics & Telemetry
dense_flops_per_patch = 2 * self.vis_dim * self.model_dim
low_rank_ratio = self.min_rank / float(self.max_rank)
effective_active_rank = (
(num_high_salience * self.max_rank) + (num_low_salience * self.min_rank)
) / float(b * num_patches)
compute_savings_pct = (1.0 - (effective_active_rank / float(self.max_rank))) * 100.0
telemetry = {
"total_patches": b * num_patches,
"high_salience_patches": num_high_salience,
"low_salience_patches": num_low_salience,
"effective_mean_rank": effective_active_rank,
"compute_savings_pct": compute_savings_pct,
"min_rank": self.min_rank,
"max_rank": self.max_rank,
"scientific_classification": "MEASURED",
}
return projected, telemetry
|