Chainer Training

Instructions for using Chainer for training

This guide walks you through using Chainer for training your model.

What is Chainer?

Chainer is a powerful, flexible and intuitive deep learning framework.

  • Chainer supports CUDA computation. It only requires a few lines of code to leverage a GPU. It also runs on multiple GPUs with little effort.
  • Chainer supports various network architectures including feed-forward nets, convnets, recurrent nets and recursive nets. It also supports per-batch architectures.
  • Forward computation can include any control flow statements of Python without lacking the ability of backpropagation. It makes code intuitive and easy to debug.

ChainerMN is an additional package for Chainer, a flexible deep learning framework. ChainerMN enables multi-node distributed deep learning with the following features:

  • Scalable — it makes full use of the latest technologies such as NVIDIA NCCL and CUDA-Aware MPI,
  • Flexible — even dynamic neural networks can be trained in parallel thanks to Chainer’s flexibility, and
  • Easy — minimal changes to existing user code are required.

This blog post provides a benchmark results using up to 128 GPUs.

Installing Chainer Operator

If you haven’t already done so please follow the Getting Started Guide to deploy Kubeflow.

An alpha version of Chainer support was introduced with Kubeflow 0.3.0. You must be using a version of Kubeflow newer than 0.3.0.

Verify that Chainer support is included in your Kubeflow deployment

This section has not yet been converted to kustomize, please refer to kubeflow/manifests/issues/232.

Check that the Chainer Job custom resource is installed

  1. kubectl get crd

The output should include chainerjobs.kubeflow.org

  1. NAME AGE
  2. ...
  3. chainerjobs.kubeflow.org 4d
  4. ...

If it is not included you can add it as follows

  1. cd ${KSONNET_APP}
  2. ks pkg install kubeflow/chainer-job
  3. ks generate chainer-operator chainer-operator
  4. ks apply ${ENVIRONMENT} -c chainer-operator

Creating a Chainer Job

You can create an Chainer Job by defining an ChainerJob config file. First, please create a file example-job-mn.yaml like below:

  1. apiVersion: kubeflow.org/v1alpha1
  2. kind: ChainerJob
  3. metadata:
  4. name: example-job-mn
  5. spec:
  6. backend: mpi
  7. master:
  8. mpiConfig:
  9. slots: 1
  10. activeDeadlineSeconds: 6000
  11. backoffLimit: 60
  12. template:
  13. spec:
  14. containers:
  15. - name: chainer
  16. image: everpeace/chainermn:1.3.0
  17. command:
  18. - sh
  19. - -c
  20. - |
  21. mpiexec -n 3 -N 1 --allow-run-as-root --display-map --mca mpi_cuda_support 0 \
  22. python3 /train_mnist.py -e 2 -b 1000 -u 100
  23. workerSets:
  24. ws0:
  25. replicas: 2
  26. mpiConfig:
  27. slots: 1
  28. template:
  29. spec:
  30. containers:
  31. - name: chainer
  32. image: everpeace/chainermn:1.3.0
  33. command:
  34. - sh
  35. - -c
  36. - |
  37. while true; do sleep 1 & wait; done

See examples/chainerjob-reference.yaml for definitions of each attributes. You may change the config file based on your requirements. By default, the example job is distributed learning with 3 nodes (1 master, 2 workers).

Deploy the ChainerJob resource to start training:

  1. kubectl create -f example-job-mn.yaml

You should now be able to see the created pods which consist of the chainer job.

  1. kubectl get pods -l chainerjob.kubeflow.org/name=example-job-mn

The training should run only for 2 epochs and takes within a few minutes even on cpu only cluster. Logs can be inspected to see its training progress.

  1. PODNAME=$(kubectl get pods -l chainerjob.kubeflow.org/name=example-job-mn,chainerjob.kubeflow.org/role=master -o name)
  2. kubectl logs -f ${PODNAME}

Monitoring an Chainer Job

  1. kubectl get -o yaml chainerjobs example-job-mn

See the status section to monitor the job status. Here is sample output when the job is successfully completed.

  1. apiVersion: kubeflow.org/v1alpha1
  2. kind: ChainerJob
  3. metadata:
  4. name: example-job-mn
  5. ...
  6. status:
  7. completionTime: 2018-09-01T16:42:35Z
  8. conditions:
  9. - lastProbeTime: 2018-09-01T16:42:35Z
  10. lastTransitionTime: 2018-09-01T16:42:35Z
  11. status: "True"
  12. type: Complete
  13. startTime: 2018-09-01T16:34:04Z
  14. succeeded: 1