-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[REFACTOR] Streamline Function Attr interface. #5045
Conversation
NOTE: I have not removed the UseDefaultCompiler member function, however, we should remove that in a followup PR by simply setting the default compiler to None and we could use StringImm should be changed to String once #4628 is merged |
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. Only a few nitpicks.
class DictAttrs : public Attrs { | ||
public: | ||
/*! | ||
* \brief Consruct a Attrs backed by DictAttrsNode. |
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/Consruct/Construct
include/tvm/ir/function.h
Outdated
* \brief Base node of all functions. | ||
* | ||
* We support several variants of functions throughout the stack. | ||
* All of the functions shares the same type system(via checked_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.
s/shares/share
include/tvm/ir/function.h
Outdated
* \code | ||
* | ||
* void HasNonzeroAttrExample(const BaseFunc& f) { | ||
* if (f->HasNonzeroAttr(attr::Inline)) { |
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.
kInline
include/tvm/relay/function.h
Outdated
* \returns The new function with updated attributes. | ||
* | ||
* \note This function performs copy on write optimization for func. | ||
* If we move an uniquely referenced func into WithAttr, |
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/an/a
thanks @zhiics please take another look |
include/tvm/ir/function.h
Outdated
* \file tvm/ir/expr.h | ||
* \brief Base expr nodes in 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.
Update file & brief here
src/ir/function.cc
Outdated
*/ | ||
|
||
/*! | ||
* \file src/tvm/ir/function.cc |
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.
src/ir/function.cc
src/relay/ir/function.cc
Outdated
*/ | ||
|
||
/*! | ||
* \file src/tvm/relay/ir/function.cc |
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.
same as above
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.
@tqchen LGTM, please fix @siju-samuel's comments.
There has been quite a few recent changes that depends heavily on the function attr interface. This PR streamlines that interface by introducing two APIs that covers most of the usages. - GetAttr which gets a typed object for a given key - HasNonzeroAttr is a quick helper that calls GetAttr to quickly check an attribute - WithAttr that creates a new function object with the given attr - The API comes with copy on write optimization to avoid multiple copies - We deliberately pick the prefix With(instead of Set) to indicate this function does not mutate the original input. On the python side: - We allow read access via func.attrs (which is a DictAttr) - func.with_attrs to create a new instance with updated attrs. We also get rid of the small wrapper functions and make sure the API centered around the GetAttr and HasNonzeroAttr interface. This PR also changes the function construction to follow the new convention.
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
Thanks @tqchen, @ZihengJiang, @siju-samuel |
* [REFACTOR] Streamline Function Attr interface. There has been quite a few recent changes that depends heavily on the function attr interface. This PR streamlines that interface by introducing two APIs that covers most of the usages. - GetAttr which gets a typed object for a given key - HasNonzeroAttr is a quick helper that calls GetAttr to quickly check an attribute - WithAttr that creates a new function object with the given attr - The API comes with copy on write optimization to avoid multiple copies - We deliberately pick the prefix With(instead of Set) to indicate this function does not mutate the original input. On the python side: - We allow read access via func.attrs (which is a DictAttr) - func.with_attrs to create a new instance with updated attrs. We also get rid of the small wrapper functions and make sure the API centered around the GetAttr and HasNonzeroAttr interface. This PR also changes the function construction to follow the new convention. * Address review comments * Address review comments * Fix doxygen path
* [REFACTOR] Streamline Function Attr interface. There has been quite a few recent changes that depends heavily on the function attr interface. This PR streamlines that interface by introducing two APIs that covers most of the usages. - GetAttr which gets a typed object for a given key - HasNonzeroAttr is a quick helper that calls GetAttr to quickly check an attribute - WithAttr that creates a new function object with the given attr - The API comes with copy on write optimization to avoid multiple copies - We deliberately pick the prefix With(instead of Set) to indicate this function does not mutate the original input. On the python side: - We allow read access via func.attrs (which is a DictAttr) - func.with_attrs to create a new instance with updated attrs. We also get rid of the small wrapper functions and make sure the API centered around the GetAttr and HasNonzeroAttr interface. This PR also changes the function construction to follow the new convention. * Address review comments * Address review comments * Fix doxygen path
There has been quite a few recent changes that depends heavily on
the function attr interface. This PR streamlines that interface by introducing
two APIs that covers most of the usages.
Thanks to @jroesch for discussing the API naming convention.
function does not mutate the original input.
On the python side:
e.g.
func.attrs["__param__"]
We also get rid of the small wrapper functions and make sure the API centered around
the GetAttr and HasNonzeroAttr interface.
This PR also changes the function construction to follow the new convention.
cc @jroesch @zhiics @mbaret