Use Linformer settings for linear complexity
masterLinformer is a variant of attention with linear complexity that works with non-autoregressive models of a fixed sequence length. You can enable it by passing LinformerSettings to the linformer_settings argument of LinearAttentionTransformerLM.
To use Linformer for the contextual attention layer (when the context has a fixed sequence length), use LinformerContextSettings and pass it to context_linformer_settings in a decoder with receives_context = True.
from linear_attention_transformer import LinearAttentionTransformerLM, LinformerSettings
# For standard Linformer attention
settings = LinformerSettings(k = 256)
enc = LinearAttentionTransformerLM(
num_tokens = 20000,
dim = 512,
heads = 8,
depth = 6,
max_seq_len = 4096,
linformer_settings = settings
).cuda()
# For Linformer contextual attention
from linear_attention_transformer import LinformerContextSettings
context_settings = LinformerContextSettings(
seq_len = 2048,
k = 256
)
dec = LinearAttentionTransformerLM(
num_tokens = 20000,
dim = 512,
heads = 8,
depth = 6,
max_seq_len = 4096,
causal = True,
context_linformer_settings = context_settings,
receives_context = True
).cuda()