MCPcopy Index your code
hub / github.com/OpenPPL/ppq / split_graph_into_blocks

Method split_graph_into_blocks

ppq/quantization/optim/training.py:185–222  ·  view source on GitHub ↗

block construction function for training-based algorithms, if `block_limit` is not specified, block grandularity will be controlled by the default value OPTIM_ADVOPT_GRAPH_MAXSIZE specified in ppq.core.common. Args: graph (BaseGraph): ppq ir graph exe

(
        self, graph: BaseGraph, executing_order: List[Operation],
        blocksize: int = None, overlap: bool = False, 
        interested_layers: List[str] = None)

Source from the content-addressed store, hash-verified

183 cfg.scale._grad = None
184
185 def split_graph_into_blocks(
186 self, graph: BaseGraph, executing_order: List[Operation],
187 blocksize: int = None, overlap: bool = False,
188 interested_layers: List[str] = None) -> List[TrainableBlock]:
189 """block construction function for training-based algorithms, if
190 `block_limit` is not specified, block grandularity will be controlled by
191 the default value OPTIM_ADVOPT_GRAPH_MAXSIZE specified in ppq.core.common.
192
193 Args:
194 graph (BaseGraph): ppq ir graph
195 executing_order (List[Operation]): topo search order
196 block_limit (int, optional): controls maximum depth of a block. Defaults to None.
197
198 Returns:
199 List[TrainableBlock]: list of all partitioned blocks
200 """
201 if blocksize is None: blocksize = OPTIM_ADVOPT_GRAPH_MAXDEPTH
202 visited_ops, blocks = set(), []
203 block_builder = BlockBuilder(graph=graph, topo_order=executing_order)
204
205 for op in graph.operations.values():
206 # start from computing op
207 if op in visited_ops and overlap is False: continue
208 if isinstance(op, QuantableOperation) and op.is_computing_op:
209 block = block_builder.build(op, blocksize)
210 # by default blocks are exclusive from each other
211 for op in block.rps: visited_ops.add(op)
212 blocks.append(block)
213
214 ret = []
215 if interested_layers is None or len(interested_layers) == 0:
216 ret = blocks # if no interested_layers, finetune all.
217 else:
218 for candidate in blocks:
219 assert isinstance(candidate, TrainableBlock)
220 if any([op.name in interested_layers for op in candidate.rps]):
221 ret.append(candidate)
222 return ret
223
224 def collect(
225 self, graph: BaseGraph, block: TrainableBlock, executor: TorchExecutor,

Callers 3

optimizeMethod · 0.80
optimizeMethod · 0.80
optimizeMethod · 0.80

Calls 4

buildMethod · 0.95
BlockBuilderClass · 0.85
addMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected