Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix optimizer parms in fit.py + Don't repeatedly call slow prepare_mk…
Browse files Browse the repository at this point in the history
…l.sh script (#7545) (#7547)

* Only call MKL script once

* Fix 'momentum' and 'multi_precision' optimizer args

* fix working
  • Loading branch information
cjolivier01 authored and piiswrong committed Aug 22, 2017
1 parent e0607bc commit f517d9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ include $(config)

ifeq ($(USE_MKL2017), 1)
# must run ./prepare_mkl before including mshadow.mk
RETURN_STRING = $(shell ./prepare_mkl.sh $(MKLML_ROOT))
MKLROOT = $(firstword $(RETURN_STRING))
RETURN_STRING := $(shell ./prepare_mkl.sh $(MKLML_ROOT))
MKLROOT := $(firstword $(RETURN_STRING))
export USE_MKLML = $(lastword $(RETURN_STRING))
endif

Expand Down
13 changes: 10 additions & 3 deletions example/image-classification/common/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,17 @@ def fit(args, network, data_loader, **kwargs):
lr_scheduler = lr_scheduler
optimizer_params = {
'learning_rate': lr,
'momentum' : args.mom,
'wd' : args.wd,
'lr_scheduler': lr_scheduler,
'multi_precision': True}
'lr_scheduler': lr_scheduler}

# Add 'multi_precision' parameter only for SGD optimizer
if args.optimizer == 'sgd':
optimizer_params['multi_precision'] = True

# Only a limited number of optimizers have 'momentum' property
has_momentum = {'sgd', 'dcasgd'}
if args.optimizer in has_momentum:
optimizer_params['momentum'] = args.mom

monitor = mx.mon.Monitor(args.monitor, pattern=".*") if args.monitor > 0 else None

Expand Down

0 comments on commit f517d9d

Please sign in to comment.