(&self, x: &Tensor)
| 298 | } |
| 299 | |
| 300 | fn silu(&self, x: &Tensor) -> Result<Tensor> { |
| 301 | if x.dtype() == DType::F32 { |
| 302 | let data = x.contiguous()?.flatten_all()?.to_vec1::<f32>()?; |
| 303 | let shape = x.dims(); |
| 304 | let mut out = data; |
| 305 | for v in out.iter_mut() { |
| 306 | let x = *v; |
| 307 | *v = x / (1.0 + (-x).exp()); |
| 308 | } |
| 309 | return Tensor::from_vec(out, shape, x.device()); |
| 310 | } |
| 311 | candle_nn::ops::silu(x) |
| 312 | } |
| 313 | |
| 314 | fn f8e4m3_to_f32(&self, x: &Tensor) -> Result<Tensor> { |
| 315 | x.to_dtype(DType::F32) |