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

exp_backward_kernel has wrong offset for grad? #36

Open
zjcs opened this issue Aug 5, 2024 · 0 comments
Open

exp_backward_kernel has wrong offset for grad? #36

zjcs opened this issue Aug 5, 2024 · 0 comments

Comments

@zjcs
Copy link

zjcs commented Aug 5, 2024

As I know, exp operation will convert lie vector to lie group, so the grad of exp should be on the tangent space, a Group::K vector, while the offset in exp_backward_kernel is Group::N. Is it wrong?

Current implementation:

        Grad dX(grad + i*Group::N);

Modified implementation:

        Grad dX(grad + i*Group::K);

Here is the code in lietorch_gpu.cu:

template <typename Group, typename scalar_t>
EIGEN_DEVICE_FUNC void exp_forward_kernel(const scalar_t* a_ptr, scalar_t* X_ptr) {
    // exponential map forward kernel
    using Tangent = Eigen::Matrix<scalar_t,Group::K,1>;
    using Data = Eigen::Matrix<scalar_t,Group::N,1>;
    
    GPU_1D_KERNEL_LOOP(i) {
        Tangent a(a_ptr + i*Group::K);
        Eigen::Map<Data>(X_ptr + i*Group::N) = Group::Exp(a).data();
    }
}

template <typename Group, typename scalar_t>
EIGEN_DEVICE_FUNC void exp_backward_kernel(const scalar_t* grad, const scalar_t* a_ptr, scalar_t* da) {
    // exponential map backward kernel
    using Tangent = Eigen::Matrix<scalar_t,Group::K,1>;
    using Grad = Eigen::Matrix<scalar_t,1,Group::K>;
    using Data = Eigen::Matrix<scalar_t,Group::N,1>;

    GPU_1D_KERNEL_LOOP(i) {
        Tangent a(a_ptr + i*Group::K);
        Grad dX(grad + i*Group::N);
        Eigen::Map<Grad>(da + i*Group::K) = dX * Group::left_jacobian(a);
    }
}
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

1 participant