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

add mu_kernel to of delta_kernel in flipout layers? #3

Closed
burntcobalt opened this issue Jul 21, 2021 · 2 comments
Closed

add mu_kernel to of delta_kernel in flipout layers? #3

burntcobalt opened this issue Jul 21, 2021 · 2 comments

Comments

@burntcobalt
Copy link

burntcobalt commented Jul 21, 2021

Hi,

Shouldn't mu_kernel be added to delta_kernel in the code below?

Best,
Lewis

diff --git a/bayesian_torch/layers/flipout_layers/conv_flipout.py b/bayesian_torch/layers/flipout_layers/conv_flipout.py
index 4b3e88d..719cfdc 100644
--- a/bayesian_torch/layers/flipout_layers/conv_flipout.py
+++ b/bayesian_torch/layers/flipout_layers/conv_flipout.py
@@ -165,7 +165,7 @@ class Conv1dFlipout(BaseVariationalLayer_):
         sigma_weight = torch.log1p(torch.exp(self.rho_kernel))
         eps_kernel = self.eps_kernel.data.normal_()
 
-        delta_kernel = (sigma_weight * eps_kernel)
+        delta_kernel = (sigma_weight * eps_kernel) + self.mu_kernel 
 
         kl = self.kl_div(self.mu_kernel, sigma_weight, self.prior_weight_mu,
                          self.prior_weight_sigma)
@ranganathkrishnan
Copy link
Contributor

Hi Lewis,

In Flipout (Wen et al. 2018 ) method, the operation is performed separately with the mean and perturbation component as shown below (Eqn(4) in https://arxiv.org/pdf/1803.04386.pdf). I hope this helps to clarify your question.

flipout

outputs

    outputs = F.conv1d(x,
                       weight=self.mu_kernel,
                       bias=self.mu_bias,
                       stride=self.stride,
                       padding=self.padding,
                       dilation=self.dilation,
                       groups=self.groups)

perturbed_outputs

    perturbed_outputs = F.conv1d(x * sign_input,
                                 bias=bias,
                                 weight=delta_kernel,
                                 stride=self.stride,
                                 padding=self.padding,
                                 dilation=self.dilation,
                                 groups=self.groups) * sign_output

outputs + perturbed_outputs

    return outputs + perturbed_outputs, kl

Best,
Ranganath

@burntcobalt
Copy link
Author

Ah, I see. Thank you, Ranganath.

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

No branches or pull requests

2 participants