You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2020/04/04 15:31:13 UTC
[GitHub] [singa] nudles commented on issue #651: [WIP ]Simply example APIs
nudles commented on issue #651: [WIP ]Simply example APIs
URL: https://github.com/apache/singa/pull/651#issuecomment-609045570
I suggest to merge the examples under `examples/autograd` into the following scheme
```
autograd
train.py
train_mpi.py
train_multiprocess.py
data # define the data loading and preprocessing
cifar10.py
mnist.py
model # define the model
cnn.py
resnet.py
xception.py
```
```python
# train.py
def run(max_epoch, rank, num_workers, model, data, sgd):
if model == 'resnet':
from model import resnet
model = resnet.create_model()
elif model == 'cnn':
model = cnn.create_model()
....
if data == 'cifar10':
from data import cifar10:
train_x, train_y, val_x, val_y = cifar10.load()
elif data == 'mnist':
....
train_x, train_y, val_x, val_y = partition(rank, num_workers, train_x, train_y, val_x, val_y)
# bp and sgd
if __name__ == '__main__':
# use argparse to get command config: max_epoch, model, data, etc. for single gpu training
sgd = # create sgd
run(0, 1, ..., sgd)
# train_mpi.py
if __name__ == '__main__':
# use argparse to get command args: max_epoch, model, data, etc. for multi-gpu training
sgd = # create sgd
dist_sgd = DistOpt(sgd...)
run(dist_sgd.rank, dist_sgd.world_size, ... dist_sgd)
# train_multiprocess.py
def run(rank, num_gpu, ...):
sgd = ...
dist_sgd = DistOpt(sgd)
train.run(rank, num_gpu, ... dist_sgd)
if __name__ == '__main__':
# use argparse to get command args: max_epoch, model, data, etc. for multi-gpu training
nccl_id = ...
process = []
for gpu_num in range(0, gpu_per_node):
process.append(multiprocessing.Process(target=run, args=(gpu_num, ... nccl_id)))
for p in process:
p.start()
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services