pytorch/torch/csrc/jit
Gregory Chanan 705d80b51e Remove some Type.tensor usages and remove native_tensor without size. (#12355)
Summary:
This is to move us along the path to removing Type from the public API.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12355

Reviewed By: ezyang

Differential Revision: D10212616

Pulled By: gchanan

fbshipit-source-id: c9cd128d1111ab219cb0b2f3bf5b632502ab97c0
2018-10-05 11:12:07 -07:00
..
batched Remove caffe2::Tensor::capacity_nbytes, at::Tensor::to##name##Data, (#11876) 2018-09-24 10:40:10 -07:00
fusers move flags to c10 (#12144) 2018-10-04 02:09:56 -07:00
passes Pretty printer improvements (#12179) 2018-10-04 15:14:51 -07:00
script Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
argument_spec.h Introduce type variables to implement generic list operators (#12040) 2018-09-26 17:02:51 -07:00
assertions.h Update include paths for ATen/core (#10130) 2018-08-03 11:57:02 -07:00
attributes.h Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
autodiff.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
autodiff.h Implement requires_grad propagation in the JIT (#11586) 2018-09-13 19:25:26 -07:00
catch_utils.hpp Use CATCH prefix to avoid name conflicts with Caffe2. 2018-09-18 08:12:45 -07:00
code_template.h
constants.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
constants.h Fix a bug in constant prop (#10923) 2018-08-27 18:10:17 -07:00
custom_operator.h Don't flatten output lists in the JIT IR (#10949) 2018-08-30 19:54:39 -07:00
export.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
export.h Use streams in JIT serialization, allow JIT serialization to/from buffer (#11932) 2018-09-28 07:54:27 -07:00
function_schema.h mutable lists (#10700) 2018-09-27 19:25:13 -07:00
generic_if.h Split Type into its own header file. 2017-09-20 12:24:27 -04:00
graph_executor.cpp mutable lists (#10700) 2018-09-27 19:25:13 -07:00
graph_executor.h add autodiff expressions for common operations (#11832) 2018-09-26 08:10:04 -07:00
graph_node_list.h Pool constants during script compilation. (#10231) 2018-09-01 22:40:50 -07:00
import.cpp Remove some Type.tensor usages and remove native_tensor without size. (#12355) 2018-10-05 11:12:07 -07:00
import.h Use streams in JIT serialization, allow JIT serialization to/from buffer (#11932) 2018-09-28 07:54:27 -07:00
init.cpp Use streams in JIT serialization, allow JIT serialization to/from buffer (#11932) 2018-09-28 07:54:27 -07:00
init.h Move JIT passes to a separate directory 2017-09-19 10:53:32 -04:00
interned_strings_class.h Move interned_strings and get build working (#12039) 2018-10-05 00:41:18 -07:00
interned_strings.h Move interned_strings and get build working (#12039) 2018-10-05 00:41:18 -07:00
interpreter.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
interpreter.h Replace 'struct Tensor' with 'class Tensor'. (#12034) 2018-09-25 09:54:35 -07:00
ir.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
ir.h Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
ivalue.h Move IValue to ATen/core (#11610) 2018-09-17 18:25:50 -07:00
named_value.h Schema-based creation of graph nodes (#10198) 2018-08-14 10:25:38 -07:00
operator.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
operator.h Sanity checks for tracing (#10841) 2018-08-28 20:25:26 -07:00
pybind_utils.h Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
pybind.h Improve shape analysis to cover all most commonly used ops (#11358) 2018-09-11 06:02:39 -07:00
python_arg_flatten.cpp Replace std::size_t with size_t (#8093) 2018-06-04 11:10:44 -04:00
python_arg_flatten.h Rename at::getType to at::getNonVariableType (#11096) 2018-08-31 09:10:49 -07:00
python_interpreter.cpp Properly catch errors in PythonOps (#12243) 2018-10-03 17:25:03 -07:00
python_ir.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
python_ir.h Move JIT passes to a separate directory 2017-09-19 10:53:32 -04:00
python_tracer.cpp Avoid using PyThreadState.frame as it is not a public member. (#11855) 2018-09-19 20:58:37 -07:00
python_tracer.h Allow tracing functions that take tuples of tensors as inputs (#10637) 2018-08-22 15:37:10 -07:00
README.md Remove legacy code from the JIT (#9323) 2018-07-11 10:25:38 -07:00
register_prim_ops.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
register_special_ops.cpp Fix split_size test failures (#11051) 2018-09-07 15:39:24 -07:00
resource_guard.h
serialization.h Use streams in JIT serialization, allow JIT serialization to/from buffer (#11932) 2018-09-28 07:54:27 -07:00
source_location.h Bag of clang tidy fixes for torch/csrc/ and torch/csrc/autograd (#11050) 2018-09-05 19:55:50 -07:00
source_range.h Move IValue to ATen/core (#11610) 2018-09-17 18:25:50 -07:00
stack.h Minor JIT improvements (#11654) 2018-09-21 14:19:54 -07:00
symbolic_variable.h add autodiff expressions for common operations (#11832) 2018-09-26 08:10:04 -07:00
test_jit.cpp Remove some Type.tensor usages and remove native_tensor without size. (#12355) 2018-10-05 11:12:07 -07:00
tracer.cpp Pop stashed IntList in resize_, warn about its usage when tracing. 2018-09-21 08:40:20 -07:00
tracer.h Pop stashed IntList in resize_, warn about its usage when tracing. 2018-09-21 08:40:20 -07:00
tracing_state.h Pop stashed IntList in resize_, warn about its usage when tracing. 2018-09-21 08:40:20 -07:00
type.cpp Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
type.h Add bool type to IR (#11834) 2018-10-03 12:40:03 -07:00
variable_tensor_list.h Match parameter names and = default (#9737) 2018-07-30 14:10:00 -07:00

jit

The jit directory contains infrastructure for a just-in-time compiler for PyTorch and associated 'script' subset of python it can execute directly.

The JIT compiler has several phases.

  1. Parsing - An AST (defined in tree_views.h) is generated either by parsing a string of python-like code (jit/script/parser.h) or by translation from the Python AST (jit/frontend.py). This phase only checks for syntactic correctness and for use of the syntactic subset of python that the script supports.

  2. Semantic Checking/Specialization - We lower the AST into an IR Graph object. In this phase we check that variables are in scope and resolve any free variables to python objects. When we find free variables that are python objects, or references to non-first-class values such as modules, we temporarily represent them as SugaredValue objects. This phase then de-sugars these values by e.g. inserting a PythonOp into the graph to call a python function.

  3. Optimizations - A GraphExecutor works on an initial Graph object, performing optimizations, possibly differentiating it, and possibly specializing it to a particular size.

  4. Translation to Instructions - to execute a graph, it is lowered by the interpreter into a linear list of Instruction objects.

  5. Execution - the interpreter reads the instruction stream, executing ATen operations and any generated code fragments.

Well-known functions

Ordinarily, when defining a compiler you want the set of functions to be user extensible; e.g., a user can add to the set of defined functions by defining an appropriate autograd Function. However, there are some functions where we want to make assumptions about their semantics, because we are going to write optimizations over them or insert them into the program. Such functions are "well-known" functions, because the JIT compiler knows about them, and a user implementation must abide by the contract (sometimes implicitly) specified by the compiler.

A well-known function is usually implemented in several parts:

  • First, we pre-intern the string (interned_strings.h) that identifies the node. This allows us to more conveniently refer to these operators without having to first do a lookup through the intern table.

  • If we generate this operator during optimizations, we will often have a helper function in Graph (ir.h) for creating the operator. This is the easiest way to find out, in code, what attributes we assume for an operator.

  • There is a runtime interpretation of the operator in torch/csrc/autograd/functions/interpreter.cpp, which specifies how we actually interpret programs that contain such an operator.

So, whence the specifications! For the most part, we are following the ONNX operator specification to determine the semantics of our operators. However, there are a few other well-known functions which are specific to PyTorch.

  • FusionGroup

    A fusion group takes some number of input tensors, applies a graph Subgraph to them, producing the returned tensors of the subgraph. Operationally, operators inside a FusionGroup are fused into a single kernel, so that their intermediate results are never materialized. Not all operators support fusion:

    • attribute:
      Subgraph
      The graph of fused operators. Its inputs and outputs should match the number of inputs and outputs to the FusionGroup operator.
    • input: 1 - ∞ (same as inputs of Subgraph)
    • output: 1 - ∞ (same as outputs of Subgraph)