Text Generation
Transformers
ONNX
GGUF
PyTorch
English
qtensorformer
tensor-networks
model-compression
adaptive-computation
kv-cache-compression
hardware-aware
energy-aware
green-ai
custom-code
multimodal
ollama
webgpu
triton
low-rank-adaptation
mixture-of-depths
edge-ai
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
Transform Q-TensorFormer into an Information-Value Adaptive Resource Allocation Architecture
eaeea8f Download experiments/run_adaptive.py from Premchan369/Q-TensorFormer: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/experiments/run_adaptive.py
- Command line
-
hf download hf://Premchan369/Q-TensorFormer/experiments/run_adaptive.py
-
curl -L -o run_adaptive.py https://huggingface.co/Premchan369/Q-TensorFormer/resolve/main/experiments/run_adaptive.py
3.17 kB
| """ | |
| Experiment Runner: Adaptive Resource Allocation & Routing Stability. | |
| Evaluates: | |
| - Marginal Utility vs Static Rank | |
| - Rank distributions across different token difficulties | |
| - Routing stability and hysteresis churn reduction | |
| - Multi-seed variance across 3 seeds | |
| """ | |
| import sys | |
| import os | |
| import json | |
| import argparse | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| import torch | |
| from src.config import ModelConfig | |
| from src.models import QTensorFormer | |
| from src.data import load_synthetic_data | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--output", type=str, default="outputs/adaptive_results.json") | |
| parser.add_argument("--seeds", type=int, nargs="+", default=[42, 123, 999]) | |
| args = parser.parse_args() | |
| os.makedirs(os.path.dirname(args.output) or ".", exist_ok=True) | |
| print("=" * 65) | |
| print("EXPERIMENT: Adaptive Allocation & Stability Analysis") | |
| print("=" * 65) | |
| cfg = ModelConfig( | |
| vocab_size=1000, | |
| d_model=128, | |
| n_layers=2, | |
| tt_rank=8, | |
| use_quantum=True, | |
| ) | |
| results_by_seed = [] | |
| for seed in args.seeds: | |
| torch.manual_seed(seed) | |
| model = QTensorFormer(cfg, preset="QTF_BALANCED") | |
| model.eval() | |
| loader = load_synthetic_data(vocab_size=1000, seq_len=32, n_samples=200, batch_size=16) | |
| ranks_recorded = [] | |
| quantum_ratios = [] | |
| churn_rates = [] | |
| with torch.no_grad(): | |
| for inp, _ in loader: | |
| _, stats = model(inp, return_stats=True) | |
| for block_stat in stats: | |
| ranks_recorded.append(block_stat["chosen_rank"]) | |
| quantum_ratios.append(block_stat["quantum_usage_pct"]) | |
| churn_rates.append(block_stat["routing_churn_rate"]) | |
| mean_rank = sum(ranks_recorded) / len(ranks_recorded) | |
| mean_quantum = sum(quantum_ratios) / len(quantum_ratios) | |
| mean_churn = sum(churn_rates) / len(churn_rates) | |
| rank_counts = {r: ranks_recorded.count(r) / len(ranks_recorded) for r in [1, 2, 4, 8]} | |
| seed_res = { | |
| "seed": seed, | |
| "mean_rank": round(mean_rank, 2), | |
| "rank_distribution": {k: round(v, 4) for k, v in rank_counts.items()}, | |
| "quantum_usage_pct": round(mean_quantum, 2), | |
| "routing_churn_rate": round(mean_churn, 4), | |
| "classification": "MEASURED", | |
| } | |
| results_by_seed.append(seed_res) | |
| print(f"Seed {seed} | Mean Rank: {mean_rank:.2f} | Quantum: {mean_quantum:.1f}% | Churn: {mean_churn:.4f}") | |
| summary = { | |
| "seeds": results_by_seed, | |
| "overall_mean_rank": round(sum(s["mean_rank"] for s in results_by_seed) / len(results_by_seed), 2), | |
| "overall_quantum_pct": round(sum(s["quantum_usage_pct"] for s in results_by_seed) / len(results_by_seed), 2), | |
| "overall_churn_rate": round(sum(s["routing_churn_rate"] for s in results_by_seed) / len(results_by_seed), 4), | |
| } | |
| with open(args.output, "w") as f: | |
| json.dump(summary, f, indent=2) | |
| print(f"\nResults saved to {args.output}") | |
| if __name__ == "__main__": | |
| main() | |