Qiu and colleagues explain the benefit of gated attention partly by the scores themselves: in the best variant most of them sit near zero. They report the mean score, compare variants that cannot be sparse, and check how many entries of the attention output the gate pushes below a small threshold. Compute those statistics for one layer.
gate_score_report(logits, Y, variant="sigmoid", threshold=1e-2)
logits has shape : the gate pre-activations for tokens, heads and head dimension .Y has the same shape: the attention outputs of the heads before gating.variant, with :
"sigmoid": ."ns_sigmoid": the non-sparse sigmoid, ."head_shared": averaged over the head axis, the same average used by every head.Return a dict of Python floats, each rounded to 4 decimals:
"mean_score": ."below_half": the fraction of scores strictly below 0.5."mean_abs_before", "mean_abs_after": the mean absolute value of and of the gated output."sparsity_before", "sparsity_gated", "sparsity_mean_scaled": the fraction of entries whose absolute value is strictly below threshold, in , in the gated output and in the mean-scaled output.ValueError for an unknown variant.