GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — nbdev/docs/tutorial_colab.html at master · SpectrumIO/nbdev Expand file tree/ Copy pathtutorial_colab.htmlMore file actions 497 lines (393 loc) · 16.7 KB / Copy pathtutorial_colab.htmlFile metadata and controls497 lines (393 loc) · 16.7 KB 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 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 325 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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 --- title: Title keywords: fastai sidebar: home_sidebar nb_path: "nbs/tutorial_colab.ipynb" --- <!-- ################################################# ### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ### ################################################# # file to edit: nbs/tutorial_colab.ipynb # command to build the docs after a change: nbdev_build_docs --> <div class="container" id="notebook-container"> {% raw %} <div class="cell border-box-sizing code_cell rendered"> </div> {% endraw %} {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="c1">#colab</span> </pre></div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Introduction">Introduction<a class="anchor-link" href="#Introduction"> </a></h2><p>In this tutorial we are going to complete an entire <code>nbdev</code>-based project from start to finish utilizing only <a href="colab.research.google.com">Google Colaboratory</a>, a free* alternative Jupyter environment with GPU capabilities. The goal is to set your project up in such a way that building, generating notebooks, testing, and setup is as seamless as possible inside their platform.</p> <p>This tutorial is also available as a video, which you can watch below:</p> <p>blah</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Why-Use-Google-Colaboratory?">Why Use Google Colaboratory?<a class="anchor-link" href="#Why-Use-Google-Colaboratory?"> </a></h2><p>Google Colaboratory offers a few unique advantages over other platforms in regards to the capabilities you can utilize:</p> <ol> <li><p>You can have synchronous programming within the same notebook</p> <p>When working in a team or in a pair-programming situation, you both can have the exact same Jupyter notebook open and synchronously write comments or code within it when your project is based out of your Google Drive. Other platforms have only recently been testing this capability</p> </li> <li><p>Smaller projects that don't require git can still be utilized</p> <p>There are certainly situations where perhaps you (or the company you work for) don't see the benefit yet in storing your code away in a repository. Simply keeping it in your Google Drive offers you this flexibility, while losing almost none of the benefits of GitHub.</p> </li> <li><p>It's free*</p> <p>Whether you're a student or someone who worries about your GPU credits, Google Colaboratory has a free option for you to utilize both Jupyter and GPU's without requiring a credit card to get started. Recently Google has released a <a href="https://colab.research.google.com/signup">Colab Pro</a> option for $10/month (only for the US and Canada right now), which allows for better access to GPU's and an in-house terminal, but neither of these are truly needed to get you utilizing Colab for <code>nbdev</code> and your software engineering projects!</p> </li> </ol> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Using-the-Template-Repository">Using the Template Repository<a class="anchor-link" href="#Using-the-Template-Repository"> </a></h2> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Now let's build a library!</p> <p>The first step in beginning your new nbdev project should be to use the <a href="https://github.com/fastai/nbdev_template">nbdev_template</a> that fastai provides.</p> <p>To start your project, select "Use this template":</p> <p><img src="https://i.imgur.com/TNtaJvQ.jpg" alt="Use this template"></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>From there you will be asked for:</p> <ol> <li>A Repository name - for this tutorial we'll call it "nbdev_colab_tutorial"</li> <li>Whether the repository will be public or private - for this tutorial use Public</li> <li>After filling out the above fields select "Create repository from template"</li> </ol> <p><img src="https://i.imgur.com/uhlWiPe.jpg" alt=""></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>After a few seconds your repository should now be live.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>The last step we need to complete for initializing our repository is filling out the <code>settings.ini</code> (You may have received an email notice stating that a run failed, this is why). Open it in your repository:</p> <p><img src="https://i.imgur.com/I18OJmk.jpg" alt=""></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>We need to edit this file with everything that nbdev needs to be properly configured</p> <blockquote><p>Read more on settings.ini <a href="https://nbdev.fast.ai/tutorial.html#Edit-settings.ini">here</a> You'll see these commented out lines in <code>settings.ini</code>. Uncomment them, and set each value as needed.</p> </blockquote> <pre><code># lib_name = your_project_name # user = your_github_username # description = A description of your project # keywords = some keywords # author = Your Name # author_email = [email protected] # copyright = Your Name or Company Name</code></pre> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Afterwards hit the "Commit changes" button at the bottom of the editor:</p> <p><img src="https://i.imgur.com/qVqcIiH.jpg" alt=""></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Now we can get started over in Colab!</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Setting-up-your-Google-Drive-and-Git-Configuration">Setting up your Google Drive and Git Configuration<a class="anchor-link" href="#Setting-up-your-Google-Drive-and-Git-Configuration"> </a></h2><p>For this next step we are going to take advantage of Colab's <a href="https://colab.research.google.com/notebooks/empty.ipynb">Scratchpad</a> notebook, as we're going to do a few housekeeping steps that don't need to be logged in a notebook somewhere.</p> <p>First you should mount your Google Drive in your instance by running the following cell and following the prompt:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">google.colab</span> <span class="kn">import</span> <span class="n">drive</span> <span class="n">drive</span><span class="o">.</span><span class="n">mount</span><span class="p">(</span><span class="s1">'/content/drive'</span><span class="p">)</span> </pre></div> </div> </div> </div> <div class="output_wrapper"> <div class="output"> <div class="output_area"> <div class="output_subarea output_stream output_stdout output_text"> <pre>Mounted at /content/drive </pre> </div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Your drive is now located at <code>/content/drive/MyDrive</code></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Next we need to change our working directory into our Google Drive, as this is where our repository will get saved to and where we can setup git</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">cd</span> drive/MyDrive </pre></div> </div> </div> </div> <div class="output_wrapper"> <div class="output"> <div class="output_area"> <div class="output_subarea output_stream output_stdout output_text"> <pre>/content/drive/MyDrive </pre> </div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Now we can clone our repository into our Drive:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>git clone https://github.com/<span class="o">{</span>insert_username_here<span class="o">}</span>/nbdev_colab_tutorial </pre></div> </div> </div> </div> <div class="output_wrapper"> <div class="output"> <div class="output_area"> <div class="output_subarea output_stream output_stdout output_text"> <pre>Cloning into 'nbdev_colab_tutorial'... remote: Enumerating objects: 25, done. remote: Counting objects: 100% (25/25), done. remote: Compressing objects: 100% (22/22), done. remote: Total 25 (delta 3), reused 13 (delta 0), pack-reused 0 Unpacking objects: 100% (25/25), done. </pre> </div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>We need to change directories again into our project:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">%</span><span class="k">cd</span> nbdev_colab_tutorial </pre></div> </div> </div> </div> <div class="output_wrapper"> <div class="output"> <div class="output_area"> <div class="output_subarea output_stream output_stdout output_text"> <pre>/content/drive/MyDrive/nbdev_colab_tutorial </pre> </div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>To let git know who we are, we need to run two bash commands:</p> <ul> <li><code>git config user.name</code></li> <li><code>git config user.email</code></li> </ul> <p>Let's do so:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>git config user.name <span class="s2">"Your name"</span> </pre></div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Lastly we need to export the template <code>00_core</code> notebook so that we have a module:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>nbdev_build_lib </pre></div> </div> </div> </div> <div class="output_wrapper"> <div class="output"> <div class="output_area"> <div class="output_subarea output_stream output_stdout output_text"> <pre>Converted 00_core.ipynb. Converted index.ipynb. </pre> </div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>The project has now been completely primed and is ready to be worked on</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Writing-a-New-Module-and-the-Setup-Cell-for-Each-Notebook">Writing a New Module and the Setup Cell for Each Notebook<a class="anchor-link" href="#Writing-a-New-Module-and-the-Setup-Cell-for-Each-Notebook"> </a></h2> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>To add in a new module or notebook to your library you should create a new Colab notebook through your Google Drive in whichever folder your notebooks are stored in.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>From there all that is needed is for you to run a small cell that should be at the top of each notebook, setting up your Colab environment and performs the following setup steps:</p> <ol> <li>Mount Google Drive</li> <li>Change to the library directory</li> <li>Installs the library</li> <li>Installs nbdev</li> </ol> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="kn">from</span> <span class="nn">google.colab</span> <span class="kn">import</span> <span class="n">drive</span> <span class="n">drive</span><span class="o">.</span><span class="n">mount</span><span class="p">(</span><span class="s1">'/content/drive'</span><span class="p">)</span> <span class="o">%</span><span class="k">cd</span> 'drive/MyDrive/{path_to_repository}/{library_name}' <span class="o">!</span>pip3 install -e . -q <span class="o">!</span>pip3 install nbdev -q </pre></div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>From there you can build your library following the <a href="https://nbdev.fast.ai/tutorial.html">tutorial</a>. Any changes you save in your notebook are reflected in your Google Drive, so you can always call <a href="/export2html.html#nbdev_build_lib"><code>nbdev_build_lib</code></a>, <code>_clean_nbs</code>, etc and have it function as expected.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h2 id="Pushing-to-Git">Pushing to Git<a class="anchor-link" href="#Pushing-to-Git"> </a></h2> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>The last step is pushing our changes to GitHub. We can check in our files to our GitHub repo with the following commands:</p> </div> </div> </div> {% raw %} <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>git add * <span class="o">!</span>git commit -m <span class="s2">"Test commit message"</span> <span class="o">!</span>git push origin master </pre></div> </div> </div> </div> </div> {% endraw %} <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>{% include note.html content='If you have Colab Pro, use the terminal to push to git with the same bash commands' %}</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>And that's it! You now know how to run <code>nbdev</code> entirely out of your Google Drive and Google Colaboratory.</p> </div> </div> </div> </div> |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |