Dernière activité 1728856597

Burn-readme-2.rs Brut
1use burn::backend::{Autodiff, Wgpu};
2use burn::tensor::{Distribution, Tensor};
3
4fn 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}");