Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Set up AWS Trainium instance","local":"set-up-aws-trainium-instance","sections":[{"title":"Create an AWS Trainium Instance","local":"create-an-aws-trainium-instance","sections":[],"depth":2},{"title":"Configuring Jupyter Notebook on your AWS Trainium Instance","local":"configuring-jupyter-notebook-on-your-aws-trainium-instance","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/entry/start.c8feabf9.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/scheduler.9039eef2.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/singletons.e7915abb.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/paths.7ca0e403.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/entry/app.e5ae3c36.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/index.cdcc3d35.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/nodes/0.6270f728.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/nodes/13.b5ae266b.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/CodeBlock.e3ac94d9.js"> | |
| <link rel="modulepreload" href="/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/chunks/Heading.96ce3702.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Set up AWS Trainium instance","local":"set-up-aws-trainium-instance","sections":[{"title":"Create an AWS Trainium Instance","local":"create-an-aws-trainium-instance","sections":[],"depth":2},{"title":"Configuring Jupyter Notebook on your AWS Trainium Instance","local":"configuring-jupyter-notebook-on-your-aws-trainium-instance","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="set-up-aws-trainium-instance" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#set-up-aws-trainium-instance"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Set up AWS Trainium instance</span></h1> <p data-svelte-h="svelte-9hcug9">In this guide, we will show you:</p> <ol data-svelte-h="svelte-32yjnp"><li>How to create an AWS Trainium instance</li> <li>How to use and run Jupyter Notebooks on your instance</li></ol> <h2 class="relative group"><a id="create-an-aws-trainium-instance" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#create-an-aws-trainium-instance"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Create an AWS Trainium Instance</span></h2> <p data-svelte-h="svelte-1rd682u">The simplest way to work with AWS Trainium and Hugging Face Transformers is the <a href="https://aws.amazon.com/marketplace/pp/prodview-gr3e6yiscria2" rel="nofollow">Hugging Face Neuron Deep Learning AMI</a> (DLAMI). The DLAMI comes with all required libraries pre-packaged for you, including the Neuron Drivers, Transformers, Datasets, and Accelerate.</p> <p data-svelte-h="svelte-8w5zox">To create an EC2 Trainium instance, you can start from the console or the Marketplace. This guide will start from the <a href="https://console.aws.amazon.com/ec2sp/v2/" rel="nofollow">EC2 console</a>.</p> <p data-svelte-h="svelte-x4tzhg">Starting from the <a href="https://console.aws.amazon.com/ec2sp/v2/" rel="nofollow">EC2 console</a> in the us-east-1 region, You first click on <strong>Launch an instance</strong> and define a name for the instance (<code>trainium-huggingface-demo</code>).</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/01-name-instance.png" alt="name instance"> <p data-svelte-h="svelte-7wwfcf">Next, you search the Amazon Marketplace for Hugging Face AMIs. Entering “Hugging Face” in the search bar for “Application and OS Images” and hitting “enter”.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/02-search-ami.png" alt="search ami"> <p data-svelte-h="svelte-cgjl8t">This should now open the “Choose an Amazon Machine Image” view with the search. You can now navigate to “AWS Marketplace AMIs” and find the <a href="https://aws.amazon.com/marketplace/pp/prodview-gr3e6yiscria2" rel="nofollow">Hugging Face Neuron Deep Learning AMI</a> and click select.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/03-select-ami.png" alt="select ami"> <p data-svelte-h="svelte-11azj2p"><em>You will be asked to subscribe if you aren’t. The AMI is completely free of charge, and you will only pay for the EC2 compute.</em></p> <p data-svelte-h="svelte-1j7ptbp">Then you need to define a key pair, which will be used to connect to the instance via <code>ssh</code>. You can create one in place if you don’t have a key pair.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/04-select-key.png" alt="select ssh key"> <p data-svelte-h="svelte-1273hb6">After that, create or select a <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html" rel="nofollow">security group</a>. Important you want to allow <code>ssh</code> traffic.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/05-select-sh.png" alt="select security group"> <p data-svelte-h="svelte-1logfj0">You are ready to launch our instance. Therefore click on “Launch Instance” on the right side.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/06-launch-instance.png" alt="select ssh key"> <p data-svelte-h="svelte-1hj8gqc">AWS will now provision the instance using the <a href="https://aws.amazon.com/marketplace/pp/prodview-gr3e6yiscria2" rel="nofollow">Hugging Face Neuron Deep Learning AMI</a>. Additional configurations can be made by increasing the disk space or creating an instance profile to access other AWS services.</p> <p data-svelte-h="svelte-1esnqaz">After the instance runs, you can view and copy the public IPv4 address to <code>ssh</code> into the machine.</p> <img src="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/setup_aws_instance/07-copy-dns.png" alt="select public dns"> <p data-svelte-h="svelte-pmoe5">Replace the empty strings <code>""</code> in the snippet below with the IP address of your instances and the path to the key pair you created/selected when launching the instance.</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->PUBLIC_DNS=<span class="hljs-string">""</span> <span class="hljs-comment"># IP address</span> | |
| KEY_PATH=<span class="hljs-string">""</span> <span class="hljs-comment"># local path to key pair</span> | |
| ssh -i <span class="hljs-variable">$KEY_PATH</span> ubuntu@<span class="hljs-variable">$PUBLIC_DNS</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1gfq877">After you are connected, you can run <code>neuron-ls</code> to ensure you have access to the Trainium accelerators. You should see a similar output than below.</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->ubuntu@ip<span class="hljs-number">-172</span><span class="hljs-number">-31</span><span class="hljs-number">-79</span><span class="hljs-number">-164</span><span class="hljs-punctuation">:</span>~$ neuron-ls | |
| instance-type<span class="hljs-punctuation">:</span> trn1<span class="hljs-number">.2</span>xlarge | |
| instance-id<span class="hljs-punctuation">:</span> i<span class="hljs-number">-0570615e41700</span>a481 | |
| +--------+--------+--------+---------+ | |
| | NEURON | NEURON | NEURON | PCI | | |
| | DEVICE | CORES | MEMORY | BDF | | |
| +--------+--------+--------+---------+ | |
| | <span class="hljs-number">0</span> | <span class="hljs-number">2</span> | <span class="hljs-number">32</span> GB | <span class="hljs-number">00</span><span class="hljs-punctuation">:</span><span class="hljs-number">1</span>e<span class="hljs-number">.0</span> | | |
| +--------+--------+--------+---------+<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="configuring-jupyter-notebook-on-your-aws-trainium-instance" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#configuring-jupyter-notebook-on-your-aws-trainium-instance"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Configuring Jupyter Notebook on your AWS Trainium Instance</span></h2> <p data-svelte-h="svelte-1awhfhm">With the instance is up and running, we can ssh into it. | |
| But instead of developing inside a terminal it is also possible to use a <code>Jupyter Notebook</code> environment. We can use it for preparing our dataset and launching the training (at least when working on a single node).</p> <p data-svelte-h="svelte-19k5h5e">For this, we need to add a port for forwarding in the <code>ssh</code> command, which will tunnel our localhost traffic to the Trainium instance.</p> <div class="code-block relative"><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->PUBLIC_DNS=<span class="hljs-string">""</span> <span class="hljs-comment"># IP address, e.g. ec2-3-80-....</span> | |
| KEY_PATH=<span class="hljs-string">""</span> <span class="hljs-comment"># local path to key, e.g. ssh/trn.pem</span> | |
| ssh -L 8080:localhost:8080 -i <span class="hljs-variable">${KEY_NAME}</span>.pem ubuntu@<span class="hljs-variable">$PUBLIC_DNS</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-fnidfy">You are done! You can now start using the Trainium accelerators with Hugging Face Transformers. Check out the <a href="./fine_tune">Fine-tune Transformers with AWS Trainium</a> guide to get started.</p> <p></p> | |
| <script> | |
| { | |
| __sveltekit_1qahfek = { | |
| assets: "/docs/optimum.neuron/v0.1.0.dev2/en", | |
| base: "/docs/optimum.neuron/v0.1.0.dev2/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/entry/start.c8feabf9.js"), | |
| import("/docs/optimum.neuron/v0.1.0.dev2/en/_app/immutable/entry/app.e5ae3c36.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 13], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 17.2 kB
- Xet hash:
- 4532e5ccad1f00fb6432a8059a779d967f95f9862742cdc448d6377ea8f0297f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.