Skip to content
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
4 changes: 2 additions & 2 deletions fl4health/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BernoulliSample(torch.autograd.Function):
"""

@staticmethod
def forward(bernoulli_probs: torch.Tensor) -> torch.Tensor: # type: ignore
def forward(bernoulli_probs: torch.Tensor) -> torch.Tensor:
return torch.bernoulli(input=bernoulli_probs)

@staticmethod
Expand All @@ -33,7 +33,7 @@ def setup_context(ctx: Any, inputs: tuple[torch.Tensor], output: torch.Tensor) -
# This method determines the "gradient" of the BernoulliSample function.
# grad_output is supposed to be the gradient w.r.t. the output of the forward method.
@staticmethod
def backward(ctx: torch.Any, grad_output: torch.Tensor) -> torch.Tensor: # type: ignore
def backward(ctx: Any, grad_output: torch.Tensor) -> torch.Tensor: # type: ignore
Comment thread
lotif marked this conversation as resolved.
# ctx.saved_tensors is a tuple (of length 1 in this case). Hence the indexing here.
bernoulli_probs = ctx.saved_tensors[0]
return bernoulli_probs * grad_output
Expand Down
Loading