knox ревизій цього gist . До ревизії
1 file changed, 16 insertions
Burn-readme-2.rs(файл створено)
@@ -0,0 +1,16 @@ | |||
1 | + | use burn::backend::{Autodiff, Wgpu}; | |
2 | + | use burn::tensor::{Distribution, Tensor}; | |
3 | + | ||
4 | + | fn main() { | |
5 | + | type Backend = Autodiff<Wgpu>; | |
6 | + | ||
7 | + | let x: Tensor<Backend, 2> = Tensor::random([32, 32], Distribution::Default); | |
8 | + | let y: Tensor<Backend, 2> = Tensor::random([32, 32], Distribution::Default).require_grad(); | |
9 | + | ||
10 | + | let tmp = x.clone() + y.clone(); | |
11 | + | let tmp = tmp.matmul(x); | |
12 | + | let tmp = tmp.exp(); | |
13 | + | ||
14 | + | let grads = tmp.backward(); | |
15 | + | let y_grad = y.grad(&grads).unwrap(); | |
16 | + | println!("{y_grad}"); |
Новіше
Пізніше