[DOC][Relay]: Add API docs for Relay.#1750
Conversation
tqchen
left a comment
There was a problem hiding this comment.
Some stylish issues on restructured text that we might need to fix
| @@ -0,0 +1,3 @@ | |||
| tvm.relay.op | |||
| ----------- | |||
There was a problem hiding this comment.
rst requires the underline to havethe same length as the title
| @@ -0,0 +1,161 @@ | |||
| ================== | |||
| Expressions | |||
| ================== | |||
There was a problem hiding this comment.
underline need to have the same length of the title.
First Level
=======
second level
--------------
third level
~~~~~~~
```
|
|
||
| .. code-block:: python | ||
| if (sum(equal(t, u))) { | ||
| jreturn x: |
|
@joshpoll @weberlo @MarisaKirisame @slyubomirsky could you guys take passes over the content. I am going to fix/clean up things which changed between last week and the final PR. |
|
@junrushao1994 @zhiics @yzhliu @ZihengJiang please review |
| Relay is differentiable programming language with support for | ||
| closures, control-flow, and recursion. It has an advanced | ||
| static type system specifically designed for programs written | ||
| by machine learning practioniers and researchers. |
|
|
||
| The shape may be any valid Relay shape as described in the below | ||
| section on shapes. | ||
|
|
|
|
||
| See :py:class:`~tvm.relay.type.IncompleteType` for its definition and documentation. | ||
|
|
||
|
|
| np.testing.assert_allclose(norm_out, xform_out) | ||
|
|
||
| # Use the TVM runtime. | ||
|
|
| a directed acyclic graph of primitive functions. | ||
|
|
||
| This may be a useful way to describe early ML models, but is | ||
| limited onceyou want to generalize to dynamic models. |
| for compiler optimizations is essential to the future of an | ||
| end-to-end deep learning compiler stack. | ||
|
|
||
| Relay's design was influenced by the authors previous experince |
| building advanced optimizing compilers for high level languages, | ||
| as well as experinces with the current TVM stack, and NNVM. | ||
|
|
||
| Concretely NNVM has played the role of this high level IR. |
|
|
||
| Concretely NNVM has played the role of this high level IR. | ||
|
|
||
| for NNVM which address design flaws of the computation graph IRs |
|
|
||
| *Note: this is not yet implemented.* | ||
|
|
||
| Finally we allo a definition be prefixed by metadata, which adds |
| parametrized by a data type, and shape. The data type must be a base | ||
| type as enforced by the kind checking rules described in TODO. | ||
|
|
||
| This restriction importantly means |
| Type Call | ||
| ~~~~~~~~~ | ||
|
|
||
| Apply a type relation to a set of input arguments, at the present momen the type |
| def __init__(self): | ||
| self.expr_map = {} | ||
|
|
||
| def expr_at(self,id: ir.LocalId) -> ir.Expr: |
| Relay which makes the important properties of computations involving tensors | ||
| explicit. | ||
|
|
||
| The result is a high-level IR for differentiable comptuation that can |
| We support a sequence of bindings followed by a body which | ||
| is the continutation after executing the sequence of bindings. | ||
|
|
||
| I believe this representation will be easier to manipulate then |
| is the continutation after executing the sequence of bindings. | ||
|
|
||
| I believe this representation will be easier to manipulate then | ||
| the mixed dataflow/control flow comptuation graphs. |
|
|
||
| See :py:class:`~tvm.relay.type.TypeParam` for its definition and documentation. | ||
|
|
||
| Type Constriant |
| from relay.operators.register import func_ty_to_placeholders, register_op | ||
| from relay.eval import defn_to_pyfunc | ||
| from relay.tyck import check_expr | ||
|
|
There was a problem hiding this comment.
I don't see relay.frontend, eval, tyck etc in the current repo. Are they going to be upstreamed soon?
There was a problem hiding this comment.
This code still needs to be updated from the old branch, but hope is to upstream these pieces in the next few days.
We have a few parallel efforts going on, some changes to the type checker for supporting VTA, the runtime compiler and evaluator, AD, debugging support, and work towards automatic quantization/8bit support. We will hopefully be releasing most of this in the next couple weeks.
3 of our team members have been away for the summer so parallelization should pick up soon.
| Kind | ||
| ~~~~ | ||
| The kind of a type parameter, represents a variable shape, | ||
| base type, type, or dimension. |
There was a problem hiding this comment.
what's the difference between base type and type? Actually, a little confused about this part. Can I understand Kind as type's type?
There was a problem hiding this comment.
Kind is basically a type's type.
base type is type that has a simple data layout, and thus can act as element of tensor efficiently.
|
|
||
| We support tuple constructors; the tuple node builds a finite (i.e statically known size) sequence of | ||
| heterogenous data. These tuples match closely to Python's and enable efficient projection of their m | ||
| embers due to their fixed length. |
| Function | ||
| ~~~~~~~~ | ||
|
|
||
| A function node represents a function, it contains a seqeuence of |
| which may reference the bound identifier. | ||
|
|
||
| We will first introduce a single binding with no type | ||
| anntoations: |
| This document contains the Python API to the Relay frontend, optimizer, and | ||
| compiler toolchain. | ||
|
|
||
| Relay is the second generation high level intermediate representation for the TVM |
There was a problem hiding this comment.
I think there should be hyphens here (compound adjectives):
"Relay is the second-generation high-level intermediate representation for the TVM compiler stack."
There was a problem hiding this comment.
there should also be a comma:
"Relay is the second-generation, high-level intermediate representation for the TVM compiler stack."
There was a problem hiding this comment.
"intermediate representation (IR)"
| Expressions | ||
| =========== | ||
|
|
||
| The Relay IR is a pure, expression oriented language, with a dataflow fragment |
There was a problem hiding this comment.
"Expression-oriented" should be hyphenated (compound adjective)
Additionally, I think in the next line it should say "Although Relay's representation is an abstract syntax tree" to clarify what exactly we mean by tree (i.e., not a tree in the sense of an acyclic graph)
| Introduction | ||
| ================== | ||
|
|
||
| Relay is differentiable programming language with support for |
There was a problem hiding this comment.
Missing article ("Relay is a differentiable programming language...")
| used to execute it uncessarily hampers many of the goals | ||
| of a framework. | ||
|
|
||
| We believe having a high level, an expressive language designed |
There was a problem hiding this comment.
"a high-level, expressive language..."
| This may be a useful way to describe early ML models, but is | ||
| limited onceyou want to generalize to dynamic models. | ||
|
|
||
| At the same time computation graphs have been over loaded |
There was a problem hiding this comment.
"At the same time, computation graphs have an overloaded purpose as both..."
| The conflation of the description of a computation, the | ||
| representation used for optimizing it, and the data structure | ||
| used to execute it uncessarily hampers many of the goals | ||
| of a framework. |
There was a problem hiding this comment.
This sentence is phrased rather confusingly. Perhaps the following might be clearer?
"Unnecessarily conflating the description, representation, and execution environment of a computation hampers many of the goals of a framework." (Also appears that this may need to be explained in greater detail.)
| class functions and closures, enabling the design of differentiable | ||
| arbitrary control flow constructs. Second we contribute a type system for | ||
| Relay which makes the important properties of computations involving tensors | ||
| explicit. |
There was a problem hiding this comment.
Miscellaneous small changes:
- "first-class" in this case should be hyphenated (compound adjective)
- There should be a comma in "the design of differentiable, arbitrary control flow constructs"
- There should be commas after "First" and "Second"
- It might be clearer in the last sentence if "makes the important properties of computations involving tensors
explicit" were "makes explicit the important properties of computations involving tensors"
|
|
||
| We believe Relay will enable researchers and industry to design a | ||
| new class of DL framework frontends, differentiable programming languages, | ||
| deep probablistic programming languages, thus accelerating the pace of |
There was a problem hiding this comment.
Should have "and" before "deep probabilistic programming languages"
| no sigil like LLVM's intrinsics. The distinction between global and local identifiers | ||
| makes certain kinds of transformation easier. For example inlining a global definition | ||
| requires no analysis, you can write a pass that just directly inlines the defintions. | ||
| It also ensures there are no spooky action at a distance, introducing a new identifier |
There was a problem hiding this comment.
Tense does not match: should be "ensures there are no spooky actions at a distance" or "ensures there is no spooky action at a distance." Additionally, the comma should be a semicolon.
| return type is omitted we will infer the return type based on the text of the | ||
| program. | ||
|
|
||
| Finally we can directly construct type polymorphic definitions by writing down |
There was a problem hiding this comment.
should be a hyphen in "type-polymorphic"
| to parameters in the machine learning. | ||
|
|
||
| When the type information is omitted we will attempt to infer a most general type | ||
| for the users. This property is known as generalization, for a definition without |
There was a problem hiding this comment.
I think it would be clearer if the comma after "generalization" were a colon (can misinterpret the "for" in the current phrasing)
|
|
||
| Static types are useful when performing compiler optimization because they | ||
| communicate properties about the data we manipulate, such as runtime shape, | ||
| data layout, storage without needing to run the program. |
There was a problem hiding this comment.
Missing conjunction before "storage"
| community, and can be viewed as a method for generalizing shape inference to | ||
| run over arbitrary user programs containing control flow and recursion. | ||
|
|
||
| Static types are useful when performing compiler optimization because they |
There was a problem hiding this comment.
"compiler optimizations" should be plural
| =========== | ||
|
|
||
| We have briefly introduced types while detailing the the expression language | ||
| of Relay, but have fully laid out the type system. |
There was a problem hiding this comment.
Sounds like it should say "but have not yet fully laid out the type system"
|
Hey everyone @tqchen @zhiics @slyubomirsky @junrushao1994 @zhiics @yzhliu @ZihengJiang sorry this took so long to update, things got busy working on the code. Split out just the API pieces and updated the pull request, if people could just give a quick review it would be great to merge soon. My final todo is fixing up cross-references to work more effectively. |
|
@jroesch LGTM. |
This PR comprises the work I did on docs for Relay in the initial PR #1672.
This adds a first pass at the language reference as well as extended documentation for the Python API docs, and some tutorials.
@slyubomirsky will follow up with the language reference pieces of the documentation, this will just contain the API docs.