 
             // gradient with respect to x[t]
             if (skip_type)
-                *gxp = gh_val*(1.f-g2);
+                *gxp = gh_val*(1.f-g2*mask);
         }
 
         up -= ncols_u_;

            // c = c'*g1 + u0*(1-g1) = (c'-u0)*g1 + u0

            // gradient with respect to values in the second gate g2
            const auto gg2 = gh_val*(c_val*mask-x_val)*(g2*(1.f-g2));
            gbias2 += gg2;
            gwc2 += gg2*prev_c_val;
            *gvp2 = gg2*prev_c_val;

            // c = c'*g1 + u0*(1-g1) = (c'-u0)*g1 + g0

            // gradient with respect to values in the second gate g2
            const auto gg2 = gh_val*(c_val-x_val)*mask*(g2*(1.f-g2));
            gbias2 += gg2;
            gwc2 += gg2*prev_c_val;
            *gvp2 = gg2*prev_c_val;
