Skip to content

Validate point-wise torch activation in eMLP and iMLP#15

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-activation-function-check
Draft

Validate point-wise torch activation in eMLP and iMLP#15
Copilot wants to merge 2 commits intomainfrom
copilot/add-activation-function-check

Conversation

Copy link

Copilot AI commented Feb 26, 2026

eMLP and iMLP silently accepted any torch.nn.Module as activation, including non-point-wise modules that break equivariance. Add an elegant, forward-compatible guard that rejects anything that isn't a torch point-wise activation.

Changes

  • _is_torch_pointwise_activation(module) — new module-level helper in emlp.py. Checks type(module).__module__ == "torch.nn.modules.activation", which covers every current and future activation in PyTorch's dedicated activation namespace without any manual enumeration.
  • eMLP.__init__ — replaces bare assert isinstance(activation, torch.nn.Module) with a ValueError using the helper.
  • iMLP.__init__ — adds the same guard (previously no activation type check existed).
# Accepted — any torch.nn activation, including future ones
eMLP(..., activation=torch.nn.SiLU())

# Raises ValueError: "Expected a point-wise non-linearity from `torch.nn` ..."
eMLP(..., activation=torch.nn.Sequential(torch.nn.ReLU()))
eMLP(..., activation=torch.nn.Linear(4, 4))
  • Tests — two new parametrized cases: one asserting several torch activations (ReLU, GELU, SiLU, Tanh, ELU) are accepted; one asserting non-activation modules raise ValueError with a message containing the offending type name.
Original prompt

in the eMLP and iMLP models, I would like an easy way to understand if the user passed any of the point-wise non-linearities used by torch. Ideally an elegant check, such that I dont need to handle any new activation funciton added.

Can you create a PR adding this feature ?

Without bothering me

The user has attached the following file paths as relevant context:

  • pyproject.toml

Created from VS Code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Danfoa <8356912+Danfoa@users.noreply.github.com>
Copilot AI changed the title [WIP] Add dynamic check for point-wise non-linearities in eMLP and iMLP Validate point-wise torch activation in eMLP and iMLP Feb 26, 2026
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