<!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>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  
  
        <link rel="index" title="Index"
              href="../../genindex.html"/>
        <link rel="search" title="Search" href="../../search.html"/>
    <link rel="top" title="PaddlePaddle  documentation" href="../../index.html"/>
        <link rel="up" title="HOW TO" href="../index_en.html"/>
        <link rel="next" title="RNN Models" href="../deep_model/rnn/index_en.html"/>
        <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" />
  <link rel="stylesheet" href="../../_static/css/override.css" type="text/css" />
  <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>

  

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

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

  
  <header class="site-header">
    <div class="site-logo">
      <a href="/"><img src="../../_static/images/PP_w.png"></a>
    </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">
<li class="toctree-l1"><a class="reference internal" href="../../getstarted/index_en.html">GET STARTED</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index_en.html">HOW TO</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a></li>
</ul>

        
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <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">
<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/build_and_install/index_en.html">Install and Build</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/docker_install_en.html">PaddlePaddle in Docker Containers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../getstarted/build_and_install/build_from_source_en.html">Installing from Sources</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="../index_en.html">HOW TO</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../usage/cmd_parameter/index_en.html">Set Command-line Parameters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/use_case_en.html">Use Case</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/arguments_en.html">Argument Outline</a></li>
<li class="toctree-l3"><a class="reference internal" href="../usage/cmd_parameter/detail_introduction_en.html">Detail Description</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html">PaddlePaddle Distributed Training</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html#introduction">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html#preparations">Preparations</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html#command-line-arguments">Command-line arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/cluster/cluster_train_en.html#use-cluster-platforms-or-cluster-management-tools">Use cluster platforms or cluster management tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_en.html">Paddle On Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="../usage/k8s/k8s_aws_en.html">Distributed PaddlePaddle Training on AWS with Kubernetes</a></li>
<li class="toctree-l2"><a class="reference internal" href="build_en.html">Build PaddlePaddle from Source Code and Run Unit Test</a></li>
<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>
<li class="toctree-l2"><a class="reference internal" href="../deep_model/rnn/index_en.html">RNN Models</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../deep_model/rnn/rnn_config_en.html">RNN Configuration</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../optimization/gpu_profiling_en.html">Tune GPU Performance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../api/index_en.html">API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/model_configs.html">Model Configuration</a><ul>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/activation.html">Activation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/layer.html">Layers</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/evaluators.html">Evaluators</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/optimizer.html">Optimizer</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/pooling.html">Pooling</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/networks.html">Networks</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../api/v2/config/attr.html">Parameter Attribute</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/data.html">Data Reader Interface and DataSets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/v2/run_logic.html">Training and Inference</a></li>
</ul>
</li>
</ul>

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

      

 







<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
      
        <li><a href="../index_en.html">HOW TO</a> > </li>
      
    <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>
<p>We sincerely appreciate your contributions. You can use fork and pull request
workflow to merge your code.</p>
<div class="section" id="code-requirements">
<span id="code-requirements"></span><h2>Code Requirements<a class="headerlink" href="#code-requirements" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li>Your code comments must be fully documented by
<a class="reference external" href="http://www.stack.nl/~dimitri/doxygen/">Doxygen</a> style.</li>
<li>Make sure the compiler option <code class="docutils literal"><span class="pre">WITH_STYLE_CHECK</span></code> is on and the compiler
passes the code style check.</li>
<li>All code must have unit test.</li>
<li>Pass all unit tests.</li>
</ul>
<p>The following tutorial guides you into submitting your contibution.</p>
</div>
<div class="section" id="creating-a-fork">
<span id="creating-a-fork"></span><h2><a class="reference external" href="https://help.github.com/articles/fork-a-repo/">Creating a Fork</a><a class="headerlink" href="#creating-a-fork" title="Permalink to this headline">¶</a></h2>
<p>Just head over to the GitHub page and click the &#8220;Fork&#8221; button.
It&#8217;s just that simple.</p>
</div>
<div class="section" id="clone">
<span id="clone"></span><h2>Clone<a class="headerlink" href="#clone" title="Permalink to this headline">¶</a></h2>
<p>Clone remote repository.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git clone https://github.com/USERNAME/Paddle
➜  <span class="nb">cd</span> Paddle
</pre></div>
</div>
</div>
<div class="section" id="create-a-local-branch">
<span id="create-a-local-branch"></span><h2>Create a local branch<a class="headerlink" href="#create-a-local-branch" title="Permalink to this headline">¶</a></h2>
<p>Paddle is currently using <a class="reference external" href="http://nvie.com/posts/a-successful-git-branching-model/">Git-flow branching model</a>.</p>
<p>All feature and bug fix development work should be done on a new branch, generally create new branch from <code class="docutils literal"><span class="pre">develop</span></code> branch .</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git checkout -b my-cool-stuff
</pre></div>
</div>
<p>Before the checkout, you need to keep the current branch directory clean, otherwise the untracked file will be brought to the new branch, which can be inspected by <code class="docutils literal"><span class="pre">git</span> <span class="pre">status</span></code>.</p>
</div>
<div class="section" id="using-pre-commit-hook">
<span id="using-pre-commit-hook"></span><h2>Using <code class="docutils literal"><span class="pre">pre-commit</span></code> hook<a class="headerlink" href="#using-pre-commit-hook" title="Permalink to this headline">¶</a></h2>
<p>Paddle developers use <a class="reference external" href="http://pre-commit.com/">pre-commit</a> tool to manage git
pre-commit hooks. It can help us format source codes (cpp, python), check some
basic thing before commit (only one EOL for each file, do not add a huge file
in git). <code class="docutils literal"><span class="pre">pre-commit</span></code> tests is a part of unit tests in Travis-CI now, every
PR doesn&#8217;t fit hook can not be merged into Paddle.</p>
<p>To use <a class="reference external" href="http://pre-commit.com/">pre-commit</a>, you should install it by
<code class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">pre-commit</span></code>, and currently, Paddle uses <code class="docutils literal"><span class="pre">clang-format</span></code> to format
c/cpp sources. Please make sure clang-format 3.8+ installed.</p>
<p>Install and run it as follow:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  pip install pre-commit
➜  pre-commit install
</pre></div>
</div>
<p>When you commit your code, the pre-commit hook will check the local code if there is
anything not suitable to commit, and so on.</p>
</div>
<div class="section" id="start-to-develop">
<span id="start-to-develop"></span><h2>Start to develop<a class="headerlink" href="#start-to-develop" title="Permalink to this headline">¶</a></h2>
<p>In this tutorial, I delete a line in README.md and created a new file.</p>
<p>We can use <code class="docutils literal"><span class="pre">git</span> <span class="pre">status</span></code> to inspect the changes of current directory, <code class="docutils literal"><span class="pre">git</span> <span class="pre">diff</span></code> to see difference.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git status
On branch <span class="nb">test</span>
Changes not staged <span class="k">for</span> commit:
  <span class="o">(</span>use <span class="s2">&quot;git add &lt;file&gt;...&quot;</span> to update what will be committed<span class="o">)</span>
  <span class="o">(</span>use <span class="s2">&quot;git checkout -- &lt;file&gt;...&quot;</span> to discard changes in working directory<span class="o">)</span>

    modified:   README.md

Untracked files:
  <span class="o">(</span>use <span class="s2">&quot;git add &lt;file&gt;...&quot;</span> to include in what will be committed<span class="o">)</span>

    <span class="nb">test</span>

no changes added to commit <span class="o">(</span>use <span class="s2">&quot;git add&quot;</span> and/or <span class="s2">&quot;git commit -a&quot;</span><span class="o">)</span>
</pre></div>
</div>
</div>
<div class="section" id="build-and-test">
<span id="build-and-test"></span><h2>Build and Test<a class="headerlink" href="#build-and-test" title="Permalink to this headline">¶</a></h2>
<p>We package PaddlePaddle&#8217;s compile environment into a Docker image, called the develop image named <code class="docutils literal"><span class="pre">paddle:dev</span></code>, it contains all compiling tools that PaddlePaddle needs.</p>
<p>If you want to build the develop image, just run:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  docker build -t paddle:dev .
</pre></div>
</div>
<p>Then we can use the develop image to build PaddlePaddle source. For example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  docker run -v <span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span>:/paddle -e <span class="s2">&quot;WITH_GPU=OFF&quot;</span> -e <span class="s2">&quot;WITH_AVX=ON&quot;</span> -e <span class="s2">&quot;WITH_TEST=ON&quot;</span> paddle:dev
</pre></div>
</div>
<p>The above command will compile PaddlePaddle and create a Dockerfile for building production image. All the generated files are in the build directory. &#8220;WITH_GPU&#8221; controls if the generated production image supports GPU. &#8220;WITH_AVX&#8221; controls if the generated production image supports AVX. &#8220;WITH_TEST&#8221; controls if the unit test will be generated.</p>
<p>Then we can generate the production image by copying the compiled PaddlePaddle program into the image by</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  docker build -t paddle:prod -f build/Dockerfile .
</pre></div>
</div>
<p>Run unit test finally:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  docker run -it -v <span class="k">$(</span><span class="nb">pwd</span><span class="k">)</span>:/paddle paddle:dev bash -c <span class="s2">&quot;cd /paddle/build &amp;&amp; ctest&quot;</span>
</pre></div>
</div>
<p>For more details, you can read <a class="reference external" href="https://github.com/PaddlePaddle/Paddle/blob/develop/doc/getstarted/build_and_install/docker_install_en.rst">this doc</a>.</p>
</div>
<div class="section" id="commit">
<span id="commit"></span><h2>Commit<a class="headerlink" href="#commit" title="Permalink to this headline">¶</a></h2>
<p>Next we cancel the changes to the README.md file and then commit our changes by following command lines:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git checkout -- README.md
➜  git status
On branch <span class="nb">test</span>
Untracked files:
  <span class="o">(</span>use <span class="s2">&quot;git add &lt;file&gt;...&quot;</span> to include in what will be committed<span class="o">)</span>

    <span class="nb">test</span>

nothing added to commit but untracked files present <span class="o">(</span>use <span class="s2">&quot;git add&quot;</span> to track<span class="o">)</span>
➜  git add <span class="nb">test</span>
</pre></div>
</div>
<p>We should write a description of each commit by <code class="docutils literal"><span class="pre">git</span> <span class="pre">commit</span></code> to allow others to know
the changes in these files.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git commit
CRLF end-lines remover...............................<span class="o">(</span>no files to check<span class="o">)</span>Skipped
yapf.................................................<span class="o">(</span>no files to check<span class="o">)</span>Skipped
Check <span class="k">for</span> added large files..............................................Passed
Check <span class="k">for</span> merge conflicts................................................Passed
Check <span class="k">for</span> broken symlinks................................................Passed
Detect Private Key...................................<span class="o">(</span>no files to check<span class="o">)</span>Skipped
Fix End of Files.....................................<span class="o">(</span>no files to check<span class="o">)</span>Skipped
clang-formater.......................................<span class="o">(</span>no files to check<span class="o">)</span>Skipped
<span class="o">[</span>my-cool-stuff c703c041<span class="o">]</span> add <span class="nb">test</span> file
 <span class="m">1</span> file changed, <span class="m">0</span> insertions<span class="o">(</span>+<span class="o">)</span>, <span class="m">0</span> deletions<span class="o">(</span>-<span class="o">)</span>
 create mode <span class="m">100644</span> <span class="m">233</span>
</pre></div>
</div>
</div>
<div class="section" id="keeping-fork-up-to-date">
<span id="keeping-fork-up-to-date"></span><h2>Keeping Fork Up to Date<a class="headerlink" href="#keeping-fork-up-to-date" title="Permalink to this headline">¶</a></h2>
<p>Before pull your request, you should sync your code from the latest PaddlePaddle.
To do this, you&#8217;ll need to add a remote at first:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git remote add upstream https://github.com/PaddlePaddle/Paddle
➜  git remote
origin
upstream
</pre></div>
</div>
<p>Update your fork with the latest upstream changes:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git fetch upstream
➜  git pull upstream develop
</pre></div>
</div>
<p>Now, your local master branch is up-to-date with everything modified upstream.</p>
</div>
<div class="section" id="push-to-github">
<span id="push-to-github"></span><h2>Push to GitHub<a class="headerlink" href="#push-to-github" title="Permalink to this headline">¶</a></h2>
<div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># push to your repository in Github</span>
➜  git push origin my-cool-stuff
</pre></div>
</div>
</div>
<div class="section" id="create-an-issue-and-a-pull-request">
<span id="create-an-issue-and-a-pull-request"></span><h2>Create an issue and a Pull Request<a class="headerlink" href="#create-an-issue-and-a-pull-request" title="Permalink to this headline">¶</a></h2>
<p>Create an Issue to describe the problem and record its number.</p>
<p>Go to the page for your fork on GitHub, select your development branch,
and click the <code class="docutils literal"><span class="pre">New</span> <span class="pre">pull</span> <span class="pre">request</span></code>.</p>
<p><img width="295" alt="screen shot 2017-04-26 at 9 09 28 pm" src="https://cloud.githubusercontent.com/assets/11692045/25436054/a6d98c66-2ac4-11e7-9cb1-18dd13150230.png"></p>
<p>Then select the target branch:</p>
<p><img width="750" alt="screen shot 2017-04-26 at 9 11 52 pm" src="https://cloud.githubusercontent.com/assets/11692045/25436139/f83b1e6c-2ac4-11e7-8c0e-add499023c46.png"></p>
<p>We can add <code class="docutils literal"><span class="pre">resolve</span> <span class="pre">#Issue</span> <span class="pre">number</span></code> in PR description to close the issue automatically after the PR is merge. More details in <a class="reference external" href="https://help.github.com/articles/closing-issues-via-commit-messages/">https://help.github.com/articles/closing-issues-via-commit-messages/</a>.</p>
<p>Then wait for review, if there need to modify, refer to the above steps to update the corresponding origin branch.</p>
</div>
<div class="section" id="delete-origin-branch">
<span id="delete-origin-branch"></span><h2>Delete origin branch<a class="headerlink" href="#delete-origin-branch" title="Permalink to this headline">¶</a></h2>
<p>After the PR is merge into the main repository, we can delete the remote branch on the PR page.</p>
<p><img width="775" alt="screen shot 2017-04-26 at 9 18 24 pm" src="https://cloud.githubusercontent.com/assets/11692045/25436457/e4cdd472-2ac5-11e7-9272-badc76c4a23e.png"></p>
<p>Or just run:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git push origin :my-cool-stuff
</pre></div>
</div>
</div>
<div class="section" id="delete-local-branch">
<span id="delete-local-branch"></span><h2>Delete local branch<a class="headerlink" href="#delete-local-branch" title="Permalink to this headline">¶</a></h2>
<p>Finally, we delete local branch:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>➜  git checkout develop 

<span class="c1"># delete my-cool-stuff branch</span>
➜  git branch -D my-cool-stuff
</pre></div>
</div>
</div>
</div>


           </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../deep_model/rnn/index_en.html" class="btn btn-neutral float-right" title="RNN Models" accesskey="n">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <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 = {
            URL_ROOT:'../../',
            VERSION:'',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: ".txt",
        };
    </script>
      <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>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
       
  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  
  
  <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>
  <script src="../../_static/js/paddle_doc_init.js"></script> 

</body>
</html>