forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lai, Weijian <laiweijian4@huawei.com> Co-committed-by: Lai, Weijian <laiweijian4@huawei.com>
52 lines
10 KiB
HTML
52 lines
10 KiB
HTML
<a name="EN-US_TOPIC_0000002079176553"></a><a name="EN-US_TOPIC_0000002079176553"></a>
|
|
|
|
<h1 class="topictitle1">Using a Custom Image</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000002079176553__en-us_topic_0000001309847669_p141811948914">The subscribed algorithms and preset images can be used in most training scenarios. In certain scenarios, ModelArts allows you to create custom images to train models.</p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p13800114115614">Customizing an image requires a deep understanding of containers. Use this method only if the subscribed algorithms and preset images cannot meet your requirements. Custom images can be used to train models in ModelArts only after they are uploaded to the Software Repository for Container (SWR).</p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p82697161540">You can use custom images for training on ModelArts in either of the following ways:</p>
|
|
<ul id="EN-US_TOPIC_0000002079176553__ul16641714113517"><li id="EN-US_TOPIC_0000002079176553__li106481453515">Using a preset image with customization<p id="EN-US_TOPIC_0000002079176553__p93211388556"><a name="EN-US_TOPIC_0000002079176553__li106481453515"></a><a name="li106481453515"></a>If you use a preset image to create a training job and you need to modify or add some software dependencies based on the preset image, you can customize the preset image. In this case, select a preset image and choose <strong id="EN-US_TOPIC_0000002079176553__b1720517572437">Customize</strong> from the framework version drop-down list box.</p>
|
|
</li></ul>
|
|
<ul id="EN-US_TOPIC_0000002079176553__ul5448016153513"><li id="EN-US_TOPIC_0000002079176553__li134481016193513">Using a custom image<p id="EN-US_TOPIC_0000002079176553__p92638351712"><a name="EN-US_TOPIC_0000002079176553__li134481016193513"></a><a name="li134481016193513"></a>You can create an image based on the ModelArts image specifications, select your own image and configure the code directory (optional) and boot command to create a training job.</p>
|
|
</li></ul>
|
|
<div class="section" id="EN-US_TOPIC_0000002079176553__section1788415252561"><h4 class="sectiontitle">Using a Preset Image with Customization</h4><p id="EN-US_TOPIC_0000002079176553__p7361194205716">The only difference between this method and creating a training job totally based on a preset image is that you must select an image. You can create a custom image based on a preset image. </p>
|
|
<div class="fignone" id="EN-US_TOPIC_0000002079176553__fig864910191115"><span class="figcap"><b>Figure 1 </b>Creating an algorithm using a preset image with customization</span><br><span><img id="EN-US_TOPIC_0000002079176553__image479017177463" src="figure/en-us_image_0000002079176661.png" width="469.49" height="177.34220000000002" title="Click to enlarge" class="imgResize"></span></div>
|
|
<p id="EN-US_TOPIC_0000002079176553__p196490010113"></p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p1778971295315">The process of this method is the same as that of creating a training job based on a preset image. For example:</p>
|
|
<ul id="EN-US_TOPIC_0000002079176553__en-us_topic_0000001133351332_en-us_topic_0000001071986951_ul179321959191811"><li id="EN-US_TOPIC_0000002079176553__li20885122044411">The system automatically injects environment variables.<ul id="EN-US_TOPIC_0000002079176553__ul738510217442"><li id="EN-US_TOPIC_0000002079176553__li799343724117">PATH=${MA_HOME}/anaconda/bin:${PATH}</li><li id="EN-US_TOPIC_0000002079176553__li8698440184415">LD_LIBRARY_PATH=${MA_HOME}/anaconda/lib:${LD_LIBRARY_PATH}</li><li id="EN-US_TOPIC_0000002079176553__li252093815457">PYTHONPATH=${MA_JOB_DIR}:${PYTHONPATH}</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000002079176553__li18239171385120">The selected boot file will be automatically started using Python commands. Ensure that the Python environment is correct. The <strong id="EN-US_TOPIC_0000002079176553__b1492745020451">PATH</strong> environment variable is automatically injected. Run the following commands to check the Python version for the training job:<ul id="EN-US_TOPIC_0000002079176553__ul3665171314511"><li id="EN-US_TOPIC_0000002079176553__li139881064514">export MA_HOME=/home/ma-user; docker run --rm {image} ${MA_HOME}/anaconda/bin/python -V</li><li id="EN-US_TOPIC_0000002079176553__li78331854125119">docker run --rm {image} $(which python) -V</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000002079176553__li2632812184912">The system automatically adds hyperparameters associated with the preset image.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000002079176553__section201791550135714"><h4 class="sectiontitle">Using a Custom Image</h4><div class="fignone" id="EN-US_TOPIC_0000002079176553__fig1047613285440"><span class="figcap"><b>Figure 2 </b>Creating an algorithm using a custom image</span><br><span><img id="EN-US_TOPIC_0000002079176553__image184455412475" src="figure/en-us_image_0000002043019012.png" width="469.49" height="185.3754" title="Click to enlarge" class="imgResize"></span></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000002079176553__en-us_topic_0000001309847669_p239405164812">For details about how to use custom images supported by the new-version training, see <a href="docker-modelarts_0017.html">Using a Custom Image to Train Models</a>.</p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p3810141819596">If all used images are customized, do as follows to use a specified Conda environment to start training:</p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p1322471615611">Training jobs do not run in a shell. Therefore, you are not allowed to run the <strong id="EN-US_TOPIC_0000002079176553__b680892144711">conda activate</strong> command to activate a specified Conda environment. In this case, use other methods to start training.</p>
|
|
<p id="EN-US_TOPIC_0000002079176553__p1134015556518">For example, Conda in your custom image is installed in the <strong id="EN-US_TOPIC_0000002079176553__b19646014154715">/home/ma-user/anaconda3</strong> directory, the Conda environment is <strong id="EN-US_TOPIC_0000002079176553__b864661434717">python-3.7.10</strong>, and the training script is stored in <strong id="EN-US_TOPIC_0000002079176553__b1464771474719">/home/ma-user/modelarts/user-job-dir/code/train.py</strong>. Use a specified Conda environment to start training in one of the following ways:</p>
|
|
<ul id="EN-US_TOPIC_0000002079176553__ul1865484214288"><li id="EN-US_TOPIC_0000002079176553__li165419424286">Method 1: Configure the correct <strong id="EN-US_TOPIC_0000002079176553__b145118293477">DEFAULT_CONDA_ENV_NAME</strong> and <strong id="EN-US_TOPIC_0000002079176553__b451212296475">ANACONDA_DIR</strong> environment variables for the image.<div class="p" id="EN-US_TOPIC_0000002079176553__p0932144515286">Run the <strong id="EN-US_TOPIC_0000002079176553__b7680123719476">python</strong> command to start the training script. The following shows an example:<pre class="screen" id="EN-US_TOPIC_0000002079176553__screen14731114812411">python /home/ma-user/modelarts/user-job-dir/code/train.py</pre>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000002079176553__li7654842172812">Method 2: Use the path of <span class="parmvalue" id="EN-US_TOPIC_0000002079176553__parmvalue186351086559"><b>conda env python</b></span>.<div class="p" id="EN-US_TOPIC_0000002079176553__p10711256102820">Run the <strong id="EN-US_TOPIC_0000002079176553__b777117347489">/home/ma-user/anaconda3/envs/python-3.7.10/bin/python</strong> command to start the training script. The following shows an example:<pre class="screen" id="EN-US_TOPIC_0000002079176553__en-us_topic_0000001145869926_screen107715549361">/home/ma-user/anaconda3/envs/python-3.7.10/bin/python /home/ma-user/modelarts/user-job-dir/code/train.py</pre>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000002079176553__li2654194210286">Method 3: Configure the <strong id="EN-US_TOPIC_0000002079176553__b367311112492">PATH</strong> environment variable.<div class="p" id="EN-US_TOPIC_0000002079176553__p16857154122917">Configure the bin directory of the specified Conda environment into the path environment variable. Run the <strong id="EN-US_TOPIC_0000002079176553__b15571195313471">python</strong> command to start the training script. The following shows an example:<pre class="screen" id="EN-US_TOPIC_0000002079176553__screen373442284212">export PATH=/home/ma-user/anaconda3/envs/python-3.7.10/bin:$PATH; python /home/ma-user/modelarts/user-job-dir/code/train.py</pre>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000002079176553__li1565574215280">Method 4: Run the <strong id="EN-US_TOPIC_0000002079176553__b7302113224915">conda run -n</strong> command.<div class="p" id="EN-US_TOPIC_0000002079176553__p825762054115">Run the <strong id="EN-US_TOPIC_0000002079176553__b5376113513498">/home/ma-user/anaconda3/bin/conda run -n python-3.7.10</strong> command to execute the training. The following shows an example:<pre class="screen" id="EN-US_TOPIC_0000002079176553__screen7211343184711">/home/ma-user/anaconda3/bin/conda run -n python-3.7.10 python /home/ma-user/modelarts/user-job-dir/code/train.py</pre>
|
|
</div>
|
|
</li></ul>
|
|
<div class="note" id="EN-US_TOPIC_0000002079176553__note15731102663017"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000002079176553__p1198117123817">If there is an error indicating that the .so file is unavailable in the <strong id="EN-US_TOPIC_0000002079176553__b12619744124917">$ANACONDA_DIR/envs/$DEFAULT_CONDA_ENV_NAME/lib</strong> directory, add the directory to <strong id="EN-US_TOPIC_0000002079176553__b362074484910">LD_LIBRARY_PATH</strong> and place the following command before the preceding boot command:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000002079176553__screen18548643387">export LD_LIBRARY_PATH=$ANACONDA_DIR/envs/$DEFAULT_CONDA_ENV_NAME/lib:$LD_LIBRARY_PATH;</pre>
|
|
<p id="EN-US_TOPIC_0000002079176553__p1949823019302">For example, the example boot command used in method 1 is as follows:</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000002079176553__screen0498113013306">export LD_LIBRARY_PATH=$ANACONDA_DIR/envs/$DEFAULT_CONDA_ENV_NAME/lib:$LD_LIBRARY_PATH; python /home/ma-user/modelarts/user-job-dir/code/train.py</pre>
|
|
</div></div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="develop-modelarts-0003.html">Preparing Algorithms</a></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script language="JavaScript">
|
|
<!--
|
|
image_size('.imgResize');
|
|
var msg_imageMax = "view original image";
|
|
var msg_imageClose = "close";
|
|
//--></script> |