Removed the signature.
[profiler-torch.git] / README.md
1
2 # Introduction #
3
4 This is a simple profiler for torch to estimate processing time per module per function.
5
6 It seems to work okay, but there was no heavy testing so far. See test-profiler.lua for a short example.
7
8 ## Example ##
9
10 A simple example would be
11
12 ```Lua
13 require 'torch'
14 require 'nn'
15 require 'profiler'
16
17 local input = torch.Tensor(100000, 20):uniform()
18 local target = torch.Tensor(input:size(1), 2):uniform()
19 local criterion = nn.MSECriterion()
20
21 local model = nn.Sequential()
22    :add(nn.Linear(input:size(2), 1000))
23    :add(nn.ReLU())
24    :add(nn.Linear(1000, target:size(2)))
25
26 profiler.decorate(model)
27 profiler.color = nil
28
29 local output = model:forward(input)
30 criterion:forward(output, target)
31 local dloss = criterion:backward(output, target)
32 model:backward(input, dloss)
33
34 profiler.print(model, input:size(1))
35 ```
36
37 which prints
38
39 ```
40  nn.Sequential 3.03s [100.00%] (30.3mus/sample)
41   :backward 1.94s [64.16%] (19.4mus/sample)
42   :updateOutput 1.08s [35.84%] (10.8mus/sample)
43   * nn.Linear 1.22s [40.41%] (12.2mus/sample)
44     :backward 0.64s [21.24%] (6.4mus/sample)
45     :updateOutput 0.58s [19.17%] (5.8mus/sample)
46   * nn.ReLU 1.05s [34.62%] (10.5mus/sample)
47     :backward 0.74s [24.30%] (7.4mus/sample)
48     :updateOutput 0.31s [10.32%] (3.1mus/sample)
49   * nn.Linear 0.76s [24.97%] (7.6mus/sample)
50     :backward 0.56s [18.62%] (5.6mus/sample)
51     :updateOutput 0.19s [6.34%] (1.9mus/sample)
52 ```
53
54 ## Usage ##
55
56 ### profiler.color ###
57
58 This is a Boolean flag to state if the printing should be done in color. It is true by default.
59
60 ### profiler.decorate(model, [functionsToDecorate]) ###
61
62 This function should be called before starting the computation.
63
64 It replaces functions specified in functionsToDecorate by instrumented versions which keep track of computation times. If functionsToDecorate is not provided, it decorates by default updateOutput and backward.
65
66 It also resets the accumulated timings to zero.
67
68 ### profiler.print(model, [nbSamples], [totalTime]) ###
69
70 Prints the measured processing times. If nbSamples is provided, the time per samples will also be printed. If totalTime is not provided, the total at the top is used.
71
72 Non-Containers are hilighted with a '*' or in red.