From 6d45461aca8ed15d8112e05964311276bf50870d Mon Sep 17 00:00:00 2001 From: Phil Wang Date: Tue, 7 Feb 2023 09:42:14 -0800 Subject: [PATCH] helpful assert --- musiclm_pytorch/musiclm_pytorch.py | 5 +++++ setup.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/musiclm_pytorch/musiclm_pytorch.py b/musiclm_pytorch/musiclm_pytorch.py index 6b7b606..fb7d877 100644 --- a/musiclm_pytorch/musiclm_pytorch.py +++ b/musiclm_pytorch/musiclm_pytorch.py @@ -367,6 +367,8 @@ def __init__( self.token_emb = nn.Embedding(num_tokens, dim) self.pos_emb = nn.Embedding(max_seq_len, dim) + self.max_seq_len = max_seq_len + self.cls_token = nn.Parameter(torch.randn(dim)) self.transformer = Transformer( @@ -405,6 +407,9 @@ def forward( # token embedding + positional embedding x = self.token_emb(x) + + assert n <= self.max_seq_len, f'text sequence length {n} must be less than {self.max_seq_len}' + x = x + self.pos_emb(torch.arange(n, device = device)) # cls tokens, as in bert diff --git a/setup.py b/setup.py index 5a23625..92e18ef 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name = 'musiclm-pytorch', packages = find_packages(exclude=[]), - version = '0.0.14', + version = '0.0.15', license='MIT', description = 'MusicLM - AudioLM + Audio CLIP to text to music synthesis', author = 'Phil Wang',