Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
IssamLaradji committed Apr 14, 2020
1 parent d089bb8 commit ff1953f
Show file tree
Hide file tree
Showing 12 changed files with 1,495 additions and 1 deletion.
128 changes: 128 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.idea
# C extensions
*.so
.vscode
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
*.ipynb_checkpoints

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule
results/
# SageMath parsed files
*.sage.py
user_configs.py
job_configs.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# First
## SPS - Stochastic Polyak Step-size [[paper]](https://arxiv.org/pdf/2002.10542.pdf)

Fast convergence with SPS optimizer. The first efficient stochastic variant of the classical Polyak step-size for SGD

### 1. Install requirements

`pip install -r requirements.txt`

### 2. Mnist experiment

`python trainval.py -e mnist -sb ../results -r 1`

where `-e` is the experiment group, `-sb` is the result directory.

### 3. kernel experiment

`python trainval.py -e kernel -sb ../results -r 1`


#### Visualize

Create the jupyter by running `create_jupyter.py`, and run the first cell to get plots,

![alt text](results/mnist.jpg)


#### Citation

```
@article{loizou2020stochastic,
title={Stochastic polyak step-size for SGD: An adaptive learning rate for fast convergence},
author={Loizou, Nicolas and Vaswani, Sharan and Laradji, Issam and Lacoste-Julien, Simon},
journal={arXiv preprint arXiv:2002.10542},
year={2020}
}
```
3 changes: 3 additions & 0 deletions create_jupyter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

from haven import haven_jupyter as hj
hj.create_jupyter(fname='results/notebook.ipynb', print_url=True, overwrite=True)
135 changes: 135 additions & 0 deletions exp_configs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from haven import haven_utils as hu
import itertools


# datasets
kernel_datasets = ["mushrooms",
# "w8a", "ijcnn",
# "rcv1"
]

# define runs
run_list = [0]

# define optimizers
c_list = [0.2, 0.5]
sps_list = []

for c, adapt_flag in itertools.product(c_list, ['smooth_iter']):
sps_list += [{'name':"sps", "c":c, 'adapt_flag':adapt_flag}]

opt_list = sps_list + [{'name': 'adam'}]

EXP_GROUPS = {}

# define interpolation exp groups
EXP_GROUPS['kernel'] = hu.cartesian_exp_group({"dataset":kernel_datasets,
"model":["linear"],
"loss_func": ['logistic_loss'],
"acc_func": ["logistic_accuracy"],
"opt": opt_list ,
"batch_size":[100],
"max_epoch":[35],
"runs":run_list})

EXP_GROUPS['mf'] = hu.cartesian_exp_group({"dataset":["matrix_fac"],
"model":["matrix_fac_1", "matrix_fac_4", "matrix_fac_10", "linear_fac"],
"loss_func": ["squared_loss"],
"opt": opt_list,
"acc_func":["mse"],
"batch_size":[100],
"max_epoch":[50],
"runs":run_list})

EXP_GROUPS['mnist'] = hu.cartesian_exp_group({"dataset":["mnist"],
"model":["mlp"],
"loss_func": ["softmax_loss"],
"opt": opt_list,
"acc_func":["softmax_accuracy"],
"batch_size":[128],
"max_epoch":[200],
"runs":run_list})

EXP_GROUPS['deep'] = (hu.cartesian_exp_group({"dataset":["cifar10"],
"model":["resnet34", "densenet121"],
"loss_func": ["softmax_loss"],
"opt": opt_list,
"acc_func":["softmax_accuracy"],
"batch_size":[128],
"max_epoch":[200],
"runs":run_list}) +

hu.cartesian_exp_group({"dataset":["cifar100"],
"model":["resnet34_100", "densenet121_100"],
"loss_func": ["softmax_loss"],
"opt": opt_list,
"acc_func":["softmax_accuracy"],
"batch_size":[128],
"max_epoch":[200],
"runs":run_list})
)

EXP_GROUPS['cifar'] = hu.cartesian_exp_group({"dataset":["cifar100"],
"model":["resnet34_100"],
"loss_func": ["softmax_loss"],
"opt": opt_list,
"acc_func":["softmax_accuracy"],
"batch_size":[128],
"max_epoch":[200],
"runs":[0]})


# define non-interpolation exp groups
eta_max_list = [1, 5, 100]
c_list = [0.5]

sps_l2_list = []
for c, eta_max in itertools.product(c_list, eta_max_list):
sps_l2_list += [{'name':"sps", "c":c,
'fstar_flag':True, 'eps':0,
'adapt_flag':'constant',
'eta_max':eta_max}]
sps_list = []
for c, eta_max in itertools.product(c_list, eta_max_list):
sps_list += [{'name':"sps", "c":c,
'fstar_flag':False, 'eps':0,
'adapt_flag':'constant',
'eta_max':eta_max}]

sgd_list = [{'name':"sgd",
"lr":10.0},{'name':"sgd",
"lr":1.0}, {'name':"sgd",
"lr":1e-3}, {'name':"sgd",
"lr":1e-1}, {'name':"sgd",
"lr":1e-2}]

EXP_GROUPS['syn_l2'] = (hu.cartesian_exp_group({"dataset":['syn'],
"model":["logistic"],
"loss_func": [
'logistic_l2_loss',
],
"acc_func": ["logistic_accuracy"],
"opt": sps_l2_list + sgd_list,
"batch_size":[1],
"max_epoch":[50],
"runs":run_list}))

EXP_GROUPS['syn'] = (hu.cartesian_exp_group({"dataset":['syn'],
"model":["logistic"],
"loss_func": [
'logistic_loss',
],
"acc_func": ["logistic_accuracy"],
"opt": sps_list + sgd_list,
"batch_size":[1],
"max_epoch":[50],
"runs":run_list}))


job_config = {'volume': ['/mnt:/mnt'],
'image': 'docker_image',
'bid': '5',
'restartable': '1',
'gpu': '1',
'mem': '32',
'cpu': '2'}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e git://github.com/ElementAI/haven.git#egg=haven
Empty file added src/__init__.py
Empty file.
Loading

0 comments on commit ff1953f

Please sign in to comment.