<!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 — 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>Folk 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> <li class="toctree-l1"><a class="reference internal" href="../../about/index_en.html">ABOUT</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/ubuntu_install_en.html">Debian Package installation guide</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">Run Distributed Training</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="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></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> <li class="toctree-l1"><a class="reference internal" href="../../about/index_en.html">ABOUT</a></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 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 WITH_STYLE_CHECK 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 “Fork” button. It’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>Paddle is currently using <a class="reference external" href="http://nvie.com/posts/a-successful-git-branching-model/">git-flow branching model</a>. The <strong>develop</strong> is the main branch, and other user’s branches are feature branches.</p> <p>Once you’ve created a fork, you can use your favorite git client to clone your repo or just head straight to the command line:</p> <div class="highlight-shell"><div class="highlight"><pre><span></span><span class="c1"># Clone your fork to your local machine</span> git clone --branch develop https://github.com/USERNAME/Paddle.git </pre></div> </div> <p>If your repository doesn’t contain <strong>develop</strong> branch, just create it by your own.</p> <div class="highlight-shell"><div class="highlight"><pre><span></span>git clone https://github.com/USERNAME/Paddle.git Paddle <span class="nb">cd</span> Paddle git checkout -b develop <span class="c1"># create develop branch.</span> git remote add upstream https://github.com/PaddlePaddle/Paddle.git <span class="c1"># add upstream to baidu/Paddle</span> git pull upstream develop <span class="c1"># update to upstream</span> </pre></div> </div> <p>Then you can start to develop by making a local developement branch</p> <div class="highlight-shell"><div class="highlight"><pre><span></span>git checkout -b MY_COOL_STUFF_BRANCH </pre></div> </div> </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’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>Then just run <code class="docutils literal"><span class="pre">pre-commit</span> <span class="pre">install</span></code> in your Paddle clone directory. 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="commit"> <span id="commit"></span><h2>Commit<a class="headerlink" href="#commit" title="Permalink to this headline">¶</a></h2> <p>Commit your changes by following command lines:</p> <div class="highlight-shell"><div class="highlight"><pre><span></span><span class="c1"># show the working tree status</span> git status <span class="c1"># add modified files</span> git add xx env <span class="nv">EDITOR</span><span class="o">=</span>vim git commit <span class="c1"># You can write your comments by vim/nano/emacs.</span> </pre></div> </div> <p>The first line of commit infomation is the title. The second and later lines are the details if any.</p> </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’ll need to add a remote at first:</p> <div class="highlight-shell"><div class="highlight"><pre><span></span><span class="c1"># see the current configured remote repository</span> git remote -v <span class="c1"># add upstream repository</span> git remote add upstream https://github.com/PaddlePaddle/Paddle.git <span class="c1"># verify the new upstream</span> git remote -v </pre></div> </div> <p>Update your fork with the latest upstream changes:</p> <div class="highlight-shell"><div class="highlight"><pre><span></span>git pull --rebase upstream develop </pre></div> </div> <p>If there are no unique commits locally, git will simply perform a fast-forward. However, if you have been making changes (in the vast majority of cases you probably shouldn’t be), you may have to deal with conflicts.</p> <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-shell"><div class="highlight"><pre><span></span><span class="c1"># push to your repository in Github</span> git push -u origin MY_COOL_STUFF_BRANCH <span class="c1"># create remote branch MY_COOL_STUFF_BRANCH to origin.</span> </pre></div> </div> </div> <div class="section" id="pull-request"> <span id="pull-request"></span><h2>Pull Request<a class="headerlink" href="#pull-request" title="Permalink to this headline">¶</a></h2> <p>Go to the page for your fork on GitHub, select your development branch, and click the <strong>pull request button</strong>.</p> </div> <div class="section" id="update-your-pull-request-with-the-lastest-version"> <span id="update-your-pull-request-with-the-lastest-version"></span><h2>Update your pull request with the lastest version<a class="headerlink" href="#update-your-pull-request-with-the-lastest-version" title="Permalink to this headline">¶</a></h2> <p>During the code review, your pull request may become stale because new commits in baidu/Paddle. GitHub allows autmotic update if there is no conflict. You can do this by clicking the “Update Branch” button in your pull request page. However, in the case of conflict, you need to do the update manually. You need to do the following on your local repository:</p> <div class="highlight-shell"><div class="highlight"><pre><span></span>git checkout MY_COOL_STUFF_BRANCH git pull upstream develop <span class="c1"># You may need to resolve the conflict according to the git prompt.</span> <span class="c1"># Make and test your code.</span> git push origin MY_COOL_STUFF_BRANCH </pre></div> </div> <p>Now your Pull Request is updated with the latest version.</p> </div> <div class="section" id="revise-your-pull-request"> <span id="revise-your-pull-request"></span><h2>Revise your pull request<a class="headerlink" href="#revise-your-pull-request" title="Permalink to this headline">¶</a></h2> <p>When you revise your pull request according to reviewer’s comments, please use ‘git commit’ instead of ‘git commit –amend’ to commit your changes so that the reviewers can see the difference between the new pull requrest and the old pull request.</p> <p>The possible commands are</p> <div class="highlight-shell"><div class="highlight"><pre><span></span>git checkout MY_COOL_STUFF_BRANCH git pull upstream develop <span class="c1"># update local to newest code base.</span> <span class="c1"># May be some conflicts will occured.</span> <span class="c1"># And develop your cool stuff</span> env <span class="nv">EDITOR</span><span class="o">=</span>vim git commit <span class="c1"># add your revise log</span> git push origin MY_COOL_STUFF_BRANCH </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> © 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>