MCPcopy Create free account
hub / github.com/alibaba/MNN / FuseAsTensor

Function FuseAsTensor

tools/converter/source/torch/torchOptimize.cpp:463–483  ·  view source on GitHub ↗

fuse as_tensor, such as below: d = prim::dtype(b); c = aten::as_tensor(a, d); -> c = aten::type_as(a, b) */

Source from the content-addressed store, hash-verified

461 -> c = aten::type_as(a, b)
462*/
463void FuseAsTensor(Graph* graph, Block* block) {
464 for (auto it = block->nodes().begin(); it != block->nodes().end();) {
465 auto* node = *it;
466 it++;
467 for (Block* sub_block : node->blocks()) {
468 FuseAsTensor(graph, sub_block);
469 }
470 if (node->kind() == prim::dtype) {
471 for (auto use : node->output(0)->uses()) {
472 auto as_tensor = use.user;
473 Node* typeAs = graph->create(aten::type_as, 1);
474 typeAs->addInput(as_tensor->input(0));
475 typeAs->addInput(node->input(0));
476 typeAs->output(0)->copyMetadata(as_tensor->output(0));
477 as_tensor->replaceAllUsesWith(typeAs);
478 as_tensor->removeAllInputs();
479 as_tensor->destroy();
480 }
481 }
482 }
483}
484
485/*
486fuse uniform, such as below:

Callers 1

torchOptPassFunction · 0.85

Calls 8

kindMethod · 0.80
addInputMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
outputMethod · 0.45
createMethod · 0.45
inputMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected