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/data/dataset.py
Browse files- tmt/data/dataset.py +75 -0
tmt/data/dataset.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
dataset.py — loads wikitext-2 or tinystories and chunks into fixed-length blocks.
|
| 3 |
+
"""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
from typing import Dict
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from datasets import load_dataset
|
| 10 |
+
from torch.utils.data import DataLoader, Dataset
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class BlockDataset(Dataset):
|
| 14 |
+
"""Chunks a flat token sequence into non-overlapping blocks of seq_len."""
|
| 15 |
+
|
| 16 |
+
def __init__(self, tokens: torch.Tensor, seq_len: int) -> None:
|
| 17 |
+
self.seq_len = seq_len
|
| 18 |
+
n_blocks = len(tokens) // (seq_len + 1)
|
| 19 |
+
# +1 so we can shift for next-token targets
|
| 20 |
+
self.data = tokens[: n_blocks * (seq_len + 1)].reshape(n_blocks, seq_len + 1)
|
| 21 |
+
|
| 22 |
+
def __len__(self) -> int:
|
| 23 |
+
return len(self.data)
|
| 24 |
+
|
| 25 |
+
def __getitem__(self, idx: int) -> Dict[str, torch.Tensor]:
|
| 26 |
+
chunk = self.data[idx]
|
| 27 |
+
return {"input_ids": chunk}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def load_text_dataset(
|
| 31 |
+
name: str = "wikitext-2",
|
| 32 |
+
seq_len: int = 256,
|
| 33 |
+
batch_size: int = 16,
|
| 34 |
+
tokenizer_name: str = "gpt2",
|
| 35 |
+
) -> Dict[str, DataLoader]:
|
| 36 |
+
"""
|
| 37 |
+
Returns {"train": DataLoader, "validation": DataLoader}.
|
| 38 |
+
Supported names: "wikitext-2", "tinystories".
|
| 39 |
+
"""
|
| 40 |
+
from transformers import AutoTokenizer
|
| 41 |
+
|
| 42 |
+
tok = AutoTokenizer.from_pretrained(tokenizer_name)
|
| 43 |
+
if tok.pad_token is None:
|
| 44 |
+
tok.add_special_tokens({"pad_token": "[PAD]"})
|
| 45 |
+
|
| 46 |
+
if name == "wikitext-2":
|
| 47 |
+
raw = load_dataset("wikitext", "wikitext-2-raw-v1")
|
| 48 |
+
elif name == "tinystories":
|
| 49 |
+
raw = load_dataset("roneneldan/TinyStories")
|
| 50 |
+
else:
|
| 51 |
+
raise ValueError(f"Unknown dataset: {name}")
|
| 52 |
+
|
| 53 |
+
def tokenize(examples):
|
| 54 |
+
return tok(examples["text"], truncation=False, return_attention_mask=False)
|
| 55 |
+
|
| 56 |
+
tokenized = raw.map(tokenize, batched=True, remove_columns=raw["train"].column_names)
|
| 57 |
+
|
| 58 |
+
loaders = {}
|
| 59 |
+
for split in ("train", "validation"):
|
| 60 |
+
if split not in tokenized:
|
| 61 |
+
continue
|
| 62 |
+
all_ids = []
|
| 63 |
+
for sample in tokenized[split]["input_ids"]:
|
| 64 |
+
all_ids.extend(sample)
|
| 65 |
+
flat = torch.tensor(all_ids, dtype=torch.long)
|
| 66 |
+
ds = BlockDataset(flat, seq_len)
|
| 67 |
+
loaders[split] = DataLoader(
|
| 68 |
+
ds,
|
| 69 |
+
batch_size=batch_size,
|
| 70 |
+
shuffle=(split == "train"),
|
| 71 |
+
num_workers=2,
|
| 72 |
+
pin_memory=True,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
return loaders
|