Skip to content

Conversation

@aymuos15
Copy link

Summary

  • Fixed GEGLU docstring which incorrectly stated the activation function was Sigmoid
  • The code correctly uses GELU, as specified in the original GEGLU paper

Details

  • GLU uses Sigmoid: GLU(x) = σ(xW) ⊗ xV
  • GEGLU uses GELU: GEGLU(x) = GELU(xW) ⊗ xV

Reference: https://arxiv.org/abs/2002.05202

The docstring incorrectly stated GEGLU uses Sigmoid, but the code
correctly uses GELU. Per the original paper (Shazeer, 2020):
- GLU uses Sigmoid: GLU(x) = σ(xW) ⊗ xV
- GEGLU uses GELU: GEGLU(x) = GELU(xW) ⊗ xV

Reference: https://arxiv.org/abs/2002.05202
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

The GEGLU class docstring in monai/networks/blocks/activation.py was corrected to describe the operation as x1 * GELU(x2) (previously documented as x1 * Sigmoid(x2)). An Examples section demonstrating usage via Act'geglu' was added. No changes were made to the code or function signatures; the implementation already applied GELU to the gate.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description covers the core fix with technical details and references, but lacks the required checklist format specified in the repository template. Add the Types of changes checklist from the template to indicate which categories apply (non-breaking change, tests added, documentation updated, etc.).
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: correcting GEGLU's docstring from incorrectly stating Sigmoid to the correct GELU activation function.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
monai/networks/blocks/activation.py (1)

190-192: Consider adding a docstring to forward method.

Per coding guidelines, docstrings should describe return values. The class-level docstring documents behavior, but the forward method lacks its own docstring specifying Args/Returns. However, this is consistent with other activation classes in this file.

Optional: Add forward method docstring
     def forward(self, input: torch.Tensor):
+        """Apply GEGLU activation.
+
+        Args:
+            input: Tensor with shape (N, *, 2*D) where last dim is split for gating.
+
+        Returns:
+            Tensor with shape (N, *, D) after applying x * GELU(gate).
+        """
         x, gate = input.chunk(2, dim=-1)
         return x * nn.functional.gelu(gate)

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 51126f9 and f5a63ce.

📒 Files selected for processing (1)
  • monai/networks/blocks/activation.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.

Files:

  • monai/networks/blocks/activation.py
🔇 Additional comments (2)
monai/networks/blocks/activation.py (2)

171-171: Docstring fix is correct.

Implementation at line 192 uses nn.functional.gelu(gate), confirming GELU is the correct activation. Good catch fixing this discrepancy.


180-187: Examples section looks good.

Follows the same pattern as Swish, MemoryEfficientSwish, and Mish classes. Comment on line 186 clarifies the even-dimension requirement - helpful for users.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
monai/networks/blocks/activation.py (1)

167-184: LGTM! Docstring now matches implementation.

The fix correctly aligns the documentation with the actual code (nn.functional.gelu(gate) on line 184).

Optional: For consistency with other activation classes in this file, consider adding an Examples section.

📝 Optional: Add Examples section
     Shape:
         - Input: :math:`(N, *, 2 * D)`
         - Output: :math:`(N, *, D)`, where `*` means, any number of additional dimensions
+
+
+    Examples::
+
+        >>> import torch
+        >>> m = GEGLU()
+        >>> input = torch.randn(2, 8)  # last dim must be even
+        >>> output = m(input)
     """
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 57fdd59 and 51126f9.

📒 Files selected for processing (1)
  • monai/networks/blocks/activation.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

Review the Python code for quality and correctness. Ensure variable names adhere to PEP8 style guides, are sensible and informative in regards to their function, though permitting simple names for loop and comprehension variables. Ensure routine names are meaningful in regards to their function and use verbs, adjectives, and nouns in a semantically appropriate way. Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings. Examine code for logical error or inconsistencies, and suggest what may be changed to addressed these. Suggest any enhancements for code improving efficiency, maintainability, comprehensibility, and correctness. Ensure new or modified definitions will be covered by existing or new unit tests.

Files:

  • monai/networks/blocks/activation.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: min-dep-py3 (3.12)
  • GitHub Check: min-dep-pytorch (2.6.0)
  • GitHub Check: quick-py3 (ubuntu-latest)
  • GitHub Check: min-dep-pytorch (2.8.0)
  • GitHub Check: quick-py3 (windows-latest)
  • GitHub Check: min-dep-pytorch (2.7.1)
  • GitHub Check: min-dep-os (macOS-latest)
  • GitHub Check: quick-py3 (macOS-latest)
  • GitHub Check: min-dep-py3 (3.11)
  • GitHub Check: min-dep-py3 (3.10)
  • GitHub Check: build-docs
  • GitHub Check: min-dep-os (ubuntu-latest)
  • GitHub Check: min-dep-py3 (3.9)
  • GitHub Check: packaging
  • GitHub Check: min-dep-os (windows-latest)
  • GitHub Check: min-dep-pytorch (2.5.1)
  • GitHub Check: flake8-py3 (mypy)
  • GitHub Check: flake8-py3 (codeformat)
  • GitHub Check: flake8-py3 (pytype)

@aymuos15
Copy link
Author

"Optional: For consistency with other activation classes in this file, consider adding an Examples section." -- Happy to add this as well if required.

@ericspod
Copy link
Member

Thanks @aymuos15 for this fix, please do add an example to be consistent with the other classes.

Add example showing usage of GEGLU to align docstring style with other activation classes. No functional changes.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@aymuos15 aymuos15 force-pushed the fix/geglu-docstring branch from 805f33f to f5a63ce Compare January 14, 2026 10:23
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