Transformers
PyTorch
English
language-model
graph-attention
adaptive-depth
temporal-decay
efficient-llm
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:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vigneshwar234/TemporalMesh-Transformer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add source: tmt/training/scheduler.py
Browse files- tmt/training/scheduler.py +28 -0
tmt/training/scheduler.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
scheduler.py — Cosine annealing with linear warmup.
|
| 3 |
+
"""
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import math
|
| 7 |
+
|
| 8 |
+
from torch.optim import Optimizer
|
| 9 |
+
from torch.optim.lr_scheduler import LambdaLR
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def cosine_warmup_scheduler(
|
| 13 |
+
optimizer: Optimizer,
|
| 14 |
+
warmup_steps: int,
|
| 15 |
+
total_steps: int,
|
| 16 |
+
min_lr_ratio: float = 0.1,
|
| 17 |
+
) -> LambdaLR:
|
| 18 |
+
"""
|
| 19 |
+
Linear warmup for `warmup_steps`, then cosine decay to `min_lr_ratio * lr`.
|
| 20 |
+
"""
|
| 21 |
+
def lr_lambda(step: int) -> float:
|
| 22 |
+
if step < warmup_steps:
|
| 23 |
+
return step / max(warmup_steps, 1)
|
| 24 |
+
progress = (step - warmup_steps) / max(total_steps - warmup_steps, 1)
|
| 25 |
+
cosine = 0.5 * (1.0 + math.cos(math.pi * progress))
|
| 26 |
+
return min_lr_ratio + (1.0 - min_lr_ratio) * cosine
|
| 27 |
+
|
| 28 |
+
return LambdaLR(optimizer, lr_lambda)
|