From: Vsevolod Stakhov Date: Thu, 4 Oct 2018 14:32:27 +0000 (+0100) Subject: [Fix] Do not load torch on each rspamadm invocation X-Git-Tag: 1.8.1~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c57c656955c6ab3577a1e4a5477379b01471889;p=thirdparty%2Frspamd.git [Fix] Do not load torch on each rspamadm invocation --- diff --git a/lualib/rspamadm/rescore.lua b/lualib/rspamadm/rescore.lua index cc331c6e85..dfa73f2d5f 100644 --- a/lualib/rspamadm/rescore.lua +++ b/lualib/rspamadm/rescore.lua @@ -18,8 +18,6 @@ if not rspamd_config:has_torch() then return end -local torch = require "torch" -local nn = require "nn" local lua_util = require "lua_util" local ucl = require "ucl" local logger = require "rspamd_logger" @@ -28,6 +26,10 @@ local rspamd_util = require "rspamd_util" local argparse = require "argparse" local rescore_utility = require "rescore_utility" +-- Load these lazily +local torch +local nn + local opts local ignore_symbols = { ['DATE_IN_PAST'] =true, @@ -509,6 +511,8 @@ local function get_threshold() end local function handler(args) + torch = require "torch" + nn = require "nn" opts = parser:parse(args) if not opts['log'] then parser:error('no log specified') diff --git a/src/plugins/lua/neural.lua b/src/plugins/lua/neural.lua index 9d0bbb4468..0221600832 100644 --- a/src/plugins/lua/neural.lua +++ b/src/plugins/lua/neural.lua @@ -33,8 +33,6 @@ local N = "neural" if rspamd_config:has_torch() then use_torch = true - torch = require "torch" - nn = require "nn" end -- Module vars @@ -949,6 +947,9 @@ else if opts.disable_torch then use_torch = false + else + torch = require "torch" + nn = require "nn" end local id = rspamd_config:register_symbol({ @@ -1017,9 +1018,9 @@ else if worker:is_primary_controller() then -- We also want to train neural nets when they have enough data rspamd_config:add_periodic(ev_base, 0.0, - function(_, _) - return maybe_train_anns(rule, cfg, ev_base, worker) - end) + function(_, _) + return maybe_train_anns(rule, cfg, ev_base, worker) + end) end end) end