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 @config_tester( model_name="VanillaDecoderTransformer", n_layers=8, d_model=512, head_amount=8, d_ffn=2048, ) 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()) @model_init( model_name="VanillaDecoderTransformer" ) 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 )