X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=profiler.lua;h=34e180b56ff9ac9ace944fe34c6f94089c392641;hb=c2a852c17eb19f472762343ee8dfe3e0d1b40dbf;hp=b95d7507575da856f5f4919e825a05a82b2eafb6;hpb=545f83595445ffd1212cbe7f23e76f906b1ff4b4;p=profiler-torch.git diff --git a/profiler.lua b/profiler.lua index b95d750..34e180b 100644 --- a/profiler.lua +++ b/profiler.lua @@ -37,7 +37,7 @@ require 'sys' profiler = {} -function profiler.decor(model, functionsToDecorate) +function profiler.decorate(model, functionsToDecorate) local functionsToDecorate = functionsToDecorate or { @@ -65,7 +65,7 @@ function profiler.decor(model, functionsToDecorate) if torch.isTypeOf(model, nn.Container) then for _, m in ipairs(model.modules) do - profiler.decor(m, functionsToDecorate) + profiler.decorate(m, functionsToDecorate) end end @@ -76,21 +76,14 @@ function profiler.print(model, nbSamples, indent) print(string.format('%s* %s', indent, model.__typename)) - if nbSamples then - for l, t in pairs(model.accTime) do - print(string.format('%s %s %.02fs (%.01fmus/sample)', - indent, - l, - t, - 1e6 * t / nbSamples)) - end - else - for l, t in pairs(model.accTime) do - print(string.format('%s %s %.02fs', - indent, - l, - t)) + for l, t in pairs(model.accTime) do + local s + if nbSamples then + s = string.format(' (%.01fmus/sample)', 1e6 * t / nbSamples) + else + s = '' end + print(string.format('%s %s %.02fs%s', indent, l, t, s)) end if torch.isTypeOf(model, nn.Container) then