From e5c8b88f90763073fc927ee232bda30fcbc05595 Mon Sep 17 00:00:00 2001 From: Laurent Mazare Date: Sun, 28 Apr 2024 08:30:35 +0200 Subject: [PATCH] Apply the cast before the scaling. (#2135) --- candle-nn/src/ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/candle-nn/src/ops.rs b/candle-nn/src/ops.rs index 1dac8c3b..7fc26c3f 100644 --- a/candle-nn/src/ops.rs +++ b/candle-nn/src/ops.rs @@ -70,7 +70,7 @@ pub fn dropout(xs: &Tensor, drop_p: f32) -> Result { let rand = Tensor::rand(0f32, 1f32, xs.shape(), xs.device())?; let scale = 1.0 / (1.0 - drop_p as f64); let drop_p = Tensor::new(drop_p, xs.device())?.broadcast_as(xs.shape())?; - let mask = (rand.ge(&drop_p)? * scale)?.to_dtype(xs.dtype())?; + let mask = (rand.ge(&drop_p)?.to_dtype(xs.dtype())? * scale)?; xs * mask }