- Notifications
You must be signed in to change notification settings - Fork 5.9k
Closed
Description
As we discussed before, shared_ptr is preferred to avoid in our refactoring code for simplifying our design and making lifecycle management clearer.
The shared_ptr of OperatorBase should be removed. We design our operator lifecycle like below:
- all Python API will return an
OperatorBase*orNetOp*. We let Python side to destroy operators. - If we destroy a
NetOporRnnOp(which contains step_net), all operator belongs to that net will be destroyed, too. - If two
NetOpwant to share sameOperator, orNetOpadd anOperator*but thatOperator*is held by Python, too. We useOperator::Clone()to create a new Operator pointer. i.e. One operator instance is avoided to be shared by multiple NetOp.- Since our operator design is very lightweight(only variable names and attrs are stored), and topology is constructed before whole training started,
Clonean operator will simplify our design without costing too much in time and space.
- Since our operator design is very lightweight(only variable names and attrs are stored), and topology is constructed before whole training started,
The whole things come to following steps:
- Add
Clonemethod to OperatorBase - Remove shared_ptr inside C++ and Python
- Expose
CreateOpAndAddItToSelfmethod forNetOpin Python(to avoidCloneevery time).