-
Notifications
You must be signed in to change notification settings - Fork 75.2k
[Graph C API] Enable plugin optimizers and configs. #47635
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
[Graph C API] Enable plugin optimizers and configs. #47635
Conversation
|
Hi @penpornk @ezhulenev, please help to have a review. Thanks very much! |
|
@penpornk This PR is the 3rd Graph C API PR. Without this PR, users won't be able to use graph plugin. |
| return mem_opt_type != RewriterConfig::NO_MEM_OPT; | ||
| } | ||
|
|
||
| Status GetGraphDevice(const GraphDef& g_def, std::set<std::string>& devices) { |
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.
Output parameters must be taken by pointer.
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
| } | ||
|
|
||
| Status GetGraphDevice(const GraphDef& g_def, std::set<std::string>& devices) { | ||
| for (auto node : g_def.node()) { |
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 auto will do a copy here, you'll need auto&.
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
| optimizers->push_back(MakeUnique<ModelPruner>()); | ||
| } | ||
| if (cfg_.implementation_selector() != RewriterConfig::OFF) { | ||
| if (cfg_.implementation_selector() != RewriterConfig::OFF && |
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.
Maybe move this repeated pattern to macro?
cfg_.implementation_selector() != RewriterConfig::OFF &&
plugin_configs.toggle_config["implementation_selector"]
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.
The pattern is not exactly the same for different optimizers, so I use 6 macros here.
#define USER_IS_ON(CFG) cfg_.CFG() == RewriterConfig::ON
#define USER_NOT_OFF(CFG) cfg_.CFG() != RewriterConfig::OFF
#define PLUGIN_IS_ON(CFG) plugin_configs.toggle_config[#CFG] == RewriterConfig::ON
#define PLUGIN_NOT_OFF(CFG) plugin_configs.toggle_config[#CFG] != RewriterConfig::OFF
#define BOTH_IS_ON(CFG) USER_IS_ON(CFG) && PLUGIN_IS_ON(CFG)
#define BOTH_NOT_OFF(CFG) USER_NOT_OFF(CFG) && PLUGIN_NOT_OFF(CFG)| } | ||
|
|
||
| Status MetaOptimizer::InitializePluginGraphOptimizers( | ||
| std::vector<std::unique_ptr<GraphOptimizer>>* optimizers, |
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.
Output parameters should be at the end.
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.
OK. Done for all functions.
|
@ezhulenev Thanks for your review! I have addressed all your comments. |
|
@ShengYang1 Can you please resolve conflicts? Thanks! |
I have already rebased, please review. Thanks! |
|
@penpornk Already rebased. Meanwhile I have slightly changed the logic in |
penpornk
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.
Meanwhile I have slightly changed the logic in
RegisterPluggableDevicePlugin. In the previous design, it will directly return error ifSE_InitPluginis not found. However, plugin with graph only should also be allowed, so I changed it to "return error if neither device nor graph is found". Suggestions are welcome. Thanks.
Thank you very much! I was about to ask for that too, because the use case with just the graph plugin is also valid in the original RFC (2nd scenario).
I marked some trivial typos. No need to fix them. I will fix them internally.
The main PluggableDevice implementation PR (#45784) missed last night's nightly test, so we'll know tomorrow whether it will get reverted. I will merge this PR after I'm sure #45784 won't get reverted.
…tensorflow#47635.) Context: [1] Grappler C API RFC https://github.com/tensorflow/community/blob/master/rfcs/20201027-modular-tensorflow-graph-c-api.md [2] Pluggable Grappler pass registration PR tensorflow#47635. PiperOrigin-RevId: 363788388 Change-Id: I8463382748c2d7c211ee80e0f9907276f6a20ad2
…#47635.) Context: [1] Grappler C API RFC https://github.com/tensorflow/community/blob/master/rfcs/20201027-modular-tensorflow-graph-c-api.md [2] Pluggable Grappler pass registration PR #47635. PiperOrigin-RevId: 363803765 Change-Id: I14b46889fc87bf7d64215dd54788398cae5a846f
|
So I have good news and bad news. Good news: This PR is merged, and the main PluggableDevice PR is now confirmed safe (based on last night's tests)! 🎉 Bad news: There has been some issues adding the new |
|
@penpornk Thanks for your effort to get this PR merged. It's really good news🎉. |
…d to complete pluggable Grappler registration PR #47635. Context: [1] Grappler C API RFC https://github.com/tensorflow/community/blob/master/rfcs/20201027-modular-tensorflow-graph-c-api.md [2] Pluggable Grappler pass registration PR #47635. PiperOrigin-RevId: 364412108 Change-Id: I0152d83de1b7ccc9da751080551f992d1ee46349
…Config and Python interface. This is the rest of the changes from PR #47635 that was hold off because there was a problem adding a new parameter (`use_plugin_optimizers`) to `RewriterConfig`. `use_plugin_optimizers` is now in `RewriteConfig` (197817f) PiperOrigin-RevId: 364617915 Change-Id: I7a1b1bb7167b4628a16ebcc551d4839aa559fda0
This is the 3rd PR(and the last one) of Graph C API, following RFC Modular TensorFlow Graph C API.
This PR is mainly to add plugin optimizer and config in meta_optimizer, which includes:
InitGraphPlugininRegisterPluggableDevicePlugin.