Browse Source

[Minor] Don't load torch unless really needed

pull/2573/head
Vsevolod Stakhov 7 years ago
parent
commit
9a3b5ef566
  1. 15
      lualib/lua_nn.lua
  2. 2
      rules/rspamd.lua

15
lualib/lua_nn.lua

@ -20,9 +20,13 @@ local exports = {}
local lua_nn_models = {}
if rspamd_config:has_torch() then
torch = require "torch"
torch.setnumthreads(1)
local conf_section = rspamd_config:get_all_opt("nn_models")
if conf_section then
if rspamd_config:has_torch() then
torch = require "torch"
torch.setnumthreads(1)
end
end
if torch then
@ -43,10 +47,9 @@ if torch then
end
end
end
local section = rspamd_config:get_all_opt("nn_models")
if section and type(section) == 'table' then
for k,v in pairs(section) do
if conf_section and type(conf_section) == 'table' then
for k,v in pairs(conf_section) do
if not rspamd_config:add_map(v, "nn map " .. k, gen_process_callback(k)) then
rspamd_logger.warnx(rspamd_config, 'cannot load NN map %1', k)
end

2
rules/rspamd.lua

@ -65,4 +65,4 @@ if rmaps and type(rmaps) == 'table' then
end
local rspamd_nn = require "lua_nn"
rspamd_nn.load_rspamd_nn() -- Load defined models
rspamd_nn.load_rspamd_nn() -- Load defined models if any
Loading…
Cancel
Save