Ctype<inplace> _dropout_impl(T& input, double p, bool train) { TORCH_CHECK(p >= 0 && p <= 1, "dropout probability has to be between 0 and 1, but got ", p); if (p == 0 || !train) { return input; } if (p == 1) { return multiply<inplace>(input, at::zeros({}, input.options())); } at::Tensor b; // used for alpha_dropout only auto noise = feature_dropout ? make_feature_noise(input) : at::empty_like(input); noise.bernoulli_(1 - p); if (alpha_dropout) { constexpr double alpha = 1.7580993408473766; double a = 1. / std::sqrt((alpha * alpha * p + 1) * (1 - p)); b = noise.add(-1).mul_(alpha * a).add_(alpha * a * p); noise.mul_(a); } else { noise.div_(1 - p); } if (!alpha_dropout) { return multiply<inplace>(input, noise); } else { return multiply<inplace>(input, noise).add_(b); } }
static inline mul(num*a,num *b,num *c){ mul_(a,b,c); c->sbit=a->sbit*b->sbit; rm0(c); }