Skip to content

Adding the CReLU Activation #1327

Closed
Closed

Description

@keskarnitish

I was trying to reproduce some of the experiments of the new paper on shattered gradients and needed to use the CReLU activation which was unavailable in PyTorch. Unfortunately, it doesn't seem to be a trivial extension of ReLU to code. (Should?) Could we add this functionality to PyTorch?

Implementations of CReLU can be found in:
Lua Torch
Chainer
Tensorflow

If I am not mistaken, this function would be added to nn/_functions/thnn/activation?

Update:

For CNNs and Linear layers, I think I have a temporary solution.

class CReLU(nn.Module):
    def __init__(self):
        super(CReLU, self).__init__()
    def forward(self, x):
        return torch.cat((F.relu(x), F.relu(-x)), 1)

Obviously, there are some issues with this (hard-coded axis argument, doesn't allow inplace operations etc.)

Activity

  1. apaszke commented on Apr 24, 2017

    @apaszke
    Contributor

    As you found, it's unnecessary to make this a function, because it can be easily implemented using existing autograd ops.

  2. keskarnitish commented on Apr 24, 2017

    @keskarnitish
    ContributorAuthor

    Sounds good to me! We can close this issue if you'd like.

  3. progirep commented on Oct 12, 2018

    @progirep

    Ok, so it can be easily be implemented using existing autograd operations. But how exactly (while avoiding the draw-backs that @keskarnitish mentioned)? LuaTorch has such a layer type, so perhaps it makes sense to add it to pytorch as well?

  4. progirep commented on Jan 4, 2019

    @progirep
  5. MohamedAliRashad commented on Feb 7, 2019

    @MohamedAliRashad
    Contributor

    I agree with @progirep and think this issue needs to be reopened and implemented ..... PyTorch is nothing less than Tensorflow or others in implementing such functions.

  6. mueller91 commented on Jan 11, 2023

    @mueller91

    also would appreciate a crelu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions