README.md 7.0 KB
Newer Older
1
# Building PaddlePaddle
G
gongweibao 已提交
2

3
## Goals
G
gongweibao 已提交
4

T
typhoonzero 已提交
5
We want to make the building procedures:
G
gongweibao 已提交
6

T
typhoonzero 已提交
7 8 9 10 11 12 13 14
1. Static, can reproduce easily.
1. Generate python `whl` packages that can be widely use cross many distributions.
1. Build different binaries per release to satisfy different environments:
    - Binaries for different CUDA and CUDNN versions, like CUDA 7.5, 8.0, 9.0
    - Binaries containing only capi
    - Binaries for python with wide unicode support or not.
1. Build docker images with PaddlePaddle pre-installed, so that we can run
PaddlePaddle applications directly in docker or on Kubernetes clusters.
G
gongweibao 已提交
15

16 17 18
To achieve this, we maintain a dockerhub repo:https://hub.docker.com/r/paddlepaddle/paddle
which provides pre-built environment images to build PaddlePaddle and generate corresponding `whl`
binaries.(**We strongly recommend building paddlepaddle in our pre-specified Docker environment.**) 
G
gongweibao 已提交
19

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
## Development Workflow

Here we describe how the workflow goes on.  We start from considering our daily development environment.

Developers work on a computer, which is usually a laptop or desktop:

<img src="doc/paddle-development-environment.png" width=500 />

or, they might rely on a more sophisticated box (like with GPUs):

<img src="doc/paddle-development-environment-gpu.png" width=500 />

A principle here is that source code lies on the development computer (host) so that editors like Eclipse can parse the source code to support auto-completion.

## Build With Docker
35

L
liaogang 已提交
36
### Build Environments
37

38
The lastest pre-built build environment images are:
39

T
typhoonzero 已提交
40 41
| Image | Tag |
| ----- | --- |
42 43
| paddlepaddle/paddle | latest-dev |
| paddlepaddle/paddle | latest-dev-android |
44

T
typhoonzero 已提交
45
### Start Build
46

T
typhoonzero 已提交
47 48 49
```bash
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
50
./paddle/scripts/paddle_docker_build.sh build
T
typhoonzero 已提交
51
```
52

T
typhoonzero 已提交
53 54
After the build finishes, you can get output `whl` package under
`build/python/dist`.
55

56 57 58
This command will download the most recent dev image from docker hub, start a container in the backend and then run the build script `/paddle/paddle/scripts/paddle_build.sh build` in the container. 
The container mounts the source directory on the host into `/paddle`. 
When it writes to `/paddle/build` in the container, it writes to `$PWD/build` on the host indeed.
59

T
typhoonzero 已提交
60
### Build Options
61

T
typhoonzero 已提交
62
Users can specify the following Docker build arguments with either "ON" or "OFF" value:
63

T
typhoonzero 已提交
64 65 66 67
| Option | Default | Description |
| ------ | -------- | ----------- |
| `WITH_GPU` | OFF | Generates NVIDIA CUDA GPU code and relies on CUDA libraries. |
| `WITH_AVX` | OFF | Set to "ON" to enable AVX support. |
68
| `WITH_TESTING` | OFF | Build unit tests binaries. |
69
| `WITH_MKL` | ON | Build with [Intel® MKL](https://software.intel.com/en-us/mkl) and [Intel® MKL-DNN](https://github.com/01org/mkl-dnn) support. |
70
| `WITH_GOLANG` | OFF | Build fault-tolerant parameter server written in go. |
T
typhoonzero 已提交
71 72 73 74 75 76
| `WITH_PYTHON` | ON | Build with python support. Turn this off if build is only for capi. |
| `WITH_STYLE_CHECK` | ON | Check the code style when building. |
| `PYTHON_ABI` | "" | Build for different python ABI support, can be cp27-cp27m or cp27-cp27mu |
| `RUN_TEST` | OFF | Run unit test immediently after the build. |
| `WITH_DOC` | OFF | Build docs after build binaries. |
| `WOBOQ` | OFF | Generate WOBOQ code viewer under `build/woboq_out` |
77

T
typhoonzero 已提交
78
## Docker Images
79

T
typhoonzero 已提交
80 81
You can get the latest PaddlePaddle docker images by
`docker pull paddlepaddle/paddle:<version>` or build one by yourself.
82

T
typhoonzero 已提交
83
### Official Docker Releases
84

T
typhoonzero 已提交
85 86 87 88
Official docker images at
[here](https://hub.docker.com/r/paddlepaddle/paddle/tags/),
you can choose either latest or images with a release tag like `0.10.0`,
Currently available tags are:
89

T
typhoonzero 已提交
90 91 92 93 94 95
|   Tag  | Description |
| ------ | --------------------- |
| latest | latest CPU only image |
| latest-gpu | latest binary with GPU support |
| 0.10.0 | release 0.10.0 CPU only binary image |
| 0.10.0-gpu | release 0.10.0 with GPU support |
96

T
typhoonzero 已提交
97
### Build Your Own Image
98

T
typhoonzero 已提交
99 100
Build PaddlePaddle docker images are quite simple since PaddlePaddle can
be installed by just running `pip install`. A sample `Dockerfile` is:
101

T
typhoonzero 已提交
102 103 104 105 106 107 108 109
```dockerfile
FROM nvidia/cuda:7.5-cudnn5-runtime-centos6
RUN yum install -y centos-release-SCL
RUN yum install -y python27
# This whl package is generated by previous build steps.
ADD python/dist/paddlepaddle-0.10.0-cp27-cp27mu-linux_x86_64.whl /
RUN pip install /paddlepaddle-0.10.0-cp27-cp27mu-linux_x86_64.whl && rm -f /*.whl
```
110

T
typhoonzero 已提交
111 112
Then build the image by running `docker build -t [REPO]/paddle:[TAG] .` under
the directory containing your own `Dockerfile`.
113

T
typhoonzero 已提交
114
- NOTE: note that you can choose different base images for your environment, you can find all the versions [here](https://hub.docker.com/r/nvidia/cuda/).
115

T
typhoonzero 已提交
116
### Use Docker Images
117

T
typhoonzero 已提交
118 119
Suppose that you have written an application program `train.py` using
PaddlePaddle, we can test and run it using docker:
120

121
```bash
T
typhoonzero 已提交
122
docker run --rm -it -v $PWD:/work paddlepaddle/paddle /work/a.py
123
```
124

T
typhoonzero 已提交
125
But this works only if all dependencies of `train.py` are in the production image. If this is not the case, we need to build a new Docker image from the production image and with more dependencies installs.
126

T
typhoonzero 已提交
127
### Run PaddlePaddle Book In Docker
G
gongweibao 已提交
128

T
typhoonzero 已提交
129 130 131
Our [book repo](https://github.com/paddlepaddle/book) also provide a docker
image to start a jupiter notebook inside docker so that you can run this book
using docker:
132

133
```bash
T
typhoonzero 已提交
134
docker run -d -p 8888:8888 paddlepaddle/book
135
```
G
gongweibao 已提交
136

T
typhoonzero 已提交
137 138
Please refer to https://github.com/paddlepaddle/book if you want to build this
docker image by your self.
139

T
typhoonzero 已提交
140
### Run Distributed Applications
141

T
typhoonzero 已提交
142
In our [API design doc](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/api.md#distributed-training), we proposed an API that starts a distributed training job on a cluster.  This API need to build a PaddlePaddle application into a Docker image as above and calls kubectl to run it on the cluster.  This API might need to generate a Dockerfile look like above and call `docker build`.
143

T
typhoonzero 已提交
144
Of course, we can manually build an application image and launch the job using the kubectl tool:
145

146
```bash
T
typhoonzero 已提交
147 148 149 150
docker build -f some/Dockerfile -t myapp .
docker tag myapp me/myapp
docker push
kubectl ...
151
```
152

153
### Reading source code with woboq codebrowser
154

155
For developers who are interested in the C++ source code, you can build C++ source code into HTML pages using [Woboq codebrowser](https://github.com/woboq/woboq_codebrowser).
156

157
- The following command builds PaddlePaddle, generates HTML pages from C++ source code, and writes HTML pages into `$HOME/woboq_out` on the host:
G
gongweibao 已提交
158

159 160 161
```bash
./paddle/scripts/paddle_docker_build.sh html
```
T
typhoonzero 已提交
162

163
- You can open the generated HTML files in your Web browser. Or, if you want to run a Nginx container to serve them for a wider audience, you can run:
T
typhoonzero 已提交
164

165 166 167
```
docker run -v $HOME/woboq_out:/usr/share/nginx/html -d -p 8080:80 nginx
```
Y
Yancey1989 已提交
168

169
## More Options
T
typhoonzero 已提交
170

171
### Build Without Docker
Y
update  
Yancey1989 已提交
172

173
Follow the *Dockerfile* in the paddlepaddle repo to set up your local dev environment and run:
Y
Yancey1989 已提交
174 175

```bash
176
./paddle/scripts/paddle_build.sh build
Y
Yancey1989 已提交
177 178
```

179
### Additional Tasks
Y
Yancey1989 已提交
180

181 182 183 184 185
You can get the help menu for the build scripts by running with no options:

```bash
./paddle/scripts/paddle_build.sh
or ./paddle/scripts/paddle_docker_build.sh
Y
Yancey1989 已提交
186
```