为图中所有节点确定深度,基于拓扑排序与动态规划,O(kn)时间复杂度 k为图节点最大度数,n为图节点个数.
(self)
| 300 | return self.create_block(sp=sp, ep=ep) |
| 301 | |
| 302 | def initialize_depth(self) -> None: |
| 303 | """为图中所有节点确定深度,基于拓扑排序与动态规划,O(kn)时间复杂度 k为图节点最大度数,n为图节点个数.""" |
| 304 | for operation in self.op_orders: |
| 305 | # graph input operation, set depth as 0 |
| 306 | if len(self.graph.get_upstream_operations(operation)) == 0: |
| 307 | self.depth[operation] = 0 |
| 308 | continue |
| 309 | |
| 310 | # otherwise we will go dp |
| 311 | depths_cache = [] |
| 312 | for up_op in self.graph.get_upstream_operations(operation): |
| 313 | assert up_op in self.depth, ('Oops, that should not happen to your network.') |
| 314 | depths_cache.append(self.depth[up_op]) |
| 315 | self.depth[operation] = max(depths_cache) + 1 |
| 316 | |
| 317 | |
| 318 | class LSQDelegator(TorchQuantizeDelegator): |
no test coverage detected