Skip to content

Commit 0e73b14

Browse files
committed
Adding a :applyToModules() method to gModule, and :training() and :evaluate() should be applied 'self' as well.
1 parent 0a66cb9 commit 0e73b14

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

gmodule.lua

+8
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,25 @@ function gModule:share(gm, ...)
177177
end
178178

179179
function gModule:training()
180+
parent.training(self)
180181
for _, m in ipairs(self.modules) do
181182
m:training()
182183
end
183184
end
184185

185186
function gModule:evaluate()
187+
parent.evaluate(self)
186188
for _, m in ipairs(self.modules) do
187189
m:evaluate()
188190
end
189191
end
190192

193+
function gModule:applyToModules(func)
194+
for _, m in ipairs(self.modules) do
195+
func(m)
196+
end
197+
end
198+
191199
--[[ Recursively applies type(type_str) to any tensors in the argument. If the
192200
argument is a tensor, type(type_str) is applied; if the argument is an array,
193201
this function recurses into it. ]]

0 commit comments

Comments
 (0)