-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
support custom vjp trait #57106
support custom vjp trait #57106
Conversation
… custom_vjp_trait
… custom_vjp_trait
你的PR提交成功,感谢你对开源项目的贡献! |
PR描述最好可以贴一个生成出来的例子,比如gelu |
|
||
namespace paddle { | ||
namespace dialect { | ||
class CustomVjpTrait : public ir::OpTraitBase<CustomVjpTrait> { |
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.
explain custom vjp
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.
done, thx
done,thx |
… custom_vjp_trait
… custom_vjp_trait
… custom_vjp_trait
return newir_program | ||
|
||
|
||
class TestCustomVjpTrait(unittest.TestCase): |
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 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.
okk,下个PR加入
# import from paddle/fluid/primitive/code_gen/gen.py | ||
sys.path.append( | ||
str(pathlib.Path(__file__).resolve().parents[3] / 'primitive/codegen') | ||
) |
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 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.
当前缺少__init__.py,使用相对路径的话需要新增才可以;
python代码规范里面也提到:
Absolute imports are recommended, as they are usually more readable and tend to be better behaved
(or at least give better error messages) if the import system is incorrectly configured .
所以使用了绝对路径。
… opt_custom_vjp_trait
… opt_custom_vjp_trait
1925e3f
* test prim custom vjp in New IR * add a new CustomVjpTrait to represent whether an op has custom vjp * add has_custom_vjp_op_list to represent ops that have custom vjp * parse has_custom_vjp_op_list and autogen CustomVjpTrait for those ops * add pybind to support checking whether an op has custom vjp in python level * add test * add test for add op custom vjp * add pybind to support checking whether an op has custom vjp in python level * fix bugs * polish code * fix bugs * generate custom_vjp trait based on op list from gen.py * delete has_custom_vjp_op_list * fix bugs * use currently defined list CUSTOM_VJP and VJP_COMPS rather than define new list * fix ctest * fix bugs * divide vjp into prim_vjp and custom vjp * add code comments * add code comments * polish codes * polish code comments * polish codes * fix bugs * add code comments * fix bugs * add custom vjp trait support in new folder * fix bugs * add another example for unit testing * fix bugs --------- Co-authored-by: cyber-pioneer <chenzhuo@tju.edu.cn>
PR types
New features
PR changes
Others
Description
add custom_vjp trait to support checking whether an op has custom vjp
For example, gelu op has custom vjp rules and is added into custom_vjp list, as follows,
Therefore, for gelu op, CustomVjpTrait is automatically added into it, as follows,
Finally, when calling has_custom_vjp(gelu_op), it will return True, representing that the custom vjp rules for gelu are currently defined.
Pcard-66975