Skip to content

Conversation

@jroesch
Copy link
Member

@jroesch jroesch commented Sep 21, 2018

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.

@jroesch jroesch changed the title [DOC][Relay]: Add initial language reference and API docs for Relay. [DOC][WIP][Relay]: Add initial language reference and API docs for Relay. Sep 21, 2018
Copy link
Member

@tqchen tqchen left a 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

@@ -0,0 +1,3 @@
tvm.relay.op
-----------
Copy link
Member

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

@@ -0,0 +1,161 @@
==================
Expressions
==================
Copy link
Member

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
~~~~~~~
```


.. code-block:: python
if (sum(equal(t, u))) {
jreturn x:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jreturn -> return

@jroesch
Copy link
Member Author

jroesch commented Sep 21, 2018

@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.

@tqchen
Copy link
Member

tqchen commented Sep 21, 2018

@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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra whitespace


The shape may be any valid Relay shape as described in the below
section on shapes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line


See :py:class:`~tvm.relay.type.IncompleteType` for its definition and documentation.


Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/onceyou/once you

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/authors/authors' ?

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concretely? or Currently?


Concretely NNVM has played the role of this high level IR.

for NNVM which address design flaws of the computation graph IRs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/for/For


*Note: this is not yet implemented.*

Finally we allo a definition be prefixed by metadata, which adds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allo? You meant allow?

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete sentence?

Type Call
~~~~~~~~~

Apply a type relation to a set of input arguments, at the present momen the type
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space after self,

Relay which makes the important properties of computations involving tensors
explicit.

The result is a high-level IR for differentiable comptuation that can
Copy link
Member

@masahi masahi Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computation

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
Copy link
Member

@masahi masahi Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We believe
then - > than

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computation


See :py:class:`~tvm.relay.type.TypeParam` for its definition and documentation.

Type Constriant
Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

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.

Kind
~~~~
The kind of a type parameter, represents a variable shape,
base type, type, or dimension.
Copy link
Contributor

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?

Copy link
Contributor

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.


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m embers -> members

Function
~~~~~~~~

A function node represents a function, it contains a seqeuence of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequence

which may reference the bound identifier.

We will first introduce a single binding with no type
anntoations:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annotations

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
Copy link
Contributor

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."

Copy link
Contributor

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."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"intermediate representation (IR)"

Expressions
===========

The Relay IR is a pure, expression oriented language, with a dataflow fragment
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comma after language.

Introduction
==================

Relay is differentiable programming language with support for
Copy link
Contributor

@slyubomirsky slyubomirsky Sep 27, 2018

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...")

used to execute it uncessarily hampers many of the goals
of a framework.

We believe having a high level, an expressive language designed
Copy link
Contributor

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..."

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
Copy link
Contributor

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..."

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.
Copy link
Contributor

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.)

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.
Copy link
Contributor

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"


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
Copy link
Contributor

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"

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
Copy link
Contributor

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.

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
Copy link
Contributor

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"

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
Copy link
Contributor

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)


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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

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

===========

We have briefly introduced types while detailing the the expression language
of Relay, but have fully laid out the type system.
Copy link
Contributor

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"

@jroesch jroesch changed the title [DOC][WIP][Relay]: Add initial language reference and API docs for Relay. [DOC][Relay]: Add initial language reference and API docs for Relay. Dec 1, 2018
@jroesch jroesch changed the title [DOC][Relay]: Add initial language reference and API docs for Relay. [DOC][Relay]: Add API docs for Relay. Dec 1, 2018
@jroesch
Copy link
Member Author

jroesch commented Dec 1, 2018

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.

@zhiics
Copy link
Member

zhiics commented Dec 1, 2018

@jroesch LGTM.

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tqchen tqchen merged commit 20afa0a into apache:master Dec 2, 2018
@tqchen tqchen added status: accepted and removed status: WIP status: need update need update based on feedbacks labels Dec 2, 2018
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
@jroesch jroesch deleted the relay-docs branch February 4, 2021 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants