已合并
[PROF] fix mstx patch err in pytorch graph mode #16175
mei-feiyao创建于 2024年11月20日
[PROF] fix mstx patch err in pytorch graph mode #16175
已合并
mei-feiyao创建于 2024年11月20日
refs/pull/16175/head合入到master
2 个文件变更+84-109
@@ -562,111 +562,95 @@ class TestProfilerTree(TestCase):
562 aten::empty562 aten::empty
563 aten::fill_563 aten::fill_
564 nn.Module: MyModule_0564 nn.Module: MyModule_0
565- torch_npu/npu/__init__.py(...): is_initialized565+ torch/nn/modules/module.py(...): _call_impl
566- torch/nn/modules/module.py(...): _wrapped_call_impl566+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
567- torch/nn/modules/module.py(...): _call_impl567+ test_profiler_tree.py(...): forward
568- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>568+ nn.Module: ReLU_0
569- test_profiler_tree.py(...): forward569+ torch/nn/modules/module.py(...): _call_impl
570- nn.Module: ReLU_0570+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
571- torch_npu/npu/__init__.py(...): is_initialized571+ torch/nn/modules/activation.py(...): forward
572- torch/nn/modules/module.py(...): _wrapped_call_impl572+ torch/nn/functional.py(...): relu
573- torch/nn/modules/module.py(...): _call_impl573+ <built-in function _has_torch_function_unary>
574- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>574+ <built-in method relu of type object at 0xXXXXXXXXXXXX>
575- torch/nn/modules/activation.py(...): forward575+ aten::relu
576- torch/nn/functional.py(...): relu576+ aten::clamp_min
577- <built-in function _has_torch_function_unary>577+ nn.Module: Linear_0
578- <built-in method relu of type object at 0xXXXXXXXXXXXX>578+ torch/nn/modules/module.py(...): _call_impl
579- aten::relu579+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
580- aten::clamp_min580+ torch/nn/modules/linear.py(...): forward
581- nn.Module: Linear_0581+ torch/nn/modules/module.py(...): __getattr__
582- torch_npu/npu/__init__.py(...): is_initialized582+ torch/nn/modules/module.py(...): __getattr__
583- torch/nn/modules/module.py(...): _wrapped_call_impl583+ <built-in function linear>
584- torch/nn/modules/module.py(...): _call_impl584+ aten::linear
585- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>585+ aten::reshape
586- torch/nn/modules/linear.py(...): forward586+ aten::view
587- torch/nn/modules/module.py(...): __getattr__587+ aten::t
588- torch/nn/modules/module.py(...): __getattr__588+ aten::transpose
589- <built-in function linear>589+ aten::as_strided
590- aten::linear590+ aten::addmm
591- aten::reshape591+ aten::expand
592- aten::view592+ aten::as_strided
593- aten::t593+ aten::copy_
594- aten::transpose594+ aten::resolve_conj
595- aten::as_strided595+ aten::resolve_conj
596- aten::addmm596+ aten::resolve_conj
597- aten::expand597+ aten::view
598- aten::as_strided598+ nn.Module: ReLU_1
599- aten::copy_599+ torch/nn/modules/module.py(...): _call_impl
600- aten::resolve_conj600+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
601- aten::resolve_conj601+ torch/nn/modules/activation.py(...): forward
602- aten::resolve_conj602+ torch/nn/functional.py(...): relu
603- aten::view603+ <built-in function _has_torch_function_unary>
604- nn.Module: ReLU_1604+ <built-in method relu of type object at 0xXXXXXXXXXXXX>
605- torch_npu/npu/__init__.py(...): is_initialized605+ aten::relu
606- torch/nn/modules/module.py(...): _wrapped_call_impl606+ aten::clamp_min
607- torch/nn/modules/module.py(...): _call_impl
608- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
609- torch/nn/modules/activation.py(...): forward
610- torch/nn/functional.py(...): relu
611- <built-in function _has_torch_function_unary>
612- <built-in method relu of type object at 0xXXXXXXXXXXXX>
613- aten::relu
614- aten::clamp_min
615 <built-in method ones of type object at 0xXXXXXXXXXXXX>607 <built-in method ones of type object at 0xXXXXXXXXXXXX>
616 aten::ones608 aten::ones
617 aten::empty609 aten::empty
618 aten::fill_610 aten::fill_
619 nn.Module: MyModule_0611 nn.Module: MyModule_0
620- torch_npu/npu/__init__.py(...): is_initialized612+ torch/nn/modules/module.py(...): _call_impl
621- torch/nn/modules/module.py(...): _wrapped_call_impl613+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
622- torch/nn/modules/module.py(...): _call_impl614+ test_profiler_tree.py(...): forward
623- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>615+ nn.Module: ReLU_0
624- test_profiler_tree.py(...): forward616+ torch/nn/modules/module.py(...): _call_impl
625- nn.Module: ReLU_0617+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
626- torch_npu/npu/__init__.py(...): is_initialized618+ torch/nn/modules/activation.py(...): forward
627- torch/nn/modules/module.py(...): _wrapped_call_impl619+ torch/nn/functional.py(...): relu
628- torch/nn/modules/module.py(...): _call_impl620+ <built-in function _has_torch_function_unary>
629- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>621+ <built-in method relu of type object at 0xXXXXXXXXXXXX>
630- torch/nn/modules/activation.py(...): forward622+ aten::relu
631- torch/nn/functional.py(...): relu623+ aten::clamp_min
632- <built-in function _has_torch_function_unary>624+ nn.Module: Linear_0
633- <built-in method relu of type object at 0xXXXXXXXXXXXX>625+ torch/nn/modules/module.py(...): _call_impl
634- aten::relu626+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
635- aten::clamp_min627+ torch/nn/modules/linear.py(...): forward
636- nn.Module: Linear_0628+ torch/nn/modules/module.py(...): __getattr__
637- torch_npu/npu/__init__.py(...): is_initialized629+ torch/nn/modules/module.py(...): __getattr__
638- torch/nn/modules/module.py(...): _wrapped_call_impl630+ <built-in function linear>
639- torch/nn/modules/module.py(...): _call_impl631+ aten::linear
640- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>632+ aten::reshape
641- torch/nn/modules/linear.py(...): forward633+ aten::view
642- torch/nn/modules/module.py(...): __getattr__634+ aten::t
643- torch/nn/modules/module.py(...): __getattr__635+ aten::transpose
644- <built-in function linear>636+ aten::as_strided
645- aten::linear637+ aten::addmm
646- aten::reshape638+ aten::expand
647- aten::view639+ aten::as_strided
648- aten::t640+ aten::copy_
649- aten::transpose641+ aten::resolve_conj
650- aten::as_strided642+ aten::resolve_conj
651- aten::addmm643+ aten::resolve_conj
652- aten::expand644+ aten::view
653- aten::as_strided645+ nn.Module: ReLU_1
654- aten::copy_646+ torch/nn/modules/module.py(...): _call_impl
655- aten::resolve_conj647+ <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
656- aten::resolve_conj648+ torch/nn/modules/activation.py(...): forward
657- aten::resolve_conj649+ torch/nn/functional.py(...): relu
658- aten::view650+ <built-in function _has_torch_function_unary>
659- nn.Module: ReLU_1651+ <built-in method relu of type object at 0xXXXXXXXXXXXX>
660- torch_npu/npu/__init__.py(...): is_initialized652+ aten::relu
661- torch/nn/modules/module.py(...): _wrapped_call_impl653+ aten::clamp_min
662- torch/nn/modules/module.py(...): _call_impl
663- <built-in method _get_tracing_state of PyCapsule object at 0xXXXXXXXXXXXX>
664- torch/nn/modules/activation.py(...): forward
665- torch/nn/functional.py(...): relu
666- <built-in function _has_torch_function_unary>
667- <built-in method relu of type object at 0xXXXXXXXXXXXX>
668- aten::relu
669- aten::clamp_min
670 torch/profiler/profiler.py(...): __exit__654 torch/profiler/profiler.py(...): __exit__
671 torch/profiler/profiler.py(...): stop655 torch/profiler/profiler.py(...): stop
672 ...""",656 ...""",
@@ -3,10 +3,6 @@ import torch
3from torch.nn import Module3from torch.nn import Module
4from torch.utils.data import DataLoader4from torch.utils.data import DataLoader
5 5 
6-import torch_npu
7-from torch_npu.utils._step import _custom_call
8- 
9-original_tx_call = Module.__call__
10original_iter = DataLoader.__iter__6original_iter = DataLoader.__iter__
11original_save = torch.serialization.save7original_save = torch.serialization.save
12original_singlenext = torch.utils.data.dataloader._SingleProcessDataLoaderIter.__next__8original_singlenext = torch.utils.data.dataloader._SingleProcessDataLoaderIter.__next__
@@ -106,10 +102,5 @@ def _custom_save(func):
106 102 
107 103 
108def apply_mstx_patch():104def apply_mstx_patch():
109- global original_tx_call
110- 
111- if Module.__call__.__name__ == "_custom_call":
112- original_tx_call = _custom_call
113- Module.__call__ = _custom_tx_call
114 DataLoader.__iter__ = _custom_dataloader_iter105 DataLoader.__iter__ = _custom_dataloader_iter
115 torch.serialization.save = _custom_save(original_save)106 torch.serialization.save = _custom_save(original_save)