Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix input names in sparsemax #193

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mambular/arch_utils/layer_utils/sparsemax.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class SparsemaxFunction(Function):
"""

@staticmethod
def forward(ctx, x, dim=-1):
def forward(ctx, input, dim=-1):
"""
Forward pass of sparsemax: a normalizing, sparse transformation.

Parameters
----------
x : torch.Tensor
input : torch.Tensor
The input tensor on which sparsemax will be applied.
dim : int, optional
Dimension along which to apply sparsemax. Default is -1.
Expand All @@ -53,8 +53,8 @@ def forward(ctx, x, dim=-1):
A tensor with the same shape as the input, with sparsemax applied.
"""
ctx.dim = dim
max_val, _ = x.max(dim=dim, keepdim=True)
x -= max_val # Numerical stability trick, as with softmax.
max_val, _ = input.max(dim=dim, keepdim=True)
input -= max_val # Numerical stability trick, as with softmax.
tau, supp_size = SparsemaxFunction._threshold_and_support(input, dim=dim)
output = torch.clamp(input - tau, min=0)
ctx.save_for_backward(supp_size, output)
Expand Down