Skip to content

feat(attention): add relu2max residual routing - #888

Open
klei22 wants to merge 1 commit into
ReaLLMASIC:masterfrom
klei22:add_relu2_attention_residuals
Open

feat(attention): add relu2max residual routing#888
klei22 wants to merge 1 commit into
ReaLLMASIC:masterfrom
klei22:add_relu2_attention_residuals

Conversation

@klei22

@klei22 klei22 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@klei22
klei22 requested review from gkielian and a lite review from Copilot August 14, 2026 06:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an alternative depth-routing normalization for the FullAttentionResidual mixer (“relu2max”), wiring it through configuration/CLI, documenting its behavior, and adding tests to validate its properties.

Changes:

  • Add weight_variant + relu2max_shift options to FullAttentionResidual, with a new relu2max weight computation path.
  • Plumb new config/CLI knobs (attention_residual_weight_variant, attention_residual_relu2max_shift) through GPTConfig, train_args.py, and model.py.
  • Add unit tests and documentation for ReLU2Max residual routing behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
variations/attention_residual_variations.py Adds relu2max routing weights and related configuration/validation.
train_args.py Exposes new CLI flags for selecting routing weight variant and shift.
tests/test_attention_residual.py Adds coverage for relu2max uniform init/trainability and normalization properties.
model.py Wires new config fields into FullAttentionResidual construction.
gpt_conf.py Adds new config defaults for residual weight variant and shift.
documentation/Attention_Residuals.md Documents ReLU2Max routing and how it differs from softmax depth routing.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +43 to +51
centered_scores = scores - scores.mean(dim=0, keepdim=True)
terms = torch.relu(centered_scores + self.relu2max_shift).square()
denominator = terms.sum(dim=0, keepdim=True)
normalized = terms / denominator.clamp_min(torch.finfo(terms.dtype).tiny)

# Retain a finite fallback for non-finite/extreme inputs and preserve
# the residual mixer's convex-combination invariant.
uniform = torch.full_like(terms, 1.0 / terms.size(0))
return torch.where(denominator > 0, normalized, uniform)
Comment thread model.py
Comment on lines 149 to 155
self.attention_residual = FullAttentionResidual(
2 * config.n_layer + 1, config.n_embd, config.attention_residual_eps
2 * config.n_layer + 1,
config.n_embd,
config.attention_residual_eps,
config.attention_residual_weight_variant,
config.attention_residual_relu2max_shift,
)
Comment on lines +94 to +95
number of retained residual sources. If every squared-ReLU term is zero, the
implementation safely falls back to uniform weights.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants