Skip to content
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

Remove performance issues from freezing MXNet #2394

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class MxModel extends BaseModel {
* @throws IOException Exception for file loading
*/
@Override
@SuppressWarnings("PMD.EmptyControlStatement")
public void load(Path modelPath, String prefix, Map<String, ?> options)
throws IOException, MalformedModelException {
setModelDir(modelPath);
Expand Down Expand Up @@ -143,12 +144,15 @@ public void load(Path modelPath, String prefix, Map<String, ?> options)
boolean trainParam =
options != null && Boolean.parseBoolean((String) options.get("trainParam"));
if (!trainParam) {
block.freezeParameters(true);
// TODO: See https://github.com/deepjavalibrary/djl/pull/2360
// NOPMD
// block.freezeParameters(true);
}
}

/** {@inheritDoc} */
@Override
@SuppressWarnings("PMD.EmptyControlStatement")
public Trainer newTrainer(TrainingConfig trainingConfig) {
PairList<Initializer, Predicate<Parameter>> initializer = trainingConfig.getInitializers();
if (block == null) {
Expand All @@ -157,7 +161,8 @@ public Trainer newTrainer(TrainingConfig trainingConfig) {
}
if (wasLoaded) {
// Unfreeze parameters if training directly
block.freezeParameters(false);
// TODO: See https://github.com/deepjavalibrary/djl/pull/2360
// block.freezeParameters(false);
}
for (Pair<Initializer, Predicate<Parameter>> pair : initializer) {
if (pair.getKey() != null && pair.getValue() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private static Model getModel(Arguments arguments)
SequentialBlock newBlock = new SequentialBlock();
SymbolBlock block = (SymbolBlock) model.getBlock();
block.removeLastBlock();
block.freezeParameters(false);
newBlock.add(block);
// the original model don't include the flatten
// so apply the flatten here
Expand Down