Naposledy aktivní 1728856667

Revize cefb81da91f1ac9a6a0e0598c0604efa9722a7b9

Burn-readme-3.rs Raw
1use burn::backend::{Autodiff, Fusion, Wgpu};
2use burn::tensor::{Distribution, Tensor};
3
4fn main() {
5 type Backend = Autodiff<Fusion<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}");
17}