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
Add source: tmt/model/ffn.py
Browse files- tmt/model/ffn.py +58 -0
tmt/model/ffn.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ffn.py — DualStreamFFN: parallel syntax + semantic feed-forward network.
|
| 3 |
+
|
| 4 |
+
Novel vs standard: instead of a single FFN (d_model → 4*d_model → d_model),
|
| 5 |
+
DualStreamFFN runs two parallel streams of half-width (d_model → d_stream),
|
| 6 |
+
each specialising on syntax or semantic content, then fuses them with a learned
|
| 7 |
+
gate. This gives the same parameter budget as a standard FFN while separating
|
| 8 |
+
representational concerns.
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import torch
|
| 13 |
+
import torch.nn as nn
|
| 14 |
+
from einops import rearrange
|
| 15 |
+
from torch import Tensor
|
| 16 |
+
|
| 17 |
+
from .config import TMTConfig
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class DualStreamFFN(nn.Module):
|
| 21 |
+
"""Two parallel feed-forward streams fused by a learned scalar gate."""
|
| 22 |
+
|
| 23 |
+
def __init__(self, cfg: TMTConfig) -> None:
|
| 24 |
+
super().__init__()
|
| 25 |
+
d = cfg.d_model
|
| 26 |
+
s = cfg.ffn_stream_dim # each stream width (default 256)
|
| 27 |
+
|
| 28 |
+
# Syntax stream
|
| 29 |
+
self.syntax_up = nn.Linear(d, s)
|
| 30 |
+
self.syntax_down = nn.Linear(s, d)
|
| 31 |
+
|
| 32 |
+
# Semantic stream
|
| 33 |
+
self.semantic_up = nn.Linear(d, s)
|
| 34 |
+
self.semantic_down = nn.Linear(s, d)
|
| 35 |
+
|
| 36 |
+
# Learned fusion gate: sigmoid(linear) → scalar ∈ (0,1) per token-dim
|
| 37 |
+
self.gate = nn.Linear(d, d)
|
| 38 |
+
|
| 39 |
+
self.act = nn.GELU()
|
| 40 |
+
self.dropout = nn.Dropout(cfg.dropout)
|
| 41 |
+
|
| 42 |
+
def forward(self, x: Tensor) -> Tensor:
|
| 43 |
+
"""
|
| 44 |
+
Args:
|
| 45 |
+
x: (B, S, D)
|
| 46 |
+
Returns:
|
| 47 |
+
out: (B, S, D)
|
| 48 |
+
"""
|
| 49 |
+
syntax = self.dropout(self.syntax_down(self.act(self.syntax_up(x))))
|
| 50 |
+
semantic = self.dropout(self.semantic_down(self.act(self.semantic_up(x))))
|
| 51 |
+
|
| 52 |
+
# Learned fusion gate
|
| 53 |
+
g = torch.sigmoid(self.gate(x)) # (B, S, D)
|
| 54 |
+
return g * syntax + (1.0 - g) * semantic
|
| 55 |
+
|
| 56 |
+
def __repr__(self) -> str:
|
| 57 |
+
p = sum(p.numel() for p in self.parameters())
|
| 58 |
+
return f"DualStreamFFN(streams=2x{self.syntax_up.out_features}, params={p:,})"
|