mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[Profiler] Move legacy profiler out of torch/csrc/autograd (#85512)
The legacy profiler is an eyesore in the autograd folder. At this point the implementation is almost completely decoupled from the rest of profiler, and it is in maintaince mode pending deprecation. As a result, I'm moving it to `torch/csrc/profiler/standalone`. Unfortuantely BC requires that the symbols remain in `torch::autograd::profiler`, so I've put some basic forwarding logic in `torch/csrc/autograd/profiler.h`. One strange bit is that `profiler_legacy.h` forward declares `torch::autograd::Node`, but doesn't seem to do anything with it. I think we can delete it, but I want to test to make sure. (Note: this should not land until https://github.com/pytorch/torchrec/pull/595 is landed.) Differential Revision: [D39108648](https://our.internmc.facebook.com/intern/diff/D39108648/) Pull Request resolved: https://github.com/pytorch/pytorch/pull/85512 Approved by: https://github.com/aaronenyeshi
This commit is contained in:
parent
35fb007749
commit
157a3d2a7c
|
|
@ -131,7 +131,6 @@ libtorch_sources_common = sorted(core_sources_common + torch_unpickler_common)
|
|||
|
||||
# The profilers are not needed in the lite interpreter build.
|
||||
libtorch_profiler_sources = [
|
||||
"torch/csrc/autograd/profiler_legacy.cpp",
|
||||
"torch/csrc/autograd/profiler_kineto.cpp",
|
||||
"torch/csrc/profiler/collection.cpp",
|
||||
"torch/csrc/profiler/kineto_shim.cpp",
|
||||
|
|
@ -141,6 +140,7 @@ libtorch_profiler_sources = [
|
|||
"torch/csrc/profiler/standalone/execution_graph_observer.cpp",
|
||||
"torch/csrc/profiler/standalone/itt_observer.cpp",
|
||||
"torch/csrc/profiler/standalone/nvtx_observer.cpp",
|
||||
"torch/csrc/profiler/standalone/profiler_legacy.cpp",
|
||||
"torch/csrc/profiler/stubs/base.cpp",
|
||||
"torch/csrc/monitor/counters.cpp",
|
||||
"torch/csrc/monitor/events.cpp",
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -1115,6 +1115,7 @@ def main():
|
|||
'include/torch/csrc/onnx/*.h',
|
||||
'include/torch/csrc/profiler/*.h',
|
||||
'include/torch/csrc/profiler/orchestration/*.h',
|
||||
'include/torch/csrc/profiler/standalone/*.h',
|
||||
'include/torch/csrc/profiler/stubs/*.h',
|
||||
'include/torch/csrc/utils/*.h',
|
||||
'include/torch/csrc/tensor/*.h',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <torch/csrc/autograd/profiler_kineto.h>
|
||||
#include <torch/csrc/autograd/profiler_legacy.h>
|
||||
#include <torch/csrc/profiler/orchestration/observer.h>
|
||||
#include <torch/csrc/profiler/standalone/profiler_legacy.h>
|
||||
|
||||
// There are some components which use these symbols. Until we migrate them
|
||||
// we have to mirror them in the old autograd namespace.
|
||||
namespace torch {
|
||||
namespace autograd {
|
||||
namespace profiler {
|
||||
using namespace ::torch::profiler_legacy;
|
||||
using ::torch::profiler::impl::ActivityType;
|
||||
using ::torch::profiler::impl::getProfilerConfig;
|
||||
using ::torch::profiler::impl::ProfilerConfig;
|
||||
using ::torch::profiler::impl::profilerEnabled;
|
||||
using ::torch::profiler::impl::ProfilerState;
|
||||
} // namespace profiler
|
||||
} // namespace autograd
|
||||
} // namespace torch
|
||||
|
|
|
|||
|
|
@ -58,9 +58,12 @@ inline int64_t getTimeUs() {
|
|||
}
|
||||
|
||||
using torch::profiler::impl::ActiveProfilerType;
|
||||
using torch::profiler::impl::ActivityType;
|
||||
using torch::profiler::impl::dtypesToStr;
|
||||
using torch::profiler::impl::EventType;
|
||||
using torch::profiler::impl::ExtraFields;
|
||||
using torch::profiler::impl::ProfilerConfig;
|
||||
using torch::profiler::impl::ProfilerState;
|
||||
using torch::profiler::impl::ProfilerStateBase;
|
||||
using torch::profiler::impl::PyExtraFieldsBase;
|
||||
using torch::profiler::impl::Result;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <torch/csrc/autograd/profiler_kineto.h>
|
||||
#include <torch/csrc/autograd/profiler.h>
|
||||
#include <torch/csrc/jit/mobile/module.h>
|
||||
|
||||
namespace torch {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include <torch/csrc/profiler/orchestration/observer.h>
|
||||
|
||||
// There are some components which use these symbols. Until we migrate them
|
||||
// we have to mirror them in the old autograd namespace.
|
||||
namespace torch {
|
||||
namespace autograd {
|
||||
namespace profiler {
|
||||
using torch::profiler::impl::ActivityType;
|
||||
using torch::profiler::impl::getProfilerConfig;
|
||||
using torch::profiler::impl::ProfilerConfig;
|
||||
using torch::profiler::impl::profilerEnabled;
|
||||
using torch::profiler::impl::ProfilerState;
|
||||
} // namespace profiler
|
||||
} // namespace autograd
|
||||
} // namespace torch
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class ExperimentalConfigWrapper {
|
|||
// do not trace CPU or GPU events.
|
||||
bool cupti_range_profiler = config_.profiler_metrics.size() > 0;
|
||||
if (cupti_range_profiler &&
|
||||
activities.count(torch::autograd::profiler::ActivityType::CPU)) {
|
||||
activities.count(torch::profiler::impl::ActivityType::CPU)) {
|
||||
LOG(WARNING)
|
||||
<< "Cannot run range profiler with CPU activities, please only"
|
||||
<< " use CUDA activity type";
|
||||
|
|
@ -211,10 +211,10 @@ void prepareTrace(
|
|||
}
|
||||
|
||||
std::set<libkineto::ActivityType> k_activities;
|
||||
if (activities.count(torch::autograd::profiler::ActivityType::CPU)) {
|
||||
if (activities.count(torch::profiler::impl::ActivityType::CPU)) {
|
||||
k_activities.insert(cpuTypes.begin(), cpuTypes.end());
|
||||
}
|
||||
if (activities.count(torch::autograd::profiler::ActivityType::CUDA)) {
|
||||
if (activities.count(torch::profiler::impl::ActivityType::CUDA)) {
|
||||
k_activities.insert(cudaTypes.begin(), cudaTypes.end());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ struct ActivityTraceWrapper {
|
|||
#endif
|
||||
};
|
||||
|
||||
using ActivitySet = std::set<torch::autograd::profiler::ActivityType>;
|
||||
using ActivitySet = std::set<torch::profiler::impl::ActivityType>;
|
||||
void prepareTrace(
|
||||
const bool cpuOnly,
|
||||
const ActivitySet& activities,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include <torch/csrc/autograd/profiler_legacy.h>
|
||||
#include <torch/csrc/profiler/standalone/profiler_legacy.h>
|
||||
|
||||
#include <torch/csrc/autograd/function.h>
|
||||
#include <torch/csrc/jit/frontend/tracer.h>
|
||||
|
|
@ -24,8 +24,7 @@
|
|||
#include <iostream>
|
||||
|
||||
namespace torch {
|
||||
namespace autograd {
|
||||
namespace profiler {
|
||||
namespace profiler_legacy {
|
||||
|
||||
// We decompose the profiler logic into the following components:
|
||||
//
|
||||
|
|
@ -679,6 +678,5 @@ void RecordProfile::processEvents(const std::vector<LegacyEvent*>& events) {
|
|||
writeProfilerEventsToStream(out_, events);
|
||||
}
|
||||
|
||||
} // namespace profiler
|
||||
} // namespace autograd
|
||||
} // namespace profiler_legacy
|
||||
} // namespace torch
|
||||
|
|
@ -16,11 +16,11 @@
|
|||
#include <torch/csrc/profiler/util.h>
|
||||
|
||||
namespace torch {
|
||||
namespace autograd {
|
||||
// namespace autograd {
|
||||
// struct Node;
|
||||
// } // namespace autograd
|
||||
|
||||
struct Node;
|
||||
|
||||
namespace profiler {
|
||||
namespace profiler_legacy {
|
||||
|
||||
enum class C10_API_ENUM EventKind : uint16_t {
|
||||
Mark,
|
||||
|
|
@ -412,6 +412,5 @@ struct TORCH_API TLSLegacyProfilerGuard {
|
|||
const c10::optional<ProfilerDisableOptions> profilerDisableOptions_;
|
||||
};
|
||||
|
||||
} // namespace profiler
|
||||
} // namespace autograd
|
||||
} // namespace profiler_legacy
|
||||
} // namespace torch
|
||||
Loading…
Reference in New Issue
Block a user