This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix optimizer bug in CPP-Package #9809
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8db9ff2
opt register only once
5ecb29f
lint pass
6491635
opt register only once
a7b2dba
add test_optimizer.cpp
0f6b6b3
Merge branch 'fix_opt' of https://github.com/chsin/incubator-mxnet in…
c5699e1
fix warning
7d00399
typo
chsin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| #include "mxnet-cpp/MxNetCpp.h" | ||
|
|
||
| using namespace std; | ||
| using namespace mxnet::cpp; | ||
|
|
||
| int main(int argc, char** argv) { | ||
| // Confirm >1 optimizers can be created w/o error | ||
| Optimizer* opt = OptimizerRegistry::Find("sgd"); | ||
| opt = OptimizerRegistry::Find("adam"); | ||
| int ret = (opt == 0) ? 1 : 0; | ||
|
|
||
| MXNotifyShutdown(); | ||
| return ret; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
You are checking all optimizers at once, but wouldn't it be better to check every optimizer separately? AFAICT
Registry::__REGISTER__is used, butRegistry::__REGISTER_OR_GET__would make more sense.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.
Optimizers are all registered at once in the original CPP-Package code and in the Python code using decorators. In the original code #5251, they were all registered at once in the file, so when the program was initialized, all optimizers would already be registered (which is the case in Python), not in the first call to the function Find, but that caused multiple definition errors, so in #5545, the were all registered at once in the first call to Find, which caused the inability to have more than one optimizer bc they would be re-registered with each call, so this change makes sure they are registered once. Why check every optimizer separately when they should all be registered at the same time and only once?
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.
It's strange for a look-up function to register optimizers. Would it make more sense to have a macro to handle the multiple-definition problem for built-in 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.
I'm not exactly sure what you mean, but it sounds like you want to revert to the original code, but that would break #5545. @sifmelcara why in #5545 did you
"3. In optimizer.hpp, I delayed the registration of sgd optimizer to the first call of OptimizerRegistry::Find."?