Hello,
I’ve been studying the trainer implementation and want to confirm my understanding against the real code and explore possible options.
Current Behavior
- Agent must be a
trace.model (a Module)
The AlgorithmBase.__init__ asserts the passed agent is a Module—no plain functions or callbacks are accepted .
- Only single-argument
__call__
MinibatchAlgorithm.forward (and its parent classes) invoke the agent via agent(x), passing exactly one element from the dataset per call .
- No direct callback function support
You cannot hand in a raw Python function or lambda to the trainer; it must be wrapped as a trace.model class (or function decorated with @trace.model) to satisfy the Module interface.
Questions
-
Function optimization
Must every function I want to train be bundled into a trace.model class (or decorated) before passing it to the trainer?
-
Custom workflow steps
If I need to bypass or extend the agent’s __call__, is the intended pattern to subclass the algorithm (e.g. MinibatchAlgorithm) and override its forward() method to call specific agent methods?
-
Multiple arguments to the agent
For agents that naturally take more than one input argument, is it better to:
- Pack them into a single container (e.g.
dict or tuple) and pass that as x so I am limited to 1 parameter functions,
- Or subclass the algorithm and override
forward() so it unpacks and passes multiple parameters to the agent directly?
Hello,
I’ve been studying the trainer implementation and want to confirm my understanding against the real code and explore possible options.
Current Behavior
trace.model(aModule)The
AlgorithmBase.__init__asserts the passedagentis aModule—no plain functions or callbacks are accepted .__call__MinibatchAlgorithm.forward(and its parent classes) invoke the agent viaagent(x), passing exactly one element from the dataset per call .You cannot hand in a raw Python function or lambda to the trainer; it must be wrapped as a
trace.modelclass (or function decorated with@trace.model) to satisfy theModuleinterface.Questions
Function optimization
Must every function I want to train be bundled into a
trace.modelclass (or decorated) before passing it to the trainer?Custom workflow steps
If I need to bypass or extend the agent’s
__call__, is the intended pattern to subclass the algorithm (e.g.MinibatchAlgorithm) and override itsforward()method to call specific agent methods?Multiple arguments to the agent
For agents that naturally take more than one input argument, is it better to:
dictortuple) and pass that asxso I am limited to 1 parameter functions,forward()so it unpacks and passes multiple parameters to the agent directly?