Hi,
As far as I can tell, this is the expected behaviour.
The problem is when you perform this operation: res_var = scalar_var*vec_var.
If the gradients wrt res_var is g_res_var, then the formula for g_scalar_var is g_res_var * d(res_var)/d(scalar_var) = sum(g_res_var .* vec_var). In this case, vec_var contains a nan, and nan*0 = nan and the result of the sum will be nan as well.