Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Implementing var->value() in tape #11

Closed
kexinzhao opened this issue Jun 19, 2018 · 0 comments · Fixed by #18
Closed

Implementing var->value() in tape #11

kexinzhao opened this issue Jun 19, 2018 · 0 comments · Fixed by #18
Assignees

Comments

@kexinzhao
Copy link
Collaborator

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 & InferVarType
LOG(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:

  1. 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.

  1. 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.

@kexinzhao kexinzhao self-assigned this Jun 19, 2018
@kexinzhao kexinzhao changed the title Implementing lazy execution in tape Implementing var->value() in tape Jun 19, 2018
@tonyyang-svail tonyyang-svail mentioned this issue Jun 19, 2018
36 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant