-
Notifications
You must be signed in to change notification settings - Fork 755
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
Graph rename v2 #9351
Graph rename v2 #9351
Conversation
…flow-Inc/oneflow into graph_rename_v2
python/oneflow/nn/graph/__init__.py
Outdated
@@ -15,3 +15,6 @@ | |||
""" | |||
from .graph import Graph | |||
from .block import Block | |||
from .block_graph import BlockGraph | |||
from .block_graph import ModuleGraph | |||
from .block_graph import TensorGraph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
导出了如上类型,以供转换
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个命名结果,取得所有人的认可了吗? @leaves-zwx @CPFLAME @jackalcooper
主要是 TensorGraph 这个,还是 GraphTensor 呢? 或者 gtensor ? TensorGraph 乍一听感觉没理解这个到底是 Tensor 还是 Graph,还是由 Tensor 组成的 Graph。
同理: ModuleGraph 和 GraphModule / gmodule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Origin Type:Module, Tensor
Graph Type: ModuleGraph, TensorGraph
Block Type: ModuleBlock, TensorBlock
一个 Block 内含了 Origin 和 Graph 两个部分;
有这样一个对应关系。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里很奇怪,一般的惯例是定语在前
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也行,那我统一改成这样:
Origin Type:Module, Tensor
Graph Type: GraphModule, GraphTensor
Block Type: BlockModule, BlockTensor
r"""ModuleGraph is the graph representation of a nn.Module in a nn.Graph. | ||
|
||
When an nn.Module is added into an nn.Graph, it is wrapped into a ModuleBlock. The ModuleBlock has a ModuleGraph inside it. | ||
You can get and set the ModuleGraph to enable graph optimization on the nn.Module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModuleGraph 的定义,stage 和 Activation checkpint 的配置改到了直接在 ModuleGraph 上配置
belonged_graph: weakref.ProxyTypes = None, | ||
tensor_graph_type: BlockGraphType = BlockGraphType.NONE | ||
): | ||
super().__init__(prefix, name, belonged_graph, tensor_graph_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TensorGraph,只用于转换,提供基类的方法,其它方法没有
if lines is not None: | ||
main_str += "\n " + "\n ".join(lines) + "\n" | ||
main_str += ")" | ||
return main_str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModuleGraph的打印
(ModuleGraph:linears(activation_checkpointing=True, )): (
(OPERATOR: linears-identity-0(_SeqGraph_0_input.0.0_2/out:(sbp=(B), size=(4, 10), dtype=(oneflow.float32))) -> (linears-identity-0/out_0:(sbp=(B), size=(4, 10), dtype=(oneflow.float32))), placement=(oneflow.placement(type="cpu", ranks=[0])))
)
python/oneflow/nn/graph/block.py
Outdated
# The original data | ||
self._oneflow_internal_origin__ = None | ||
# The graph representation of the original data | ||
self._oneflow_internal_blockgraph__ = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block 的数据拆成原始的 eager 和 graph 两个部分,以避免冲突
python/oneflow/nn/graph/block.py
Outdated
self._type = BlockType.MODULE | ||
self._is_executing_forward = False | ||
super().__init__() | ||
self._oneflow_internal_blockgraph__ = ModuleGraph(prefix, name, belonged_graph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModuleBlock 初始化,内含一个 ModuleGraph
def set_origin(self, origin): | ||
self._origin = origin | ||
def _oneflow_internal_blockgraph__set_origin(self, origin): | ||
self._oneflow_internal_origin__ = origin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModuleBlock 初始化,内含一个原始的 Module
Speed stats:
|
Speed stats:
|
View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9351/ |
Speed stats:
|
View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9351/ |
Speed stats:
|
CI failed when running job: cuda-module. PR label automerge has been removed |
Speed stats:
|
Speed stats:
|
View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/9351/ |
本 pr 去掉 Block 上的 attribute 和 config
实现的方案:
用例
Fix issue: #9193
另外支持 nn.Module 多重继承时的property获取
Fix issue:#9345 and #9186