Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
45 lines (34 loc) · 1.4 KB
/
Copy pathProgram.cs
File metadata and controls
45 lines (34 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
usingSystem;
usingSystem.Diagnostics;
usingSystem.Linq;
usingNumpy.Models;
usingPython.Runtime;
usingTorch;
namespaceSimpleNeuralNetworkExample
{
partialclassProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("Importing torch ...");
vardtype=torch.@float;
vardevice=torch.device("cuda:0");// "cuda:0" or "cpu"
// N is batch size; D_in is input dimension;
// H is hidden dimension; D_out is output dimension.
var(N,D_in,H,D_out)=(64,1000,100,10);
// Create random Tensors to hold input and outputs.
// Setting requires_grad=False indicates that we do not need to compute gradients
// with respect to these Tensors during the backward pass.
Console.WriteLine("Creating random data ...");
varx=torch.randn(newShape(N,D_in),device:device,dtype:dtype);
vary=torch.randn(newShape(N,D_out),device:device,dtype:dtype);
LearnManualBackprop(dtype,device,x,y);
LearnWithAutoGrad(dtype,device,x,y);
LearnWithNnModules(x,y);
LearnWithCustomAutoGrad(dtype,device,x,y);
LearnWithOptimizer(x,y);
Console.Write("Hit any key to exit: ");
Console.ReadKey();
}
}
}