pytorch
183b04da - [pytorch] remove tracing logic from gen_variable_factories.py (#39514)

Commit
4 years ago
[pytorch] remove tracing logic from gen_variable_factories.py (#39514) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/39514 For methods in `variable_factories.h`, we set `AutoNonVariableTypeMode` guard before dispatching, which also disables tracing as side effort, so we need replicate the tracing logic. Now as we have created separate TraceType, we should be able to remove tracing from `variable_factories.h`. Example of old code: ``` inline at::Tensor arange(at::Scalar start, at::Scalar end, at::Scalar step, const at::TensorOptions & options = {}) { #if !defined(PYTORCH_DISABLE_TRACING) torch::jit::Node* node = nullptr; std::shared_ptr<jit::tracer::TracingState> tracer_state; if (jit::tracer::isTracing()) { tracer_state = jit::tracer::getTracingState(); at::Symbol op_name; op_name = jit::Symbol::fromQualString("aten::arange"); node = tracer_state->graph->create(op_name, /*num_outputs=*/0); jit::tracer::recordSourceLocation(node); jit::tracer::addInputs(node, "start", start); jit::tracer::addInputs(node, "end", end); jit::tracer::addInputs(node, "step", step); jit::tracer::addInputs(node, "options", options); tracer_state->graph->insertNode(node); jit::tracer::setTracingState(nullptr); } #endif at::Tensor tensor = ([&]() { at::AutoNonVariableTypeMode non_var_type_mode(true); return at::arange(start, end, step, at::TensorOptions(options)); })(); at::Tensor result = autograd::make_variable(std::move(tensor), /*requires_grad=*/options.requires_grad()); #if !defined(PYTORCH_DISABLE_TRACING) if (tracer_state) { jit::tracer::setTracingState(std::move(tracer_state)); jit::tracer::addOutput(node, result); } #endif return result; } ``` Example of new code: ``` inline at::Tensor arange(at::Scalar start, at::Scalar end, at::Scalar step, const at::TensorOptions & options = {}) { at::Tensor tensor = ([&]() { at::AutoNonVariableTypeMode non_var_type_mode(true); return at::arange(start, end, step, at::TensorOptions(options)); })(); at::Tensor result = autograd::make_variable(std::move(tensor), /*requires_grad=*/options.requires_grad()); return result; } ``` ghstack-source-id: 105407617 Test Plan: CI Differential Revision: D21880936 fbshipit-source-id: 19a4330eed5bc1ee956ad1c638a9658e7a1ce283
Author
Parents
Loading