You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
In Tape, we want to provide the lazy evaluation feature, so that we can use the following code to compute the value of a variable:
auto loss = softmax(linear2(linear1(input)), label); // compile time InferShape & InferVarTypeLOG(INFO) << loss.value(); // Run forward up to loss
When value() is called upon a variable, the variable must know the location of the operator handle in the global tape so that tape run from the current op position up to the location of the target op handle.
There are two ways of adding the needed info in variable class for lazy exe:
Add a int op_position_ field
Pros: tape is implemented as a vector of op handles and has a built-in current_position field. A op_position_ field in variable is easy to implement and understand by comparing it with current_location and overall size of the tape.
Cons: OpHandle does not store its position in the tape. If we later want to do kernel fusion or something similar to change the vector<ophandle> in tape, the position of the ops needed to updated for variables generated by many ops.
Add a weak_ptr<OpHandle> op_ field. (we don't consider shared_ptr here because there maybe cyclic referencing issue between OpHandle and Variable)
Pros: If there is change in vector<ophandle> in tape, we mostly don't need to change Variable.
Cons:
weak_ptr may occupy more memory than size_t.
Hard to implement and error prone: we need to use while to compare the current OPHandle and the target OpHandle and run it until we hit the target position, but what if the variable's correponding OP is before the current location or there is no such OpHandle in the current tape.
Thanks @tonyyang-svail for the suggestion on simply run the tape forward method when calling the value() function in the Variable. It is simple, straightforward and thus preferred.
The text was updated successfully, but these errors were encountered:
In Tape, we want to provide the lazy evaluation feature, so that we can use the following code to compute the value of a variable:
When
value()
is called upon a variable, the variable must know the location of the operator handle in the global tape so that tape run from the current op position up to the location of the target op handle.There are two ways of adding the needed info in variable class for lazy exe:
int op_position_
fieldPros: tape is implemented as a vector of op handles and has a built-in current_position field. A
op_position_
field in variable is easy to implement and understand by comparing it with current_location and overall size of the tape.Cons:
OpHandle
does not store its position in the tape. If we later want to do kernel fusion or something similar to change thevector<ophandle>
in tape, the position of the ops needed to updated for variables generated by many ops.weak_ptr<OpHandle> op_
field. (we don't consider shared_ptr here because there maybe cyclic referencing issue between OpHandle and Variable)Pros: If there is change in
vector<ophandle>
in tape, we mostly don't need to change Variable.Cons:
size_t
.while
to compare the current OPHandle and the target OpHandle and run it until we hit the target position, but what if the variable's correponding OP is before the current location or there is no such OpHandle in the current tape.Thanks @tonyyang-svail for the suggestion on simply run the tape forward method when calling the value() function in the Variable. It is simple, straightforward and thus preferred.
The text was updated successfully, but these errors were encountered: