<meta charset="utf-8" /><meta http-equiv="content-security-policy" content=""><meta name="hf:doc:metadata" content="{&quot;local&quot;:&quot;gaudi-configuration&quot;,&quot;sections&quot;:[{&quot;local&quot;:&quot;optimum.habana.GaudiConfig&quot;,&quot;title&quot;:&quot;GaudiConfig&quot;}],&quot;title&quot;:&quot;Gaudi Configuration&quot;}" data-svelte="svelte-1phssyn">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/assets/pages/__layout.svelte-hf-doc-builder.css">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/start-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/vendor-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/paths-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/pages/__layout.svelte-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/pages/gaudi_config.mdx-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/Tip-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/Docstring-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/IconCopyLink-hf-doc-builder.js">
	<link rel="modulepreload" href="/docs/optimum.habana/pr_356/en/_app/chunks/CodeBlock-hf-doc-builder.js"> 






<h1 class="relative group"><a id="gaudi-configuration" 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="#gaudi-configuration"><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>Gaudi Configuration
	</span></h1>

<p>In order to make the most of Gaudi, it is advised to rely on advanced features such as Habana Mixed Precision or optimized operators.
You can specify which features to use in a Gaudi configuration, which will take the form of a JSON file following this template:</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><!-- HTML_TAG_START --><span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;use_habana_mixed_precision&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span>/<span class="hljs-keyword">false</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_opt_level&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;O1&quot;</span>/<span class="hljs-string">&quot;O2&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_is_verbose&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span>/<span class="hljs-keyword">false</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;use_fused_adam&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span>/<span class="hljs-keyword">false</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;use_fused_clip_norm&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span>/<span class="hljs-keyword">false</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_bf16_ops&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
    <span class="hljs-string">&quot;torch operator to compute in bf16&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;...&quot;</span>
  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_fp32_ops&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
    <span class="hljs-string">&quot;torch operator to compute in fp32&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;...&quot;</span>
  <span class="hljs-punctuation">]</span>
<span class="hljs-punctuation">}</span><!-- HTML_TAG_END --></pre></div>
<p>Here is a description of each configuration parameter:</p>
<ul><li><code>use_habana_mixed_precision</code> enables to decide whether or not Habana Mixed Precision (HMP) should be used. HMP allows to mix <em>fp32</em> and <em>bf16</em> operations. You can find more information <a href="https://docs.habana.ai/en/latest/PyTorch/PyTorch_User_Guide/PT_Mixed_Precision.html" rel="nofollow">here</a>.</li>
<li><code>hmp_opt_level</code> enables to specify the optimization level to use for HMP such as:<ul><li><code>&quot;O1&quot;</code>, which is the default and recommended mode of operation,</li>
<li><code>&quot;O2&quot;</code>, which can be used for debugging convergence issues as well as for initial iterations of converting a new model to run with mixed precision.</li></ul></li>
<li><code>hmp_is_verbose</code> enables to decide whether to log precision decisions for each operation for debugging purposes. It is disabled by default. You can find an example of such log <a href="https://docs.habana.ai/en/latest/PyTorch/PyTorch_User_Guide/PT_Mixed_Precision.html#hmp-logs" rel="nofollow">here</a>.</li>
<li><code>use_fused_adam</code> enables to decide whether to use the <a href="https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Custom_Ops_PyTorch.html#custom-optimizers" rel="nofollow">custom fused implementation of the ADAM optimizer provided by Habana</a>.</li>
<li><code>use_fused_clip_norm</code> enables to decide whether to use the <a href="https://docs.habana.ai/en/latest/PyTorch/Model_Optimization_PyTorch/Custom_Ops_PyTorch.html#other-custom-ops" rel="nofollow">custom fused implementation of gradient norm clipping provided by Habana</a>.</li>
<li><code>hmp_bf16_ops</code> enables to specify the Torch operations that should be computed in <em>bf16</em>. You can find more information about casting rules <a href="https://docs.habana.ai/en/latest/PyTorch/PyTorch_User_Guide/PT_Mixed_Precision.html#basic-design-rules" rel="nofollow">here</a>.</li>
<li><code>hmp_fp32_ops</code> enables to specify the Torch operations that should be computed in <em>fp32</em>. You can find more information about casting rules <a href="https://docs.habana.ai/en/latest/PyTorch/PyTorch_User_Guide/PT_Mixed_Precision.html#basic-design-rules" rel="nofollow">here</a>.</li></ul>


<div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p><code>hmp_opt_level</code>, <code>hmp_is_verbose</code>, <code>hmp_bf16_ops</code> and <code>hmp_fp32_ops</code> will not be used if <code>use_habana_mixed_precision</code> is false.</p></div>
<p>You can find examples of Gaudi configurations in the <a href="https://huggingface.co/habana" rel="nofollow">Habana model repository on the Hugging Face Hub</a>. For instance, <a href="https://huggingface.co/Habana/bert-large-uncased-whole-word-masking/blob/main/gaudi_config.json" rel="nofollow">for BERT Large we have</a>:</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><!-- HTML_TAG_START --><span class="hljs-punctuation">{</span>
  <span class="hljs-attr">&quot;use_habana_mixed_precision&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_opt_level&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;O1&quot;</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_is_verbose&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">false</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;use_fused_adam&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;use_fused_clip_norm&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-keyword">true</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_bf16_ops&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
    <span class="hljs-string">&quot;add&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;addmm&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;bmm&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;div&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;dropout&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;gelu&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;iadd&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;linear&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;layer_norm&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;matmul&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;mm&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;rsub&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;softmax&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;truediv&quot;</span>
  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
  <span class="hljs-attr">&quot;hmp_fp32_ops&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>
    <span class="hljs-string">&quot;embedding&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;nll_loss&quot;</span><span class="hljs-punctuation">,</span>
    <span class="hljs-string">&quot;log_softmax&quot;</span>
  <span class="hljs-punctuation">]</span>
<span class="hljs-punctuation">}</span><!-- HTML_TAG_END --></pre></div>
<h2 class="relative group"><a id="optimum.habana.GaudiConfig" 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="#optimum.habana.GaudiConfig"><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>GaudiConfig
	</span></h2>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">

<div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="optimum.habana.GaudiConfig"><!-- HTML_TAG_START --><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">class</span> <span class="font-medium">optimum.habana.</span><span class="font-semibold">GaudiConfig</span></span></h3><!-- HTML_TAG_END -->
		<a id="optimum.habana.GaudiConfig" class="header-link invisible with-hover:group-hover:visible pr-2" href="#optimum.habana.GaudiConfig"><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></a>
		<a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/optimum.habana/blob/vr_356/src/optimum/habana/gaudi_configuration.py#L48" target="_blank"><span>&lt;</span>
				<span class="hidden md:block mx-0.5 hover:!underline">source</span>
				<span>&gt;</span></a></span>
	<p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span>
			<span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">**kwargs<span class="opacity-60"></span></span>
				</span>
			<span>)</span>
			</p>

	
	<div class="!mb-10 relative docstring-details ">
		
		
		</div></div></div>


		<script type="module" data-hydrate="1y0wsm">
		import { start } from "/docs/optimum.habana/pr_356/en/_app/start-hf-doc-builder.js";
		start({
			target: document.querySelector('[data-hydrate="1y0wsm"]').parentNode,
			paths: {"base":"/docs/optimum.habana/pr_356/en","assets":"/docs/optimum.habana/pr_356/en"},
			session: {},
			route: false,
			spa: false,
			trailing_slash: "never",
			hydrate: {
				status: 200,
				error: null,
				nodes: [
					import("/docs/optimum.habana/pr_356/en/_app/pages/__layout.svelte-hf-doc-builder.js"),
						import("/docs/optimum.habana/pr_356/en/_app/pages/gaudi_config.mdx-hf-doc-builder.js")
				],
				params: {}
			}
		});
	</script>
