Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Google TPU","local":"google-tpu","sections":[{"title":"Modo eager","local":"eager-mode","sections":[],"depth":2},{"title":"Modo compilado","local":"compiled-mode","sections":[],"depth":2},{"title":"Paralelismo de tensores","local":"tensor-parallelism","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/BF9UNEM9.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DPnyVmXs.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DSGUT_OW.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/C045MWWx.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DTZsP_3B.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/IaDvMxLQ.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/311.C19KkVwx.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/bKdwVYpU.js" rel="modulepreload"> | |
| <!--vjbfci--><meta name="hf:doc:metadata" content="{"title":"Google TPU","local":"google-tpu","sections":[{"title":"Eager mode","local":"eager-mode","sections":[],"depth":2},{"title":"Compiled mode","local":"compiled-mode","sections":[],"depth":2},{"title":"Tensor parallelism","local":"tensor-parallelism","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/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: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" 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 dir="auto">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="google-tpu" 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="#google-tpu"><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><!---->Google TPU<!----></span></h1><!--]--><!----> <p>Las unidades de procesamiento de tensores (TPU) son los aceleradores de aprendizaje automático de Google, disponibles como Cloud TPU (v6e, v7x). | |
| Diffusers se ejecuta en ellos a través de <a href="https://github.com/google-pytorch/torch_tpu/" rel="nofollow">TorchTPU</a>, el backend de PyTorch para TPU, | |
| con cambios mínimos en el código.</p> <p>Hay disponibles tres modos de ejecución:</p> <table><thead><tr><th>Modo</th><th>Constante</th><th>Cómo activar</th><th>Notas</th></tr></thead><tbody><tr><td>Eager estricto (predeterminado)</td><td><code>EagerMode.DEFER_NEVER</code></td><td><code>pipe.to("tpu")</code></td><td>Operaciones despachadas una a la vez, asíncronas</td></tr><tr><td>Eager optimizado</td><td><code>EagerMode.DEFER_AND_FUSE</code></td><td><code>TORCH_TPU_DEFER_AND_FUSE=1</code></td><td>Operaciones diferidas y fusionadas en grafos más grandes; más rápido que el modo estricto eager, con una compilación más larga</td></tr><tr><td>Compilar</td><td>—</td><td><code>torch.compile(module, backend="tpu")</code></td><td>Compilación AOT con <code>TpuBackend</code></td></tr></tbody></table> <p>Siga la <a href="https://github.com/google-pytorch/torch_tpu/" rel="nofollow">guía de instalación de TorchTPU</a>. Una vez instalado, <code>import torch</code> lo carga automáticamente y registra el dispositivo <code>"tpu"</code>, por lo que <code>pipe.to("tpu")</code> es el único cambio necesario. Añada <code>import torch_tpu</code> solo si deshabilitó la carga automática del backend con <code>TORCH_DEVICE_BACKEND_AUTOLOAD=0</code>.</p> <!--[1--><h2 class="relative group"><a id="eager-mode" 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="#eager-mode"><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><!---->Modo eager<!----></span></h2><!--]--><!----> <p>FLUX.1-schnell no cabe en un solo chip v6e a la vez, por lo que use <a href="/docs/diffusers/main/es/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a> para | |
| mover cada modelo al TPU solo mientras se ejecuta. Detecta automáticamente el dispositivo <code>"tpu"</code>.</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> Copiado</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline | |
| pipe = FluxPipeline.from_pretrained(<span class="hljs-string">"black-forest-labs/FLUX.1-schnell"</span>, dtype=torch.bfloat16) | |
| pipe.enable_model_cpu_offload() | |
| image = pipe( | |
| prompt=<span class="hljs-string">"a golden retriever surfing a wave, photorealistic"</span>, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">4</span>, | |
| guidance_scale=<span class="hljs-number">0.0</span>, | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"output.png"</span>)<!----></pre></div><!----> <p>Si un modelo es demasiado grande para un solo chip, o si tienes varios chips y quieres una latencia más baja, divide los modelos entre los chips. Consulta la sección <a href="#tensor-parallelism">Paralelismo de tensores</a>.</p> <!--[1--><h2 class="relative group"><a id="compiled-mode" 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="#compiled-mode"><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><!---->Modo compilado<!----></span></h2><!--]--><!----> <p>TorchTPU registra <code>"tpu"</code> como nombre de backend de <code>torch.compile</code> (<code>TpuBackend</code> por debajo), por lo que los componentes se compilan como cualquier otro destino de <code>torch.compile</code>. La primera llamada (calentamiento) es lenta porque compila; las llamadas posteriores con las mismas formas reutilizan el gráfico compilado.</p> <blockquote class="important"><p>TorchTPU requiere <strong>formas estáticas</strong>, por lo que debe pasar <code>dynamic=False</code>. Una nueva <code>height</code> o <code>width</code> vuelve a compilar para esa forma, una sola vez; las formas ya vistas se reutilizan. Cambiar <code>num_inference_steps</code> no vuelve a compilar.</p></blockquote> <p>Cuando el pipeline completo cabe en un solo chip, muévelo a la TPU y compila el transformador completo. Stable Diffusion 3.5 | |
| Medium (~15GB en bf16) cabe en un solo chip v6e.</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> Copiado</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusion3Pipeline | |
| pipe = StableDiffusion3Pipeline.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-3.5-medium"</span>, dtype=torch.bfloat16) | |
| pipe.to(<span class="hljs-string">"tpu"</span>) | |
| pipe.transformer.<span class="hljs-built_in">compile</span>(backend=<span class="hljs-string">"tpu"</span>, fullgraph=<span class="hljs-literal">True</span>, dynamic=<span class="hljs-literal">False</span>) | |
| <span class="hljs-comment"># Warmup — triggers static graph compilation.</span> | |
| pipe(prompt=<span class="hljs-string">"warmup"</span>, height=<span class="hljs-number">1024</span>, width=<span class="hljs-number">1024</span>, num_inference_steps=<span class="hljs-number">40</span>, guidance_scale=<span class="hljs-number">4.5</span>) | |
| <span class="hljs-comment"># Later calls with the same shapes reuse the compiled graph.</span> | |
| image = pipe( | |
| prompt=<span class="hljs-string">"a golden retriever surfing a wave, photorealistic"</span>, | |
| height=<span class="hljs-number">1024</span>, | |
| width=<span class="hljs-number">1024</span>, | |
| num_inference_steps=<span class="hljs-number">40</span>, | |
| guidance_scale=<span class="hljs-number">4.5</span>, | |
| ).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"output.png"</span>)<!----></pre></div><!----> <p>Si el pipeline no cabe en un solo chip:</p> <ul><li>Con varios chips, divídalo en fragmentos mediante <a href="#tensor-parallelism">paralelismo de tensores</a> en su lugar. Todo permanece en la TPU, | |
| y <code>pipe.transformer.compile(...)</code> funciona de la misma manera en el transformador fragmentado.</li> <li>Con <a href="/docs/diffusers/main/es/api/pipelines/overview#diffusers.DiffusionPipeline.enable_model_cpu_offload">enable_model_cpu_offload()</a>, los hooks de offload no pueden ser trazados por <code>torch.compile</code>. En su lugar, compile solo los bloques repetidos del transformer, con <code>pipe.transformer.compile_repeated_blocks(backend="tpu", fullgraph=True, dynamic=False)</code>.</li></ul> <!--[1--><h2 class="relative group"><a id="tensor-parallelism" 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="#tensor-parallelism"><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><!---->Paralelismo de tensores<!----></span></h2><!--]--><!----> <p>Divida los modelos demasiado grandes para un solo chip en varios. El codificador de texto (~48GB) y el transformador (~64GB) de FLUX.2-dev superan cada uno la capacidad de un solo chip, por lo que el ejemplo siguiente divide ambos:</p> <ul><li>el transformer con <a href="/docs/diffusers/main/es/api/parallel#diffusers.TensorParallelConfig">TensorParallelConfig</a>, pasado al argumento <code>parallel_config</code> de <a href="/docs/diffusers/main/es/api/models/overview#diffusers.ModelMixin.from_pretrained">from_pretrained()</a>. Cada rank solo lee su propia porción de cada peso fragmentado, por lo que el modelo completo nunca se materializa. Para más detalles generales sobre TP (<code>_tp_plan</code>, colwise/rowwise), consulte la guía de <a href="./tensor_parallelism">Tensor parallelism</a>.</li> <li>el codificador de texto con el propio <a href="https://huggingface.co/docs/transformers/perf_infer_gpu_multi" rel="nofollow">paralelismo de tensores</a> de Transformers, pasando un <a href="https://huggingface.co/docs/transformers/main/en/expert_parallelism#transformers.DistributedConfig" rel="nofollow">DistributedConfig</a> y la misma malla.</li></ul> <p>En TPU, inicializa el grupo de procesos con <code>backend="tpu_dist"</code> y construye la malla con <code>DeviceMesh("tpu", ...)</code>.</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> Copiado</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">import</span> torch.distributed <span class="hljs-keyword">as</span> dist | |
| <span class="hljs-keyword">from</span> torch.distributed.device_mesh <span class="hljs-keyword">import</span> DeviceMesh | |
| <span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DistributedConfig, Mistral3ForConditionalGeneration | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Flux2Pipeline, Flux2Transformer2DModel, TensorParallelConfig | |
| dist.init_process_group(backend=<span class="hljs-string">"tpu_dist"</span>) | |
| mesh = DeviceMesh(<span class="hljs-string">"tpu"</span>, <span class="hljs-built_in">list</span>(<span class="hljs-built_in">range</span>(dist.get_world_size()))) | |
| repo_id = <span class="hljs-string">"black-forest-labs/FLUX.2-dev"</span> | |
| text_encoder = Mistral3ForConditionalGeneration.from_pretrained( | |
| repo_id, | |
| subfolder=<span class="hljs-string">"text_encoder"</span>, | |
| dtype=torch.bfloat16, | |
| distributed_config=DistributedConfig(tp_plan=<span class="hljs-string">"auto"</span>), | |
| device_mesh=mesh, | |
| ) | |
| transformer = Flux2Transformer2DModel.from_pretrained( | |
| repo_id, subfolder=<span class="hljs-string">"transformer"</span>, dtype=torch.bfloat16, parallel_config=TensorParallelConfig(mesh=mesh) | |
| ) | |
| pipe = Flux2Pipeline.from_pretrained( | |
| repo_id, text_encoder=text_encoder, transformer=transformer, dtype=torch.bfloat16 | |
| ) | |
| pipe.vae.to(<span class="hljs-string">"tpu"</span>) | |
| image = pipe( | |
| prompt=<span class="hljs-string">"a golden retriever surfing a wave, photorealistic"</span>, | |
| num_inference_steps=<span class="hljs-number">28</span>, | |
| generator=torch.Generator(<span class="hljs-string">"cpu"</span>).manual_seed(<span class="hljs-number">0</span>), | |
| ).images[<span class="hljs-number">0</span>] | |
| <span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span>: | |
| image.save(<span class="hljs-string">"output.png"</span>)<!----></pre></div><!----> <p>Inicie un proceso por chip. Establezca <code>--nproc_per_node</code> para usar el número total de chips TPU de su host.</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> Copiado</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">eval</span> $(python -m torch_tpu._internal.distributed.launchers.singlehost_wrapper | sed <span class="hljs-string">'s/^/export /'</span>) | |
| torchrun --nproc_per_node=8 flux2_tp.py<!----></pre></div><!----> <blockquote class="warning"><p>El comando de lanzamiento anterior utiliza un módulo interno de TorchTPU (<code>torch_tpu._internal</code>), no una API estable, y se espera que cambie en una futura versión de TorchTPU. Consulte el <a href="https://github.com/google-pytorch/torch_tpu/" rel="nofollow">repositorio de TorchTPU</a> para conocer la forma actual de lanzar trabajos de varios chips.</p></blockquote> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/tpu.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_g37pnb = { | |
| base: "/docs/diffusers/main/en", | |
| assets: "/docs/diffusers/main/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 311], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 25.3 kB
- Xet hash:
- 1da67f4ecf8725ad776a9ac4117abdf1ea992313c71ec5f9298b59001ecd717e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.