contribute_to_paddle_en.html 22.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Contribute Code &mdash; PaddlePaddle  documentation</title>
  

  
  

  

  
  
    

  

  
  
27
    <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
28 29 30 31 32
  

  
  
        <link rel="index" title="Index"
33 34 35 36
              href="../genindex.html"/>
        <link rel="search" title="Search" href="../search.html"/>
    <link rel="top" title="PaddlePaddle  documentation" href="../index.html"/>
        <link rel="up" title="Development" href="index_en.html"/>
37
        <link rel="next" title="Contribute Documentation" href="write_docs_en.html"/>
38 39 40
        <link rel="prev" title="Write New Layers" href="new_layer_en.html"/> 

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/css/perfect-scrollbar.min.css" type="text/css" />
41
  <link rel="stylesheet" href="../_static/css/override.css" type="text/css" />
42 43 44 45 46 47 48 49 50 51 52 53 54
  <script>
  var _hmt = _hmt || [];
  (function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?b9a314ab40d04d805655aab1deee08ba";
    var s = document.getElementsByTagName("script")[0]; 
    s.parentNode.insertBefore(hm, s);
  })();
  </script>

  

  
55
  <script src="../_static/js/modernizr.min.js"></script>
56 57 58 59 60 61 62 63

</head>

<body class="wy-body-for-nav" role="document">

  
  <header class="site-header">
    <div class="site-logo">
64
      <a href="/"><img src="../_static/images/PP_w.png"></a>
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    </div>
    <div class="site-nav-links">
      <div class="site-menu">
        <a class="fork-on-github" href="https://github.com/PaddlePaddle/Paddle" target="_blank"><i class="fa fa-github"></i>Fork me on Github</a>
        <div class="language-switcher dropdown">
          <a type="button" data-toggle="dropdown">
            <span>English</span>
            <i class="fa fa-angle-up"></i>
            <i class="fa fa-angle-down"></i>
          </a>
          <ul class="dropdown-menu">
            <li><a href="/doc_cn">中文</a></li>
            <li><a href="/doc">English</a></li>
          </ul>
        </div>
        <ul class="site-page-links">
          <li><a href="/">Home</a></li>
        </ul>
      </div>
      <div class="doc-module">
        
        <ul class="current">
87 88 89 90
<li class="toctree-l1"><a class="reference internal" href="../getstarted/index_en.html">GET STARTED</a></li>
<li class="toctree-l1"><a class="reference internal" href="../build_and_install/index_en.html">Install and Build</a></li>
<li class="toctree-l1"><a class="reference internal" href="../howto/index_en.html">HOW TO</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index_en.html">Development</a></li>
91 92 93 94
</ul>

        
<div role="search">
95
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>        
      </div>
    </div>
  </header>
  
  <div class="main-content-wrap">

    
    <nav class="doc-menu-vertical" role="navigation">
        
          
          <ul class="current">
112 113
<li class="toctree-l1"><a class="reference internal" href="../getstarted/index_en.html">GET STARTED</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../getstarted/quickstart_en.html">Quick Start</a></li>
114 115
</ul>
</li>
116 117 118 119
<li class="toctree-l1"><a class="reference internal" href="../build_and_install/index_en.html">Install and Build</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../build_and_install/pip_install_en.html">Install Using pip</a></li>
<li class="toctree-l2"><a class="reference internal" href="../build_and_install/docker_install_en.html">Run in Docker Containers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../build_and_install/build_from_source_en.html">Build from Sources</a></li>
120 121
</ul>
</li>
122 123 124 125 126
<li class="toctree-l1"><a class="reference internal" href="../howto/index_en.html">HOW TO</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../howto/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
127 128
</ul>
</li>
129 130 131 132 133 134 135 136
<li class="toctree-l2"><a class="reference internal" href="../howto/cluster/index_en.html">Distributed Training</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster/preparations_en.html">Preparations</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster/cmd_argument_en.html">Command-line arguments</a></li>
<li class="toctree-l3"><a class="reference internal" href="../howto/cluster/multi_cluster/index_en.html">Use different clusters</a><ul>
<li class="toctree-l4"><a class="reference internal" href="../howto/cluster/multi_cluster/fabric_en.html">Cluster Training Using Fabric</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/cluster/multi_cluster/openmpi_en.html">Cluster Training Using OpenMPI</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/cluster/multi_cluster/k8s_en.html">PaddlePaddle On Kubernetes</a></li>
<li class="toctree-l4"><a class="reference internal" href="../howto/cluster/multi_cluster/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li>
137 138
</ul>
</li>
139 140 141 142 143 144 145 146 147 148
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../howto/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../howto/rnn/rnn_config_en.html">RNN Configuration</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../howto/optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="index_en.html">Development</a><ul class="current">
149 150
<li class="toctree-l2"><a class="reference internal" href="new_layer_en.html">Write New Layers</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Contribute Code</a></li>
151
<li class="toctree-l2"><a class="reference internal" href="write_docs_en.html">Contribute Documentation</a></li>
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
</ul>
</li>
</ul>

        
    </nav>
    
    <section class="doc-content-wrap">

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
174
        <li><a href="index_en.html">Development</a> > </li>
175 176 177 178 179 180 181 182 183 184 185 186
      
    <li>Contribute Code</li>
  </ul>
</div>
      
      <div class="wy-nav-content" id="doc-content">
        <div class="rst-content">
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="contribute-code">
<span id="contribute-code"></span><h1>Contribute Code<a class="headerlink" href="#contribute-code" title="Permalink to this headline"></a></h1>
187 188
<p>You are welcome to contribute to project PaddlePaddle. To contribute to PaddlePaddle, you have to agree with the
<a class="reference external" href="https://gist.github.com/wangkuiyi/0c22c7b1bd3bb7eb27d76f85c3a3e329">PaddlePaddle Contributor License Agreement</a>.</p>
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
<p>We sincerely appreciate your contribution.  This document explains our workflow and work style.</p>
<div class="section" id="workflow">
<span id="workflow"></span><h2>Workflow<a class="headerlink" href="#workflow" title="Permalink to this headline"></a></h2>
<p>PaddlePaddle uses this <a class="reference external" href="http://nvie.com/posts/a-successful-git-branching-model/">Git branching model</a>.  The following steps guide usual contributions.</p>
<ol>
<li><p class="first">Fork</p>
<p>Our development community has been growing fastly; it doesn&#8217;t make sense for everyone to write into the official repo.  So, please file Pull Requests from your fork.  To make a fork,  just head over to the GitHub page and click the <a class="reference external" href="https://help.github.com/articles/fork-a-repo/">&#8220;Fork&#8221; button</a>.</p>
</li>
<li><p class="first">Clone</p>
<p>To make a copy of your fork to your local computers, please run</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git clone https://github.com/your-github-account/paddle
<span class="nb">cd</span> paddle
</pre></div>
</div>
</li>
<li><p class="first">Create the local feature branch</p>
<p>For daily works like adding a new feature or fixing a bug, please open your feature branch before coding:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git checkout -b my-cool-stuff
</pre></div>
</div>
</li>
<li><p class="first">Commit</p>
<p>Before issuing your first <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span></code> command, please install <a class="reference external" href="http://pre-commit.com/"><code class="docutils literal"><span class="pre">pre-commit</span></code></a> by running the following commands:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>pip install pre-commit
pre-commit install
</pre></div>
</div>
<p>Our pre-commit configuration requires clang-format 3.8 for auto-formating C/C++ code and yapf for Python.</p>
<p>Once installed, <code class="docutils literal"><span class="pre">pre-commit</span></code> checks the style of code and documentation in every commit.  We will see something like the following when you run <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>➜  git commit
CRLF end-lines remover...............................(no files to check)Skipped
yapf.................................................(no files to check)Skipped
Check for added large files..............................................Passed
Check for merge conflicts................................................Passed
Check for broken symlinks................................................Passed
Detect Private Key...................................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
clang-formater.......................................(no files to check)Skipped
[my-cool-stuff c703c041] add test file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 233
</pre></div>
</div>
</li>
<li><p class="first">Build and test</p>
<p>Users can build PaddlePaddle natively on Linux and Mac OS X.  But to unify the building environment and to make it easy for debugging, the recommended way is <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/howto/dev/build_en.md">using Docker</a>.</p>
</li>
<li><p class="first">Keep pulling</p>
<p>An experienced Git user pulls from the official repo often &#8211; daily or even hourly, so they notice conflicts with others work early, and it&#8217;s easier to resolve smaller conflicts.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git remote add upstream https://github.com/PaddlePaddle/Paddle
git pull upstream develop
</pre></div>
</div>
</li>
<li><p class="first">Push and file a pull request</p>
<p>You can &#8220;push&#8221; your local work into your forked repo:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git push origin my-cool-stuff
</pre></div>
</div>
<p>The push allows you to create a pull request, requesting owners of this <a class="reference external" href="https://github.com/PaddlePaddle/Paddle">official repo</a> to pull your change into the official one.</p>
<p>To create a pull request, please follow <a class="reference external" href="https://help.github.com/articles/creating-a-pull-request/">these steps</a>.</p>
<p>If your change is for fixing an issue, please write <a class="reference external" href="https://help.github.com/articles/closing-issues-using-keywords/">&#8220;Fixes &lt;issue-URL&gt;&#8221;</a> in the description section of your pull request.  Github would close the issue when the owners merge your pull request.</p>
<p>Please remember to specify some reviewers for your pull request.  If you don&#8217;t know who are the right ones, please follow Github&#8217;s recommendation.</p>
</li>
</ol>
<ol>
<li><p class="first">Delete local and remote branches</p>
<p>To keep your local workspace and your fork clean, you might want to remove merged branches:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>git push origin :my-cool-stuff
git checkout develop
git pull upstream develop
git branch -d my-cool-stuff
</pre></div>
</div>
</li>
</ol>
<div class="section" id="code-review">
<span id="code-review"></span><h3>Code Review<a class="headerlink" href="#code-review" title="Permalink to this headline"></a></h3>
<ul class="simple">
<li>Please feel free to ping your reviewers by sending them the URL of your pull request via IM or email.  Please do this after your pull request passes the CI.</li>
<li>Please answer reviewers&#8217; every comment.  If you are to follow the comment, please write &#8220;Done&#8221;; please give a reason otherwise.</li>
<li>If you don&#8217;t want your reviewers to get overwhelmed by email notifications, you might reply their comments by <a class="reference external" href="https://help.github.com/articles/reviewing-proposed-changes-in-a-pull-request/">in a batch</a>.</li>
<li>Reduce the unnecessary commits.  Some developers commit often.  It is recommended to append a sequence of small changes into one commit by running <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span> <span class="pre">--amend</span></code> instead of <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span></code>.</li>
</ul>
</div>
</div>
<div class="section" id="coding-standard">
<span id="coding-standard"></span><h2>Coding Standard<a class="headerlink" href="#coding-standard" title="Permalink to this headline"></a></h2>
<div class="section" id="code-style">
<span id="code-style"></span><h3>Code Style<a class="headerlink" href="#code-style" title="Permalink to this headline"></a></h3>
<p>Our C/C++ code follows the <a class="reference external" href="http://google.github.io/styleguide/cppguide.html">Google style guide</a>.</p>
<p>Our Python code follows the <a class="reference external" href="https://www.python.org/dev/peps/pep-0008/">PEP8 style guide</a>.</p>
<p>Our build process helps to check the code style.  In <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/b84e8226514b8bb4405c3c28e54aa5077193d179/paddle/scripts/docker/build.sh#L42"><code class="docutils literal"><span class="pre">build.sh</span></code></a>, the entry point of our <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/b84e8226514b8bb4405c3c28e54aa5077193d179/Dockerfile#L88">builder Docker image</a>, the CMake argument <code class="docutils literal"><span class="pre">WITH_STYLE_CHECK</span></code> is set to <code class="docutils literal"><span class="pre">ON</span></code> by default.  This flag is on</p>
<p>Please install pre-commit, which automatically reformat the changes to C/C++ and Python code whenever we run <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span></code>.  To check the whole codebase, we can run the command <code class="docutils literal"><span class="pre">pre-commit</span> <span class="pre">run</span> <span class="pre">-a</span></code>, as in the <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/b84e8226514b8bb4405c3c28e54aa5077193d179/paddle/scripts/travis/check_style.sh#L30"><code class="docutils literal"><span class="pre">check_style.sh</span></code> file</a>, which is invoked by <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/b84e8226514b8bb4405c3c28e54aa5077193d179/.travis.yml#L43">our Travis CI configuration</a>.</p>
</div>
<div class="section" id="unit-tests">
<span id="unit-tests"></span><h3>Unit Tests<a class="headerlink" href="#unit-tests" title="Permalink to this headline"></a></h3>
<p>Please remember to add related unit tests.</p>
<ul class="simple">
<li>For C/C++ code, please follow <a class="reference external" href="https://github.com/google/googletest/blob/master/googletest/docs/Primer.md"><code class="docutils literal"><span class="pre">google-test</span></code> Primer</a>.</li>
<li>For Python code, please use <a class="reference external" href="http://pythontesting.net/framework/unittest/unittest-introduction/">Python&#8217;s standard <code class="docutils literal"><span class="pre">unittest</span></code> package</a>.</li>
</ul>
</div>
<div class="section" id="writing-logs">
<span id="writing-logs"></span><h3>Writing Logs<a class="headerlink" href="#writing-logs" title="Permalink to this headline"></a></h3>
<p>We use <a class="reference external" href="https://github.com/google/glog">glog</a> for logging in our C/C++ code.</p>
<p>For general information, please use <code class="docutils literal"><span class="pre">LOG</span></code>.  For debug information, please use <a class="reference external" href="http://htmlpreview.github.io/?https://github.com/google/glog/blob/master/doc/glog.html#verbose"><code class="docutils literal"><span class="pre">VLOG</span></code></a>.  The reason is at <a class="reference external" href="https://groups.google.com/a/chromium.org/d/msg/chromium-dev/3NDNd1KzXeY/AZKMMx37fdQJ">here</a>.</p>
<p><code class="docutils literal"><span class="pre">VLOG</span></code> requires a <em>verbose level</em> parameter.  For example:</p>
<div class="highlight-c++"><div class="highlight"><pre><span></span><span class="n">VLOG</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Operator FC is taking &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">num_inputs</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;inputs.&quot;</span>
</pre></div>
</div>
<p>When we run a PaddlePaddle application or test, we can specify a verbose threshold.  For example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="nv">GLOG_vmodule</span><span class="o">=</span><span class="nv">buddy_allocator</span><span class="o">=</span><span class="m">2</span> <span class="se">\</span>
<span class="nv">GLOG_v</span><span class="o">=</span><span class="m">10</span> <span class="se">\</span>
python <span class="se">\</span>
../python/paddle/v2/framework/tests/test_recurrent_op.py
</pre></div>
</div>
<p>This will enable VLOG messages generated by <code class="docutils literal"><span class="pre">buddy_allocator.{h,cc}</span></code> and in the verbose range of 0 to 3, so you will see above example VLOG message, which is in level 3.  This suggests that we output overall messages in lower verbose levels, so they display with higher probability.  When coding C++, please follow the verbose level convention as follows:</p>
<ul class="simple">
<li>verbose level 1: <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/framework">framework</a></li>
<li>verbose level 3: <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/operators">operators</a></li>
<li>verbose level 5: <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/memory">memory</a>, <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/platform">platform</a></li>
<li>verbose level 7: <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/tree/develop/paddle/math">math</a></li>
</ul>
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
325
        <a href="write_docs_en.html" class="btn btn-neutral float-right" title="Contribute Documentation" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
      
      
        <a href="new_layer_en.html" class="btn btn-neutral" title="Write New Layers" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2016, PaddlePaddle developers.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
358
            URL_ROOT:'../',
359 360 361 362 363 364 365
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
        };
    </script>
366 367 368
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
369 370 371 372 373 374
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
       
  

  
  
375
    <script type="text/javascript" src="../_static/js/theme.js"></script>
376 377 378 379
  
  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/perfect-scrollbar/0.6.14/js/perfect-scrollbar.jquery.min.js"></script>
380
  <script src="../_static/js/paddle_doc_init.js"></script> 
381 382 383

</body>
</html>