<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yulia Zvyagelskaya</title>
    <description>The latest articles on DEV Community by Yulia Zvyagelskaya (@yzvyagelskaya).</description>
    <link>https://dev.to/yzvyagelskaya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93933%2F073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg</url>
      <title>DEV Community: Yulia Zvyagelskaya</title>
      <link>https://dev.to/yzvyagelskaya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yzvyagelskaya"/>
    <language>en</language>
    <item>
      <title>Your First Job In The Cloud / 3</title>
      <dc:creator>Yulia Zvyagelskaya</dc:creator>
      <pubDate>Sat, 25 Aug 2018 16:21:55 +0000</pubDate>
      <link>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud--3-28ka</link>
      <guid>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud--3-28ka</guid>
      <description>&lt;h2&gt;
  
  
  Chapter 1. The First Job In The Cloud
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uoBFnZmP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--X3Lunxj9--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/93933/073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud-4lcj" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 18 '18 ・ 5 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Chapter 2. Getting The Job Done
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uoBFnZmP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--X3Lunxj9--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/93933/073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud-2-4ob8" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud /2&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 19 '18 ・ 5 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Chapter 3. Let My Cloud Work
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;And I wrote my happy songs &lt;br&gt;
Every child may joy to hear&lt;br&gt;
— William Blake&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Splitting The Job Into Pieces
&lt;/h3&gt;

&lt;p&gt;In the previous chapter we had an environment prepared to launch our lovely job. The only thing left before we might let the ship sail freely would be to split the whole job into logical pieces. Why?&lt;/p&gt;

&lt;p&gt;Well, the things might go wrong. One might want to tune something on the last step. The cloud computing saves our laptop uptime but it costs money. In most cases while playing with our model parameters we do not need to start from the scratch redoing the whole bunch of preparation steps, like cleaning up text, splitting the input into train and test datasets and like.&lt;/p&gt;

&lt;p&gt;I would suggest to have following steps separated for text processing (for images or anything else that might differ, but the whole approach would still work.)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;drop all the unnecessary data and leave only that we are to process&lt;/li&gt;
&lt;li&gt;clean the input with sorta regular expressions&lt;/li&gt;
&lt;li&gt;split the input into train and test datasets&lt;/li&gt;
&lt;li&gt;train the model on train dataset&lt;/li&gt;
&lt;li&gt;check the model on test dataset&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  One By One
&lt;/h3&gt;

&lt;p&gt;My advise would be to split the script into several classes, each playing it’s own role. The files would also contain the &lt;code&gt;__main__&lt;/code&gt; section allowing to execute them as standalone scripts, accepting parameters that are relevant to that particular step.&lt;/p&gt;

&lt;h4&gt;
  
  
  Smaller Is Better
&lt;/h4&gt;

&lt;p&gt;The first step should be done &lt;em&gt;locally&lt;/em&gt; to decrease the size of the file we are going to upload. That saves us the time while uploading &lt;em&gt;and&lt;/em&gt; the size taken by the input data in our basket.&lt;/p&gt;

&lt;p&gt;For that one should simply load the CSV, get rid of all the unnecessary columns and save it back. That is it. The result should be copied to the bucket and all steps will be done in the cloud.&lt;/p&gt;

&lt;h4&gt;
  
  
  Janitor For The Rescue
&lt;/h4&gt;

&lt;p&gt;In most articles, books, talks on the subject people recommend to get rid of all the punctuation and to expand syntactic sugar (“I’d’ve been” ⇒ “I could have been”) to help the trainer to recognize same words. Most if not all propose the obsolete regular expression to do that.&lt;/p&gt;

&lt;p&gt;Texts in the Internets differ from those produced by typewriting machines. They are all use &lt;em&gt;unicode&lt;/em&gt; now. Nowadays the &lt;a href="https://en.wikipedia.org/wiki/Apostrophe"&gt;apostrophe&lt;/a&gt; might be both “'” typed by the lazy post author &lt;em&gt;and&lt;/em&gt; “’” if the creator of the text has a sense typographical beauty. The same is for quotes &lt;em&gt;' " ’ ”&lt;/em&gt;, dashes &lt;em&gt;- -- – –&lt;/em&gt;, numbers &lt;em&gt;1 2 ¹ ² ½&lt;/em&gt; and even ʟᴇᴛᴛᴇʀs 𝒾𝓃 𝓉𝒽𝑒 𝖆𝖗𝖙𝖎𝖈𝖑𝖊. And legacy regular expressions would not recognize all that zoo.&lt;/p&gt;

&lt;p&gt;Luckily enough, modern regular expressions have matchers that might match exactly what we need to semantically. Tose are called &lt;a href="https://en.wikipedia.org/wiki/Regular_expression#Character_classes"&gt;&lt;em&gt;Character Classes&lt;/em&gt;&lt;/a&gt; and might be used to match e. g. all the punctuation, or all the letters &lt;em&gt;and&lt;/em&gt; digits.&lt;/p&gt;

&lt;p&gt;For the text processing I would suggest to preserve only alphanumerics (letters and digits) and the punctuation. The latter should be unified (all the double quotes should be converted to typewriter double quotes, the same with single quotes and dashes.)&lt;/p&gt;

&lt;p&gt;After this is done, the list of shortened forms might be used to expand all &lt;em&gt;“I’m”_s to _“I am”_s etc. That is basically it. _Dump&lt;/em&gt; the result of this step to the bucket. Until the input data has changed, this step might be avoided in subsequent executions of model training process. I personally use &lt;em&gt;pickles&lt;/em&gt; for that, but the format does not absolutely matter.&lt;/p&gt;

&lt;h4&gt;
  
  
  Sibling Sets: Train And Test
&lt;/h4&gt;

&lt;p&gt;The common approach would be to split the dataset into to parts, one to train the model and another one to test it. Split &lt;em&gt;and&lt;/em&gt; save the result to the basket. This process usually takes a few parameters, like &lt;em&gt;padding&lt;/em&gt; and &lt;em&gt;max-words&lt;/em&gt; which are rarely changed. Chances are you would not tweak them very often.&lt;/p&gt;

&lt;p&gt;Save the result.&lt;/p&gt;

&lt;h4&gt;
  
  
  Train The Model
&lt;/h4&gt;

&lt;p&gt;Train the model. Make sure you log everything &lt;em&gt;to the logger&lt;/em&gt;, not to standard output to preserve logs of the process. I usually use &lt;code&gt;logging.info&lt;/code&gt; for debugging message and &lt;code&gt;logging.warn&lt;/code&gt; for iportant ones I want to be reported. Google ML Log Viewer allows to filter out log messages by severity and later one might have a glance at &lt;em&gt;important&lt;/em&gt; stuff only.&lt;/p&gt;

&lt;p&gt;Save the model.&lt;/p&gt;

&lt;h4&gt;
  
  
  Check It
&lt;/h4&gt;

&lt;p&gt;I do check in the cloud as well. Later on one might download the model to local and use the testset saved in the step 3 to test it, but I am fine with examining logs in the cloud.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Summing Up
&lt;/h3&gt;

&lt;p&gt;If you are like me and had the steps put into classes, the resulting &lt;code&gt;__main__&lt;/code&gt; of the package that will be run in the cloud would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# parse all the arguments
&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'janitize'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;Janitor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remote_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'split'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;Splitter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keep_n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'keep_n'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remote_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'train'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Modeller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;train_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remote_dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'check'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="n"&gt;Modeller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;check_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remote_dir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is all I wanted to share for now. Happy clouding!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>tutorial</category>
      <category>cloudcomputing</category>
    </item>
    <item>
      <title>Your First Job In The Cloud /2</title>
      <dc:creator>Yulia Zvyagelskaya</dc:creator>
      <pubDate>Sun, 19 Aug 2018 09:00:02 +0000</pubDate>
      <link>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud-2-4ob8</link>
      <guid>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud-2-4ob8</guid>
      <description>&lt;h2&gt;
  
  
  Chapter 1. The First Job In The Cloud
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93933%2F073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud-4lcj" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 18 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Chapter 2. Getting The Job Done
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Hear the voice of the Bard!&lt;br&gt;
— William Blake&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Setting Up Packages
&lt;/h3&gt;

&lt;p&gt;In the end of the &lt;a href="https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud-4lcj"&gt;Chapter 1&lt;/a&gt; we were able to run a job in the cloud. It was completed successfully (if not, please blame Google, not me.) We’ve seen this fascinating green light icon next to it. Let’s now try the real job‽&lt;/p&gt;

&lt;p&gt;Not yet. We are not mature enough to enter a cage with lions. Let’s do it step by step.&lt;/p&gt;

&lt;p&gt;I assume you have the code—that apparently trains a model—on hand. Unlike other tutorials, this one won’t provide a code training model for you. We are talking about deployment to &lt;em&gt;ML Engine&lt;/em&gt;. Sorry for that.&lt;/p&gt;

&lt;p&gt;This code probably has a bundle of &lt;code&gt;import&lt;/code&gt;s. It probably requires &lt;code&gt;Tensorflow&lt;/code&gt;, &lt;code&gt;Keras&lt;/code&gt; and some other packages that are not included into python standard library. If all you imported was &lt;code&gt;Tensorflow&lt;/code&gt; and the whole rest was written by you, you barely need this tutorial. Such a brave person should wade through everything on their own.&lt;/p&gt;

&lt;p&gt;So, yeah. Packages. Copy all the &lt;code&gt;import&lt;/code&gt; lines from all your files to the top of the job scaffold we have created in the &lt;em&gt;Chapter 1&lt;/em&gt; (“Our First Job” section, I struggled to find how do I do an anchor to the subtitle inside the post here.)&lt;/p&gt;

&lt;p&gt;Submit a job to the cloud. Go check logs in approximately 8 minutes to see that the task has failed. If it has not, I envy you, you seem to use only standard packages included into &lt;em&gt;ML Engine&lt;/em&gt; setup by default. I was not as lucky. Google includes the very limited set of packages (probably to reduce the docker launch time.)&lt;/p&gt;

&lt;p&gt;So, we need to demand the additional packages we need explicitly. Unfortunately, AFAICT, there is no way to retrieve a diff between what &lt;em&gt;ML Engine&lt;/em&gt; provides out of the box and what we need, So we are obliged to add them one by one, submit job, check logs, cry, yell at the sky, repeat. To add packages, open the file &lt;code&gt;setup.py&lt;/code&gt; we have created in the &lt;em&gt;Chapter 1&lt;/em&gt; and add the following lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; from setuptools import find_packages
 from setuptools import setup
&lt;span class="err"&gt;
&lt;/span&gt; setup(
     name='test1',
     version='0.1',
&lt;span class="gi"&gt;+    install_requires=['scikit-learn&amp;gt;=0.18','annoy&amp;gt;=1.12','nltk&amp;gt;=3.2'],
+    packages=find_packages(),
+    include_package_data=True,
&lt;/span&gt;     description='My First Job'
 )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Keep adding entries in &lt;code&gt;install_requires&lt;/code&gt; until &lt;em&gt;ML Engine&lt;/em&gt; is satisfied and the job turns back to successful processing. It might happen, that some packages you need were designed for python younger than &lt;code&gt;3.5&lt;/code&gt; (in my case it was the package that used fancy new string formatting &lt;code&gt;f'Hi, {name}'&lt;/code&gt;, introduced in &lt;code&gt;3.6&lt;/code&gt;. I did not find better solution, rather than download this package locally, backport it to &lt;code&gt;3.5&lt;/code&gt; and re-package it myself. Build the package and put it both into your bucket (I have created a subfolder &lt;code&gt;packages&lt;/code&gt; there for that purpose) &lt;em&gt;and&lt;/em&gt; the same folder with &lt;code&gt;setup.py&lt;/code&gt; script. Now we have to tell &lt;em&gt;ML Engine&lt;/em&gt; to use our version of it. Update your shell script with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;     --module-name test1.test1 \
     --package-path ./test1 \
&lt;span class="gi"&gt;+    --packages my_package-0.1.2.tar.gz \
&lt;/span&gt;     --config=test1/test1.yaml \
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The same should be done with all your own packages you need to include into the distribution to run a job. The &lt;code&gt;install_packages&lt;/code&gt; parameter in call to &lt;code&gt;setup&lt;/code&gt; in &lt;code&gt;setup.py&lt;/code&gt; has to be updated accordingly. Also, update your cloud config with &lt;code&gt;packageUris&lt;/code&gt; parameter:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;trainingInput&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;scaleTier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CUSTOM&lt;/span&gt;
  &lt;span class="na"&gt;masterType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;complex_model_m_gpu&lt;/span&gt;
  &lt;span class="na"&gt;pythonVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.5"&lt;/span&gt;
  &lt;span class="na"&gt;runtimeVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1.9"&lt;/span&gt;
  &lt;span class="na"&gt;packageUris&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;gs://foo-bar-baz-your-bucket-name/packages/my_package-0.1.2.tar.gz'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Submit a job and check that the job is now green.&lt;/p&gt;
&lt;h3&gt;
  
  
  Doing Their Job
&lt;/h3&gt;

&lt;p&gt;Not all 3rd party packages are ready to be used in cloud. It’s the very same machine as our own laptop, but virtual, so everything should be the same, right?—Well, yes and no. Everything is the same. But this VM is shut down as the job finishes. Meaning if we need some results besides logs (like a trained model file, you know,) we have to &lt;em&gt;store&lt;/em&gt; it somewhere outside of the container where this job was run, otherwise it’ll die together with the container. &lt;/p&gt;

&lt;p&gt;Python standard &lt;code&gt;open(file_name, mode)&lt;/code&gt; does not work with buckets (&lt;code&gt;gs://...../file_name&lt;/code&gt;). One needs to &lt;code&gt;from tensorflow.python.lib.io import file_io&lt;/code&gt; and change all calls to &lt;code&gt;open(file_name, mode)&lt;/code&gt; to &lt;code&gt;file_io.FileIO(file_name, mode=mode)&lt;/code&gt; (note the named mode parameter.) The interface of the opened handle is the same.&lt;/p&gt;

&lt;p&gt;Some 3rd party packages have an explicit &lt;code&gt;save&lt;/code&gt; method, accepting the file name instead of &lt;code&gt;FileIO&lt;/code&gt; and the only possibility would be to &lt;em&gt;copy&lt;/em&gt; it to the bucket afterwards. I did not manage to use &lt;em&gt;Google SDK&lt;/em&gt; for that, since it is absent in containers, so here is the tiny snippet copying the file from the container to the bucket.&lt;/p&gt;

&lt;p&gt;The code below is quite inefficient, because it loads the whole model at once and then dumps it to the bucket, but it worked for me for relatively small models:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;file_io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FileIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rb&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;i_f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;file_io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FileIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_dir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wb+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;o_f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;o_f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i_f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The mode must be set to binary for both reading and writing. When the file is relatively big, it makes sense to read and write it in chunks to decrease memory consumption, but chunking files on binary IO read operations seems to be a bit out of scope of this tutorial. I recommend to wrap this into the function and call this function as needed. &lt;/p&gt;

&lt;p&gt;Now, when we have all the needed packages installed, and the function to store files in the bucket on hand, there is nothing preventing us from trying our model in the cloud with a whole load of the data in the cloud. Right?&lt;/p&gt;

&lt;p&gt;Nope. I strongly suggest to split the job into smaller steps, like “cleaning up,” “splitting into training and testing sets,” “preprocessing,” “training,” etc and &lt;em&gt;dump all the intermediate results to the bucket&lt;/em&gt;. Since you needed a training process to be run in the cloud, it should be very time consuming. Having the intermediate results on hand might save you a lot of time in the future. For instance, adjusting the parameters given to the train process itself does not require all the preparation steps to be re-run. In such a case we might just start with &lt;em&gt;Step N&lt;/em&gt;, using the output from the previous step that was dumped before as the input.&lt;/p&gt;

&lt;p&gt;How to do it, I will show in the next chapter. Happy clouding!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93933%2F073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud--3-28ka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud / 3&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 25 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>machinelearning</category>
      <category>tutorial</category>
      <category>cloudcomputing</category>
    </item>
    <item>
      <title>Your First Job In The Cloud</title>
      <dc:creator>Yulia Zvyagelskaya</dc:creator>
      <pubDate>Sat, 18 Aug 2018 16:34:51 +0000</pubDate>
      <link>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud-4lcj</link>
      <guid>https://dev.to/yzvyagelskaya/your-first-job-in-the-cloud-4lcj</guid>
      <description>&lt;h2&gt;
  
  
  Chapter 1. The First Job In The Cloud
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;On a cloud I saw a child,&lt;br&gt;
And he laughing said to me: “...&lt;br&gt;
— William Blake&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nowadays one should live in a cave on an uninhabited island lost in Arctic ocean to have never heard of “Artificial Intelligence,” “Machine Learning,” “NLP” and the family of buzzwords. Having a masters in Data Science, I feel a bit less excited about tomorrow’s AI revolution. That does not mean &lt;em&gt;DS&lt;/em&gt; is boring or undue—rather it requires a lot of effort to be put into and I really like that feeling of being doing stuff on the bleeding edge.&lt;/p&gt;

&lt;p&gt;As a relatively new industry, ML has not set up the &lt;em&gt;processes&lt;/em&gt; yet. I have heard something opposite about Google and Facebook, but we are still considered nerds in small businesses. The role developers used to play twenty years ago. That’s great to see that more and more people are getting into ML, either being excited by Google slides on a last conference, or just being curious whether the neural nets can indeed distinguish between cats and dogs seen on a photo.&lt;/p&gt;

&lt;p&gt;Big corps prepare and &lt;em&gt;share&lt;/em&gt; (thanks God it’s XXI century) huge datasets, trained models and everything the junior data scientist might use to play in the sandbox. After we made sure that models trained on Google or Facebook data somehow work and even might predict things (in some cases under some very eccentric circumstances, but it’s still &lt;em&gt;so&lt;/em&gt; thrilling,) we usually want to try to train our own model ourselves. It takes hours on our own laptop, even despite the dataset is limited to tweets from our forty two friends for the last single year. Results usually look &lt;em&gt;promising&lt;/em&gt;, but unsatisfactory. There is no way the laptop could proceed with &lt;em&gt;the whole tweet feed for the last decade&lt;/em&gt; without exploding the SDD and blowing up. &lt;/p&gt;

&lt;p&gt;That is the time we get to the magical words: cloud calculus. Or how do you name it. Let’s Google servers do explode instead of our lovely laptops, right? Right. Our next job will be in the cloud. Pun intended.&lt;/p&gt;

&lt;p&gt;There are not that many resources, explaining how one might stop procrastinating starring at the laptop monitor for when the model is built and start getting benefits of living in the 2018 AD. There are Google ML, Amazon SageMaker, Azure Machine Learning Studio, but the documentation everywhere was written by developers for gray-bearded geeks. There is an enormous threshold to execute the very first job in the cloud. And this writing is supposed to bridge that gap.&lt;/p&gt;

&lt;p&gt;That is not a rocket science and there is nothing really complex. Just few steps to make and several things to take into consideration. That’s the breathtaking journey and once done, the subsequent trips will seem a cakewalk. Let’s go.&lt;/p&gt;

&lt;p&gt;All the below is written for Google ML Engine, but it might be applied to any cloud computing system almost as is. I will try not to go deeply into details, concentrating more on &lt;em&gt;whats&lt;/em&gt; rather than on &lt;em&gt;hows&lt;/em&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Before We Start
&lt;/h3&gt;

&lt;p&gt;First of all, I want to reference the paper that helped me a lot to move my job into the cloud. &lt;a href="https://liufuyang.github.io/2017/04/02/just-another-tensorflow-beginner-guide-4.html" rel="noopener noreferrer"&gt;Tensorflow beginner guide&lt;/a&gt; by Fuyang Liu's Blog is almost perfect, save for it does not cover pitfalls and does not suggest shortpaths where it could have made sense.&lt;/p&gt;

&lt;p&gt;Google also has a &lt;a href="https://cloud.google.com/ml-engine/docs/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; on ML Engine, I wish I were as smart as to use it &lt;em&gt;as a guide&lt;/em&gt;. We still need it though to quickly look up this and that.&lt;/p&gt;

&lt;p&gt;First we need to &lt;a href="https://cloud.google.com/ml-engine/docs/tensorflow/getting-started-training-prediction#setup" rel="noopener noreferrer"&gt;set up our cloud environment&lt;/a&gt;. I refer to Google guide here because things tend to change within time and I hope they will keep this info up-to-date.&lt;/p&gt;

&lt;p&gt;After we have the account enabled for ML, we should set up our local environment. I strongly advise using Linux, MacOS is more or less robust, Windows will make you cry. Once we are to run jobs in the cloud, I believe you have python installed and configured. What we need to install is &lt;a href="https://cloud.google.com/sdk/docs/" rel="noopener noreferrer"&gt;Google SDK&lt;/a&gt;. It’s pretty straightforward though, download it from the page linked and install.&lt;/p&gt;

&lt;p&gt;Now we need to setup our credentials. &lt;a href="https://cloud.google.com/sdk/docs/initializing" rel="noopener noreferrer"&gt;&lt;code&gt;gcloud init&lt;/code&gt;&lt;/a&gt; should do.&lt;/p&gt;

&lt;p&gt;Let’s check it works as expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud ml-engine models list
Listed 0 items.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Wow. We are all set.&lt;/p&gt;
&lt;h3&gt;
  
  
  Our First Job
&lt;/h3&gt;

&lt;p&gt;That is the important part. Don’t try to upload and run your fancy last project. It’ll fail and you’ll get frustrated. Let’s enter cold water slowly. Let’s make your first job completed successfully, showing a fascinating green light icon when you’ll check your jobs status.&lt;/p&gt;

&lt;p&gt;The cloud expects the python package to be uploaded and the main module to execute it specified. So, let’s go with a pretty simple python package. Let’s assume it’s named &lt;code&gt;test1.py&lt;/code&gt; and resides in the directory named &lt;code&gt;test1&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# coding: utf-8
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;--job-dir&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;GCS job directory (required by GoogleML)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;--arg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Test argument&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;required&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;arguments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;__dict__&lt;/span&gt;
  &lt;span class="n"&gt;job_dir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;job_dir&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;arg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;arg&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hey, ML Engine, you are not scary!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  
  &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Argument received: {}.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We use &lt;code&gt;logging&lt;/code&gt; because unlike simple &lt;code&gt;stdout&lt;/code&gt; logs are available through the web interface.&lt;/p&gt;

&lt;p&gt;Also you’ll need a cloud configuration file on your local. It might be placed everywhere, I prefer to have a config file per project. Put &lt;code&gt;test1.yml&lt;/code&gt; in the same directory:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;trainingInput&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;scaleTier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CUSTOM&lt;/span&gt;
  &lt;span class="c1"&gt;# 1 GPU&lt;/span&gt;
  &lt;span class="na"&gt;masterType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;standard_gpu&lt;/span&gt;
  &lt;span class="c1"&gt;# 4 GPUs&lt;/span&gt;
  &lt;span class="c1"&gt;# complex_model_m_gpu&lt;/span&gt;
  &lt;span class="na"&gt;runtimeVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1.9"&lt;/span&gt;
  &lt;span class="na"&gt;pythonVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.5"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I am not sure who took that decision, but the default &lt;code&gt;python&lt;/code&gt; version &lt;em&gt;for ML Engine&lt;/em&gt; is &lt;code&gt;2.7&lt;/code&gt;, that’s why two last lines are mandatory. &lt;/p&gt;

&lt;p&gt;Also you would need to create a file &lt;code&gt;setup.py&lt;/code&gt;, containing the description of our project. It will be processed by Google SDK.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;setuptools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;find_packages&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;setuptools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;setup&lt;/span&gt;

&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;test1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0.1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;My First Job&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Well, that is it. Let’s try (this file &lt;code&gt;test1.sh&lt;/code&gt; should be on the same level as the package folder.)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;BUCKET_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;foo-bar-baz-your-bucket-name
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;REGION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east1
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;JOB_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"test1_&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt; +%Y%m%d_%H%M%S&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;JOB_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;gs://&lt;span class="nv"&gt;$BUCKET_NAME&lt;/span&gt;/&lt;span class="nv"&gt;$JOB_NAME&lt;/span&gt;

gcloud ml-engine &lt;span class="nb"&gt;jobs &lt;/span&gt;submit training &lt;span class="nv"&gt;$JOB_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--staging-bucket&lt;/span&gt; gs://&lt;span class="nv"&gt;$BUCKET_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--job-dir&lt;/span&gt; gs://&lt;span class="nv"&gt;$BUCKET_NAME&lt;/span&gt;/&lt;span class="nv"&gt;$JOB_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--region&lt;/span&gt; &lt;span class="nv"&gt;$REGION&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--runtime-version&lt;/span&gt; 1.9 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--module-name&lt;/span&gt; test1.test1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--package-path&lt;/span&gt; ./test1 &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;test1/test1.yaml &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--arg&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;NB!&lt;/strong&gt; you have to specify your bucket name &lt;em&gt;and&lt;/em&gt; you might need to change the region as well.&lt;/p&gt;

&lt;p&gt;I strongly advise to create a shell script to run (schedule/queue) a job from the very beginning. It’s much easier to tackle with when it comes to modifications.&lt;/p&gt;

&lt;p&gt;There are three ‘subsections’ of arguments there: first four are job-specific and remain unchanged from job to job. The second is job-specific settings. The third one (after &lt;code&gt;--&lt;/code&gt;) contains argument that will be passed to the &lt;code&gt;__main__&lt;/code&gt; function of your package.&lt;/p&gt;

&lt;p&gt;Go try it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./test1.sh

Job &lt;span class="o"&gt;[&lt;/span&gt;test1_20180818_085812] submitted successfully.
Your job is still active. You may view the status of your job with the &lt;span class="nb"&gt;command&lt;/span&gt;

  &lt;span class="nv"&gt;$ &lt;/span&gt;gcloud ml-engine &lt;span class="nb"&gt;jobs &lt;/span&gt;describe test1_20180818_085812

or &lt;span class="k"&gt;continue &lt;/span&gt;streaming the logs with the &lt;span class="nb"&gt;command&lt;/span&gt;

  &lt;span class="nv"&gt;$ &lt;/span&gt;gcloud ml-engine &lt;span class="nb"&gt;jobs &lt;/span&gt;stream-logs test1_20180818_085812
jobId: test1_20180818_085812
state: QUEUED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now you might execute &lt;code&gt;gcloud ml-engine jobs describe ...&lt;/code&gt; as suggested. It’ll spit out another portion of text. Copy the last link and paste in into your browser address line. You should see...&lt;/p&gt;

&lt;p&gt;What should you see there I will describe in the next chapter. Happy clouding!&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93933%2F073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud-2-4ob8" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud /2&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 19 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="/yzvyagelskaya" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93933%2F073781bc-e97a-4286-92b4-7fd1d04cf6d3.jpg" alt="yzvyagelskaya"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/yzvyagelskaya/your-first-job-in-the-cloud--3-28ka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Your First Job In The Cloud / 3&lt;/h2&gt;
      &lt;h3&gt;Yulia Zvyagelskaya ・ Aug 25 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#machinelearning&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#cloudcomputing&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



</description>
      <category>machinelearning</category>
      <category>tutorial</category>
      <category>cloudcomputing</category>
    </item>
  </channel>
</rss>
