Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"CPU","local":"cpu","sections":[{"title":"Kubernetes","local":"kubernetes","sections":[{"title":"PyTorchJob","local":"pytorchjob","sections":[],"depth":3},{"title":"Deploy","local":"deploy","sections":[],"depth":3}],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/start.3Ggj4A00.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/RVZRN09O.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/CNOmh-VW.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/entry/app.D0MfcWQC.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/Up3XY6Oq.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DOLBYqcr.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/ByRGanGp.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/0.B9LS0rGA.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/Hu1IfMtR.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/nodes/5.TNbUbjUB.js" rel="modulepreload"> | |
| <link href="/docs/transformers/main/en/_app/immutable/chunks/BulnHs9s.js" rel="modulepreload"> | |
| <!--cj616l--><meta name="hf:doc:metadata" content="{"title":"CPU","local":"cpu","sections":[{"title":"Kubernetes","local":"kubernetes","sections":[{"title":"PyTorchJob","local":"pytorchjob","sections":[],"depth":3},{"title":"Deploy","local":"deploy","sections":[],"depth":3}],"depth":2},{"title":"Next steps","local":"next-steps","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/transformers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" 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><!----></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="cpu" 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="#cpu"><span><svg 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>CPU</span></h1><!--]--><!----> <p>CPU training works well when GPUs aren’t available or when you want a cost-effective setup. Modern Intel CPUs support bf16 mixed precision training with <a href="https://docs.pytorch.org/docs/stable/amp" rel="nofollow">PyTorch’s AMP</a> (Automatic Mixed Precision) for CPU backends, which reduces memory usage and speeds up training.</p> <p>Scale CPU training across multiple sockets or nodes if a single CPU is too slow. The examples below cover three scenarios:</p> <ul><li>a single CPU</li> <li>multiple processes on one machine (one per CPU socket)</li> <li>multiple processes across several machines</li></ul> <p>All distributed examples use <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/mpi-library.html" rel="nofollow">Intel MPI</a> from the <a href="https://www.intel.com/content/www/us/en/developer/tools/oneapi/hpc-toolkit.html" rel="nofollow">Intel oneAPI HPC Toolkit</a> for communication and a DDP strategy with <a href="/docs/transformers/pr_48728/en/main_classes/trainer#transformers.Trainer">Trainer</a>.</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><!--[--><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">single CPU</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">distributed CPU (single node)</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">distributed CPU (multiple nodes)</div><!--]--></div> <div class="language-select"><!--[0--><p><a href="/docs/transformers/pr_48728/en/main_classes/trainer#transformers.Trainer">Trainer</a> supports bf16 mixed precision training on CPU. Prefer bf16 over fp16 for CPU training because it’s more numerically stable. Pass <code>--bf16</code> to enable PyTorch’s CPU autocast and <code>--use_cpu</code> to force CPU training. You can pass the same parameters to <a href="/docs/transformers/pr_48728/en/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a> directly.</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 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="language-py "><!----><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments | |
| training_args = TrainingArguments( | |
| output_dir=<span class="hljs-string">"./outputs"</span>, | |
| bf16=<span class="hljs-literal">True</span>, | |
| use_cpu=<span class="hljs-literal">True</span>, | |
| )<!----></pre></div><!----><!----><!--]--><!----> <!--[-1--><!--]--><!----> <!--[-1--><!--]--><!----><!----></div><!----> <!--[1--><h2 class="relative group"><a id="kubernetes" 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="#kubernetes"><span><svg 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>Kubernetes</span></h2><!--]--><!----> <p>Distributed CPU training can also run on a Kubernetes cluster using <a href="https://www.kubeflow.org/docs/components/training/user-guides/pytorch/" rel="nofollow">PyTorchJob</a>.</p> <p>Complete the following setup before deploying:</p> <ol><li>Ensure you have access to a Kubernetes cluster with <a href="https://www.kubeflow.org/docs/started/installing-kubeflow/" rel="nofollow">Kubeflow</a> installed.</li> <li>Install and configure <a href="https://kubernetes.io/docs/tasks/tools" rel="nofollow">kubectl</a> to interact with the cluster.</li> <li>Set up a <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow">PersistentVolumeClaim (PVC)</a> to store datasets and model files.</li> <li>Build a Docker image for the training script and its dependencies.</li></ol> <p>The example Dockerfile below starts from an Intel-optimized PyTorch base image that includes MPI support for multi-node CPU training. It also installs two performance libraries:</p> <ul><li><code>google-perftools</code> (<code>libtcmalloc</code>): a memory allocator that reduces allocation overhead compared to the default system allocator.</li> <li><code>libomp-dev</code> (<code>libiomp5</code>): Intel’s OpenMP runtime, which provides better CPU thread management than the GNU OpenMP default.</li></ul> <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 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="language-dockerfile "><!----><span class="hljs-keyword">FROM</span> intel/intel-optimized-pytorch:<span class="hljs-number">2.4</span>.<span class="hljs-number">0</span>-pip-multinode | |
| <span class="hljs-keyword">RUN</span><span class="language-bash"> apt-get update -y && \ | |
| apt-get install -y --no-install-recommends --fix-missing \ | |
| google-perftools \ | |
| libomp-dev</span> | |
| <span class="hljs-keyword">WORKDIR</span><span class="language-bash"> /workspace</span> | |
| <span class="hljs-comment"># Install Transformers and copy your training script into the image</span> | |
| <span class="hljs-keyword">RUN</span><span class="language-bash"> pip install --no-cache-dir transformers</span> | |
| <span class="hljs-keyword">COPY</span><span class="language-bash"> train.py /workspace/train.py</span><!----></pre></div><!----> <p>Build the image and push it to a registry accessible from your cluster’s nodes before deploying.</p> <!--[2--><h3 class="relative group"><a id="pytorchjob" 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="#pytorchjob"><span><svg 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>PyTorchJob</span></h3><!--]--><!----> <p><a href="https://www.kubeflow.org/docs/components/training/user-guides/pytorch/" rel="nofollow">PyTorchJob</a> is a Kubernetes custom resource that manages PyTorch distributed training jobs. It handles worker pod lifecycle, restart policy, and process coordination. Your training script only needs to handle the model and data.</p> <p>The example yaml file below sets up four workers running a training script with bf16 enabled.</p> <p>When setting CPU resource limits and requests, use <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu" rel="nofollow">CPU units</a> where one unit equals one physical core or virtual core. Set both limits and requests to the same value for a <code>Guaranteed</code> <a href="https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod" rel="nofollow">quality of service</a>. Leave some cores unallocated for kubelet and system processes. Set <code>OMP_NUM_THREADS</code> to match the number of allocated CPU units so PyTorch uses all available cores.</p> <p>Adapt the yaml file based on your training script and the number of nodes in your cluster.</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 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="language-yaml "><!----><span class="hljs-attr">apiVersion:</span> <span class="hljs-string">"kubeflow.org/v1"</span> | |
| <span class="hljs-attr">kind:</span> <span class="hljs-string">PyTorchJob</span> | |
| <span class="hljs-attr">metadata:</span> | |
| <span class="hljs-attr">name:</span> <span class="hljs-string">transformers-pytorchjob</span> | |
| <span class="hljs-attr">spec:</span> | |
| <span class="hljs-attr">elasticPolicy:</span> | |
| <span class="hljs-attr">rdzvBackend:</span> <span class="hljs-string">c10d</span> | |
| <span class="hljs-attr">minReplicas:</span> <span class="hljs-number">1</span> | |
| <span class="hljs-attr">maxReplicas:</span> <span class="hljs-number">4</span> | |
| <span class="hljs-attr">maxRestarts:</span> <span class="hljs-number">10</span> | |
| <span class="hljs-attr">pytorchReplicaSpecs:</span> | |
| <span class="hljs-attr">Worker:</span> | |
| <span class="hljs-attr">replicas:</span> <span class="hljs-number">4</span> <span class="hljs-comment"># The number of worker pods</span> | |
| <span class="hljs-attr">restartPolicy:</span> <span class="hljs-string">OnFailure</span> | |
| <span class="hljs-attr">template:</span> | |
| <span class="hljs-attr">spec:</span> | |
| <span class="hljs-attr">containers:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">pytorch</span> | |
| <span class="hljs-attr">image:</span> <span class="hljs-string"><image</span> <span class="hljs-string">name>:<tag></span> <span class="hljs-comment"># Specify the docker image to use for the worker pods</span> | |
| <span class="hljs-attr">imagePullPolicy:</span> <span class="hljs-string">IfNotPresent</span> | |
| <span class="hljs-attr">command:</span> [<span class="hljs-string">"/bin/bash"</span>, <span class="hljs-string">"-c"</span>] | |
| <span class="hljs-attr">args:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-string">>- | |
| cd /workspace; | |
| torchrun train.py \ | |
| --model_name_or_path distilbert/distilbert-base-uncased \ | |
| --do_train \ | |
| --do_eval \ | |
| --per_device_train_batch_size 12 \ | |
| --learning_rate 3e-5 \ | |
| --num_train_epochs 2 \ | |
| --output_dir /tmp/pvc-mount/output_$(date +%Y%m%d_%H%M%S) \ | |
| --bf16; | |
| </span> <span class="hljs-attr">env:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">LD_PRELOAD</span> | |
| <span class="hljs-attr">value:</span> <span class="hljs-string">"/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4.5.9:/usr/local/lib/libiomp5.so"</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">HF_HUB_CACHE</span> | |
| <span class="hljs-attr">value:</span> <span class="hljs-string">"/tmp/pvc-mount/hub_cache"</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">HF_DATASETS_CACHE</span> | |
| <span class="hljs-attr">value:</span> <span class="hljs-string">"/tmp/pvc-mount/hf_datasets_cache"</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">LOGLEVEL</span> | |
| <span class="hljs-attr">value:</span> <span class="hljs-string">"INFO"</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">OMP_NUM_THREADS</span> <span class="hljs-comment"># Set to match the number of allocated CPU units</span> | |
| <span class="hljs-attr">value:</span> <span class="hljs-string">"240"</span> | |
| <span class="hljs-attr">resources:</span> | |
| <span class="hljs-attr">limits:</span> | |
| <span class="hljs-attr">cpu:</span> <span class="hljs-number">240</span> <span class="hljs-comment"># Update the CPU and memory limit values based on your nodes</span> | |
| <span class="hljs-attr">memory:</span> <span class="hljs-string">128Gi</span> | |
| <span class="hljs-attr">requests:</span> | |
| <span class="hljs-attr">cpu:</span> <span class="hljs-number">240</span> <span class="hljs-comment"># Update the CPU and memory request values based on your nodes</span> | |
| <span class="hljs-attr">memory:</span> <span class="hljs-string">128Gi</span> | |
| <span class="hljs-attr">volumeMounts:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">pvc-volume</span> | |
| <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/tmp/pvc-mount</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">mountPath:</span> <span class="hljs-string">/dev/shm</span> | |
| <span class="hljs-attr">name:</span> <span class="hljs-string">dshm</span> | |
| <span class="hljs-attr">restartPolicy:</span> <span class="hljs-string">Never</span> | |
| <span class="hljs-attr">nodeSelector:</span> <span class="hljs-comment"># Optionally use nodeSelector to match a certain node label for the worker pods</span> | |
| <span class="hljs-attr">node-type:</span> <span class="hljs-string">gnr</span> | |
| <span class="hljs-attr">volumes:</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">pvc-volume</span> | |
| <span class="hljs-attr">persistentVolumeClaim:</span> | |
| <span class="hljs-attr">claimName:</span> <span class="hljs-string">transformers-pvc</span> | |
| <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">dshm</span> | |
| <span class="hljs-attr">emptyDir:</span> | |
| <span class="hljs-attr">medium:</span> <span class="hljs-string">Memory</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="deploy" 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="#deploy"><span><svg 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>Deploy</span></h3><!--]--><!----> <p>Deploy the PyTorchJob to the cluster with the following command.</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 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="language-bash "><!----><span class="hljs-built_in">export</span> NAMESPACE=<specify your namespace> | |
| kubectl create -f pytorchjob.yaml -n <span class="hljs-variable">${NAMESPACE}</span><!----></pre></div><!----> <p>List the pods in the namespace to monitor their status. Pods start as <strong>Pending</strong> while the container image is pulled, then transition to <strong>Running</strong>.</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 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="language-bash "><!---->kubectl get pods -n <span class="hljs-variable">${NAMESPACE}</span> | |
| NAME READY STATUS RESTARTS AGE | |
| ... | |
| transformers-pytorchjob-worker-0 1/1 Running 0 7m37s | |
| transformers-pytorchjob-worker-1 1/1 Running 0 7m37s | |
| transformers-pytorchjob-worker-2 1/1 Running 0 7m37s | |
| transformers-pytorchjob-worker-3 1/1 Running 0 7m37s | |
| ...<!----></pre></div><!----> <p>Stream logs from a worker pod to follow training progress.</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 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="language-bash "><!---->kubectl logs transformers-pytorchjob-worker-0 -n <span class="hljs-variable">${NAMESPACE}</span> -f<!----></pre></div><!----> <p>Copy the trained model from the PVC or your storage location after training completes. Then delete the PyTorchJob resource.</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 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="language-bash "><!---->kubectl delete -f pytorchjob.yaml -n <span class="hljs-variable">${NAMESPACE}</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="next-steps" 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="#next-steps"><span><svg 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>Next steps</span></h2><!--]--><!----> <ul><li>Read the <a href="https://huggingface.co/blog/intel-sapphire-rapids" rel="nofollow">Accelerating PyTorch Transformers with Intel Sapphire Rapids</a> blog post for a deeper look at BF16 performance on modern Intel hardware.</li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/cpu.md" target="_blank"><svg class="mr-1" 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="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_16srhz2 = { | |
| base: "/docs/transformers/main/en", | |
| assets: "/docs/transformers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/transformers/main/en/_app/immutable/entry/start.3Ggj4A00.js"), | |
| import("/docs/transformers/main/en/_app/immutable/entry/app.D0MfcWQC.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 5], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 33.8 kB
- Xet hash:
- 928810bbfb55b17ccbd67f5d7fc65089e3624714b56cb3bdba6c433fbf71809b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.