Text Generation
PyTorch
Transformers
English
language-model
graph-neural-network
sparse-attention
adaptive-depth
temporal-decay
mesh-attention
efficient-transformer
novel-architecture
causal-lm
research
preprint
mesh-transformer
dynamic-graph
early-exit
per-token-routing
Eval Results (legacy)
Instructions to use vigneshwar234/TemporalMesh-Transformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vigneshwar234/TemporalMesh-Transformer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vigneshwar234/TemporalMesh-Transformer")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vigneshwar234/TemporalMesh-Transformer", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use vigneshwar234/TemporalMesh-Transformer with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vigneshwar234/TemporalMesh-Transformer" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vigneshwar234/TemporalMesh-Transformer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vigneshwar234/TemporalMesh-Transformer
- SGLang
How to use vigneshwar234/TemporalMesh-Transformer 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 "vigneshwar234/TemporalMesh-Transformer" \ --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": "vigneshwar234/TemporalMesh-Transformer", "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 "vigneshwar234/TemporalMesh-Transformer" \ --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": "vigneshwar234/TemporalMesh-Transformer", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vigneshwar234/TemporalMesh-Transformer with Docker Model Runner:
docker model run hf.co/vigneshwar234/TemporalMesh-Transformer
File size: 2,346 Bytes
d266df1 | 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 | """
exit_gate.py — ExitGate: per-token adaptive depth routing.
Novel vs standard: every token in a standard transformer passes through all N
layers unconditionally. ExitGate computes a confidence scalar after each layer
norm. If confidence > exit_threshold the token's representation is frozen and
it skips all remaining layers, halving average compute on easy tokens.
The auxiliary training loss encourages the gate to be decisive (push toward 0
or 1) without forcing early exits — the model learns when it is confident.
"""
from __future__ import annotations
from typing import Tuple
import torch
import torch.nn as nn
from torch import Tensor
from .config import TMTConfig
class ExitGate(nn.Module):
"""Single linear → sigmoid confidence gate per token."""
def __init__(self, cfg: TMTConfig) -> None:
super().__init__()
self.threshold = cfg.exit_threshold
# Single scalar projection: d_model → 1
self.gate_proj = nn.Linear(cfg.d_model, 1)
nn.init.zeros_(self.gate_proj.weight)
nn.init.constant_(self.gate_proj.bias, -2.0) # start pessimistic
def forward(self, x: Tensor, exit_mask: Tensor) -> Tuple[Tensor, Tensor, Tensor]:
"""
Args:
x: (B, S, D) current token representations
exit_mask: (B, S) bool — True where token has already exited
Returns:
x: (B, S, D) unchanged (gating is applied in TMTLayer)
new_mask: (B, S) bool — updated exit mask
confidence: (B, S) float confidence scores for auxiliary loss
"""
confidence = torch.sigmoid(self.gate_proj(x)).squeeze(-1) # (B, S)
# New exits: not already exited AND confidence above threshold
newly_exited = (~exit_mask) & (confidence > self.threshold)
new_mask = exit_mask | newly_exited
return x, new_mask, confidence
def auxiliary_loss(self, confidence: Tensor) -> Tensor:
"""
Encourage decisive gates — push confidence toward 0 or 1.
Loss = -E[|conf - 0.5|] so the model is penalised for being uncertain.
"""
return -(confidence - 0.5).abs().mean()
def __repr__(self) -> str:
p = sum(p.numel() for p in self.parameters())
return f"ExitGate(threshold={self.threshold}, params={p:,})"
|