Skip to content

Conversation

@Solaryee
Copy link
Contributor

@Solaryee Solaryee commented Mar 8, 2021

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:

  1. Run plugin optimizer in meta_optimizer.
  2. Change config if plugin optimizer is enabled, otherwise leave it as default. Print it when plugin config is conflicit with user config.
  3. Call InitGraphPlugin in RegisterPluggableDevicePlugin.

@google-ml-butler google-ml-butler bot added the size:L CL Change Size: Large label Mar 8, 2021
@google-cla google-cla bot added the cla: yes label Mar 8, 2021
@Solaryee
Copy link
Contributor Author

Solaryee commented Mar 8, 2021

Hi @penpornk @ezhulenev, please help to have a review. Thanks very much!

@gbaned gbaned self-assigned this Mar 8, 2021
@Jianhui-Li
Copy link

@penpornk This PR is the 3rd Graph C API PR. Without this PR, users won't be able to use graph plugin.

@penpornk penpornk requested review from ezhulenev and penpornk March 11, 2021 01:06
return mem_opt_type != RewriterConfig::NO_MEM_OPT;
}

Status GetGraphDevice(const GraphDef& g_def, std::set<std::string>& devices) {
Copy link
Contributor

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.

Copy link
Contributor Author

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()) {
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 auto will do a copy here, you'll need auto&.

Copy link
Contributor Author

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

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

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.

@Solaryee
Copy link
Contributor Author

@ezhulenev Thanks for your review! I have addressed all your comments.

@gbaned gbaned requested a review from ezhulenev March 12, 2021 14:38
@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 12, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 12, 2021
@penpornk penpornk added the kokoro:force-run Tests on submitted change label Mar 12, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 12, 2021
@gbaned gbaned added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Mar 16, 2021
@gbaned
Copy link
Contributor

gbaned commented Mar 17, 2021

@ShengYang1 Can you please resolve conflicts? Thanks!

@gbaned gbaned added stat:awaiting response Status - Awaiting response from author and removed ready to pull PR ready for merge process labels Mar 17, 2021
@Solaryee
Copy link
Contributor Author

@ShengYang1 Can you please resolve conflicts? Thanks!

I have already rebased, please review. Thanks!

@penpornk
Copy link
Member

#45784 just got merged. Could you please resolve conflicts again? Thank you!

@Solaryee
Copy link
Contributor Author

@penpornk Already rebased.

Meanwhile I have slightly changed the logic in RegisterPluggableDevicePlugin. In the previous design, it will directly return error if SE_InitPlugin is 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.

Copy link
Member

@penpornk penpornk left a 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 if SE_InitPlugin is 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.

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Mar 18, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Mar 18, 2021
ArmageddonKnight pushed a commit to UofT-EcoSystem/tensorflow that referenced this pull request Mar 19, 2021
…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
copybara-service bot pushed a commit that referenced this pull request Mar 19, 2021
…#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
@copybara-service copybara-service bot merged commit 1342121 into tensorflow:master Mar 19, 2021
@penpornk
Copy link
Member

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 RewriterConfig option (use_plugin_optimizers). I added it separately here but the change got reverted. So I made this PR use kUsePluginOptimizers = RewriterConfig::ON; in metaoptimizer.cc and removed the changes in eager/context.py for now. I will change them back once I can get the RewriterConfig change back in.

@Solaryee
Copy link
Contributor Author

@penpornk Thanks for your effort to get this PR merged. It's really good news🎉.

@gbaned gbaned removed the stat:awaiting response Status - Awaiting response from author label Mar 21, 2021
copybara-service bot pushed a commit that referenced this pull request Mar 22, 2021
…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
copybara-service bot pushed a commit that referenced this pull request Mar 23, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes ready to pull PR ready for merge process size:L CL Change Size: Large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants