Download benchmarks/models/vanilla_decoder_transformer.py from Pulsar-Dynamic-Technologies/Adria: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/benchmarks/models/vanilla_decoder_transformer.py
- Command line
-
hf download hf://Pulsar-Dynamic-Technologies/Adria/benchmarks/models/vanilla_decoder_transformer.py
-
curl -L -o vanilla_decoder_transformer.py https://huggingface.co/Pulsar-Dynamic-Technologies/Adria/resolve/main/benchmarks/models/vanilla_decoder_transformer.py
1.05 kB
| import torch | |
| import torch.nn as nn | |
| from benchmarks.config import load_config | |
| from benchmarks.registry import config_tester, model_init | |
| from net import VanillaDecoderTransformer | |
| def count_params(vocab_size: int, seq_len: int, n_layers: int, d_model: int, head_amount: int, d_ffn: int): | |
| with torch.device("meta"): | |
| model = VanillaDecoderTransformer( | |
| vocab_size=vocab_size, | |
| n_layers=n_layers, | |
| n_ctx=seq_len, | |
| d_model=d_model, | |
| head_amount=head_amount, | |
| d_ffn=d_ffn | |
| ) | |
| return sum(p.numel() for p in model.parameters()) | |
| def make_model(n_params: int, vocab_size: int, seq_len: int) -> nn.Module: | |
| cfg = load_config("VanillaDecoderTransformer", n_params) | |
| return VanillaDecoderTransformer( | |
| vocab_size=vocab_size, | |
| n_ctx=seq_len, | |
| **cfg | |
| ) | |