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

Small negative values cause the gradient of sigmoid to become NaN #1139

Closed
wcshds opened this issue Jan 12, 2024 · 1 comment · Fixed by #1140
Closed

Small negative values cause the gradient of sigmoid to become NaN #1139

wcshds opened this issue Jan 12, 2024 · 1 comment · Fixed by #1140

Comments

@wcshds
Copy link
Contributor

wcshds commented Jan 12, 2024

Here is the code:

use burn::{
    backend::{Autodiff, NdArray},
    tensor::{activation, Data, Tensor},
};

fn main() {
    let data = Data::<f32, 1>::from([-90.0]);

    let device = Default::default();
    let tensor_1 = Tensor::<Autodiff<NdArray>, 1>::from_data(data, &device).require_grad();

    let tensor_2 = activation::sigmoid(tensor_1.clone());
    let grads = tensor_2.backward();

    let grad_1 = tensor_1.grad(&grads).unwrap();
    println!("{}", grad_1);
}

The result is NaN.

@wcshds
Copy link
Contributor Author

wcshds commented Jan 12, 2024

Is it possible to manually define differentials during the activation function backpropagation? So we don't have to automatically differentiate log and exp.

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 a pull request may close this issue.

1 participant