-
Notifications
You must be signed in to change notification settings - Fork 682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Free EagerTensor caught in nn.Graph build #5777
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…dev_cc_free_eager_tensor
Speed stats:
|
…dev_cc_free_eager_tensor
strint
reviewed
Aug 11, 2021
strint
reviewed
Aug 11, 2021
leaves-zwx
reviewed
Aug 11, 2021
strint
approved these changes
Aug 11, 2021
leaves-zwx
approved these changes
Aug 11, 2021
…-Inc/oneflow into dev_cc_free_eager_tensor
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
August 11, 2021 12:58
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
August 11, 2021 16:29
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
August 11, 2021 18:39
oneflow-ci-bot
requested review from
oneflow-ci-bot
and removed request for
oneflow-ci-bot
August 11, 2021 20:13
Speed stats:
|
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
动静转换 nn.Graph 支持 转化 Build 过程中(nn.Module)被捕获的 自由变量(Free EagerTensor)为 不可训练的 Variable Op。
比如 nn.Module forward 函数中临时创建的 Tensor。
由于 RunLazyJobInstruction 传入的参数里包含了 NNGraph(shared_ptr),且 VM 相应的 LazyJobComputeStream 会保存 last NNGraph 用于处理 NNGraph 运行时的 相同 Graph 流水、不同 Graph 互斥。所以有一个约束是 NNGraph 对象中不能 Hold 住任何的 Tensor 对象(shared_ptr),因为如果这么做的话,会使得这个 Tensor 的生命周期延长到非常非常晚。因此在处理 Graph Build 过程中遇到的游离 EagerTensor 时,我选择保存到 SessionContext 中,并在 NNGraph 析构时释放这些 Tensor 的 指针,使得 Tensor 的生命周期可以跟 Graph 保持同步。
在 module forward 中写的 x > 0 之类的 代码会自动生成 flow.Tensor([0]) ,这时构建的 Tensor 应该是 EagerTensor (即 forward 时创建 游离 Tensor)。所以需要在 flow.Tensor 函数中临时禁用掉 LazyMode。