-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[DOC][Relay]: Add API docs for Relay. #1750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tqchen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some stylish issues on restructured text that we might need to fix
docs/api/python/relay/op.rst
Outdated
| @@ -0,0 +1,3 @@ | |||
| tvm.relay.op | |||
| ----------- | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rst requires the underline to havethe same length as the title
docs/langref/relay/expressions.rst
Outdated
| @@ -0,0 +1,161 @@ | |||
| ================== | |||
| Expressions | |||
| ================== | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underline need to have the same length of the title.
First Level
=======
second level
--------------
third level
~~~~~~~
```
docs/langref/relay/expressions.rst
Outdated
|
|
||
| .. code-block:: python | ||
| if (sum(equal(t, u))) { | ||
| jreturn x: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jreturn -> return
|
@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 |
docs/langref/relay/intro.rst
Outdated
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra whitespace
docs/langref/relay/type_system.rst
Outdated
|
|
||
| The shape may be any valid Relay shape as described in the below | ||
| section on shapes. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
docs/langref/relay/type_system.rst
Outdated
|
|
||
| See :py:class:`~tvm.relay.type.IncompleteType` for its definition and documentation. | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
| np.testing.assert_allclose(norm_out, xform_out) | ||
|
|
||
| # Use the TVM runtime. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
docs/langref/relay/intro.rst
Outdated
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/onceyou/once you
docs/langref/relay/intro.rst
Outdated
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/authors/authors' ?
docs/langref/relay/intro.rst
Outdated
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concretely? or Currently?
docs/langref/relay/intro.rst
Outdated
|
|
||
| Concretely NNVM has played the role of this high level IR. | ||
|
|
||
| for NNVM which address design flaws of the computation graph IRs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/for/For
docs/langref/relay/intro.rst
Outdated
|
|
||
| *Note: this is not yet implemented.* | ||
|
|
||
| Finally we allo a definition be prefixed by metadata, which adds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allo? You meant allow?
docs/langref/relay/type_system.rst
Outdated
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete sentence?
docs/langref/relay/type_system.rst
Outdated
| Type Call | ||
| ~~~~~~~~~ | ||
|
|
||
| Apply a type relation to a set of input arguments, at the present momen the type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
momen?
| def __init__(self): | ||
| self.expr_map = {} | ||
|
|
||
| def expr_at(self,id: ir.LocalId) -> ir.Expr: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space after self,
docs/langref/relay/intro.rst
Outdated
| Relay which makes the important properties of computations involving tensors | ||
| explicit. | ||
|
|
||
| The result is a high-level IR for differentiable comptuation that can |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computation
docs/langref/relay/expressions.rst
Outdated
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We believe
then - > than
docs/langref/relay/expressions.rst
Outdated
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computation
docs/langref/relay/type_system.rst
Outdated
|
|
||
| See :py:class:`~tvm.relay.type.TypeParam` for its definition and documentation. | ||
|
|
||
| Type Constriant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constraint
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
docs/langref/relay/type_system.rst
Outdated
| Kind | ||
| ~~~~ | ||
| The kind of a type parameter, represents a variable shape, | ||
| base type, type, or dimension. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
docs/langref/relay/expressions.rst
Outdated
|
|
||
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m embers -> members
docs/langref/relay/expressions.rst
Outdated
| Function | ||
| ~~~~~~~~ | ||
|
|
||
| A function node represents a function, it contains a seqeuence of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sequence
docs/langref/relay/expressions.rst
Outdated
| which may reference the bound identifier. | ||
|
|
||
| We will first introduce a single binding with no type | ||
| anntoations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annotations
docs/api/python/relay/index.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"intermediate representation (IR)"
docs/langref/relay/expressions.rst
Outdated
| Expressions | ||
| =========== | ||
|
|
||
| The Relay IR is a pure, expression oriented language, with a dataflow fragment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No comma after language.
docs/langref/relay/intro.rst
Outdated
| Introduction | ||
| ================== | ||
|
|
||
| Relay is differentiable programming language with support for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing article ("Relay is a differentiable programming language...")
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a high-level, expressive language..."
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"At the same time, computation graphs have an overloaded purpose as both..."
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.)
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"
docs/langref/relay/intro.rst
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have "and" before "deep probabilistic programming languages"
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be a hyphen in "type-polymorphic"
docs/langref/relay/intro.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be clearer if the comma after "generalization" were a colon (can misinterpret the "for" in the current phrasing)
docs/langref/relay/type_system.rst
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing conjunction before "storage"
docs/langref/relay/type_system.rst
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"compiler optimizations" should be plural
docs/langref/relay/type_system.rst
Outdated
| =========== | ||
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
junrushao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.