import{S as Jr,i as Tr,s as jr,e as i,k as h,w as d,t as s,M as gr,c as n,d as t,m as f,a as r,x as m,h as o,b as c,N as vr,G as l,g as p,y as u,L as $r,q as w,o as y,B as b,v as _r}from"../../chunks/vendor-hf-doc-builder.js";import{I as ce}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as M}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Ur}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function kr(Si){let G,$l,Z,P,vt,de,is,Jt,ns,_l,me,Ul,k,rs,ue,ps,hs,Tt,fs,cs,kl,Y,ds,we,ms,us,El,T,ws,jt,ys,bs,gt,Ms,vs,$t,Js,Ts,Il,Ke,js,Bl,X,H,_t,ye,gs,Ut,$s,Wl,et,_s,Cl,be,Gl,Me,Zl,ve,Xl,Je,xl,tt,Us,Al,Te,Fl,x,V,kt,je,ks,Et,Es,zl,E,Is,It,Bs,Ws,Bt,Cs,Gs,Sl,ge,Nl,Q,Zs,Wt,Xs,xs,Pl,$e,Yl,A,D,Ct,_e,As,Gt,Fs,Hl,lt,zs,Vl,R,Ss,Zt,Ns,Ps,Ql,Ue,Dl,ke,Rl,F,q,Xt,Ee,Ys,xt,Hs,ql,I,Vs,At,Qs,Ds,Ft,Rs,qs,Ll,Ie,Ol,Be,Kl,We,ea,v,Ls,zt,Os,Ks,St,eo,to,Nt,lo,ao,Pt,so,oo,Yt,io,no,ta,at,ro,la,st,po,aa,Ce,sa,ot,ho,oa,Ge,ia,it,fo,na,L,co,Ht,mo,uo,ra,O,wo,Vt,Qt,yo,bo,pa,Ze,ha,Xe,fa,B,Mo,Dt,vo,Jo,Rt,To,jo,ca,xe,da,z,K,qt,Ae,go,Lt,$o,ma,nt,_o,ua,Fe,wa,ze,ya,rt,pt,Ni,ba,S,ee,Ot,Se,Uo,Kt,ko,Ma,te,Eo,el,Io,Bo,va,ht,Wo,Ja,Ne,Ta,Pe,ja,ft,ct,Pi,ga,N,le,tl,Ye,Co,ll,Go,$a,ae,Zo,al,Xo,xo,_a,j,Ao,sl,Fo,zo,He,So,No,se,ol,Po,Yo,Ho,Ua,Ve,il,Vo,Qo,ka,oe,U,Do,nl,Ro,qo,rl,Lo,Oo,pl,Ko,ei,ti,hl,li,Ea,g,ai,fl,si,oi,cl,ii,ni,dl,ri,pi,Ia,Qe,Ba,W,hi,ml,fi,ci,ul,di,mi,Wa,ie,De,ui,wl,wi,yi,bi,J,Mi,yl,vi,Ji,bl,Ti,ji,Ml,gi,$i,vl,_i,Ui,Jl,ki,Ei,Ca,C,Ii,Tl,Bi,Wi,jl,Ci,Gi,Ga,dt,Zi,Za,Re,Xa,qe,xa,Le,Aa,Oe,Fa,ne,Xi,gl,xi,Ai,za;return de=new ce({}),me=new Ur({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/stable_diffusion_jax_how_to.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/stable_diffusion_jax_how_to.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/stable_diffusion_jax_how_to.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/stable_diffusion_jax_how_to.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/stable_diffusion_jax_how_to.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/stable_diffusion_jax_how_to.ipynb"}]}}),ye=new ce({}),be=new M({props:{code:"JTIzJTIwdW5jb21tZW50JTIwdG8lMjBpbnN0YWxsJTIwdGhlJTIwbmVjZXNzYXJ5JTIwbGlicmFyaWVzJTIwaW4lMjBDb2xhYiUwQSUyMyFwaXAlMjBpbnN0YWxsJTIwamF4JTNEJTNEMC4zLjI1JTIwamF4bGliJTNEJTNEMC4zLjI1JTIwZmxheCUyMHRyYW5zZm9ybWVycyUyMGZ0ZnklMEElMjMhcGlwJTIwaW5zdGFsbCUyMGRpZmZ1c2Vycw==",highlighted:`<span class="hljs-comment"># uncomment to install the necessary libraries in Colab</span>
<span class="hljs-comment">#!pip install jax==0.3.25 jaxlib==0.3.25 flax transformers ftfy</span>
<span class="hljs-comment">#!pip install diffusers</span>`}}),Me=new M({props:{code:"aW1wb3J0JTIwamF4LnRvb2xzLmNvbGFiX3RwdSUwQSUwQWpheC50b29scy5jb2xhYl90cHUuc2V0dXBfdHB1KCklMEFpbXBvcnQlMjBqYXg=",highlighted:`<span class="hljs-keyword">import</span> jax.tools.colab_tpu

jax.tools.colab_tpu.setup_tpu()
<span class="hljs-keyword">import</span> jax`}}),ve=new M({props:{code:"bnVtX2RldmljZXMlMjAlM0QlMjBqYXguZGV2aWNlX2NvdW50KCklMEFkZXZpY2VfdHlwZSUyMCUzRCUyMGpheC5kZXZpY2VzKCklNUIwJTVELmRldmljZV9raW5kJTBBJTBBcHJpbnQoZiUyMkZvdW5kJTIwJTdCbnVtX2RldmljZXMlN0QlMjBKQVglMjBkZXZpY2VzJTIwb2YlMjB0eXBlJTIwJTdCZGV2aWNlX3R5cGUlN0QuJTIyKSUwQWFzc2VydCUyMCglMEElMjAlMjAlMjAlMjAlMjJUUFUlMjIlMjBpbiUyMGRldmljZV90eXBlJTBBKSUyQyUyMCUyMkF2YWlsYWJsZSUyMGRldmljZSUyMGlzJTIwbm90JTIwYSUyMFRQVSUyQyUyMHBsZWFzZSUyMHNlbGVjdCUyMFRQVSUyMGZyb20lMjBFZGl0JTIwJTNFJTIwTm90ZWJvb2slMjBzZXR0aW5ncyUyMCUzRSUyMEhhcmR3YXJlJTIwYWNjZWxlcmF0b3IlMjI=",highlighted:`num_devices = jax.device_count()
device_type = jax.devices()[<span class="hljs-number">0</span>].device_kind

<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Found <span class="hljs-subst">{num_devices}</span> JAX devices of type <span class="hljs-subst">{device_type}</span>.&quot;</span>)
<span class="hljs-keyword">assert</span> (
    <span class="hljs-string">&quot;TPU&quot;</span> <span class="hljs-keyword">in</span> device_type
), <span class="hljs-string">&quot;Available device is not a TPU, please select TPU from Edit &gt; Notebook settings &gt; Hardware accelerator&quot;</span>`}}),Je=new M({props:{code:"Rm91bmQlMjA4JTIwSkFYJTIwZGV2aWNlcyUyMG9mJTIwdHlwZSUyMENsb3VkJTIwVFBVLg==",highlighted:'Found <span class="hljs-number">8</span> JAX devices of <span class="hljs-built_in">type</span> Cloud TPU.'}}),Te=new M({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwamF4JTBBaW1wb3J0JTIwamF4Lm51bXB5JTIwYXMlMjBqbnAlMEElMEFmcm9tJTIwcGF0aGxpYiUyMGltcG9ydCUyMFBhdGglMEFmcm9tJTIwamF4JTIwaW1wb3J0JTIwcG1hcCUwQWZyb20lMjBmbGF4LmpheF91dGlscyUyMGltcG9ydCUyMHJlcGxpY2F0ZSUwQWZyb20lMjBmbGF4LnRyYWluaW5nLmNvbW1vbl91dGlscyUyMGltcG9ydCUyMHNoYXJkJTBBZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBJTBBZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEZsYXhTdGFibGVEaWZmdXNpb25QaXBlbGluZQ==",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> jax
<span class="hljs-keyword">import</span> jax.numpy <span class="hljs-keyword">as</span> jnp

<span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path
<span class="hljs-keyword">from</span> jax <span class="hljs-keyword">import</span> pmap
<span class="hljs-keyword">from</span> flax.jax_utils <span class="hljs-keyword">import</span> replicate
<span class="hljs-keyword">from</span> flax.training.common_utils <span class="hljs-keyword">import</span> shard
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FlaxStableDiffusionPipeline`}}),je=new ce({}),ge=new M({props:{code:"ZHR5cGUlMjAlM0QlMjBqbnAuYmZsb2F0MTY=",highlighted:"dtype = jnp.bfloat16"}}),$e=new M({props:{code:"cGlwZWxpbmUlMkMlMjBwYXJhbXMlMjAlM0QlMjBGbGF4U3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMkMlMEElMjAlMjAlMjAlMjByZXZpc2lvbiUzRCUyMmJmMTYlMjIlMkMlMEElMjAlMjAlMjAlMjBkdHlwZSUzRGR0eXBlJTJDJTBBKQ==",highlighted:`pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>,
    revision=<span class="hljs-string">&quot;bf16&quot;</span>,
    dtype=dtype,
)`}}),_e=new ce({}),Ue=new M({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyQSUyMGNpbmVtYXRpYyUyMGZpbG0lMjBzdGlsbCUyMG9mJTIwTW9yZ2FuJTIwRnJlZW1hbiUyMHN0YXJyaW5nJTIwYXMlMjBKaW1pJTIwSGVuZHJpeCUyQyUyMHBvcnRyYWl0JTJDJTIwNDBtbSUyMGxlbnMlMkMlMjBzaGFsbG93JTIwZGVwdGglMjBvZiUyMGZpZWxkJTJDJTIwY2xvc2UlMjB1cCUyQyUyMHNwbGl0JTIwbGlnaHRpbmclMkMlMjBjaW5lbWF0aWMlMjIlMEFwcm9tcHQlMjAlM0QlMjAlNUJwcm9tcHQlNUQlMjAqJTIwamF4LmRldmljZV9jb3VudCgpJTBBcHJvbXB0X2lkcyUyMCUzRCUyMHBpcGVsaW5lLnByZXBhcmVfaW5wdXRzKHByb21wdCklMEFwcm9tcHRfaWRzLnNoYXBl",highlighted:`prompt = <span class="hljs-string">&quot;A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of field, close up, split lighting, cinematic&quot;</span>
prompt = [prompt] * jax.device_count()
prompt_ids = pipeline.prepare_inputs(prompt)
prompt_ids.shape`}}),ke=new M({props:{code:"KDglMkMlMjA3Nyk=",highlighted:'(<span class="hljs-number">8</span>, <span class="hljs-number">77</span>)'}}),Ee=new ce({}),Ie=new M({props:{code:"cF9wYXJhbXMlMjAlM0QlMjByZXBsaWNhdGUocGFyYW1zKQ==",highlighted:"p_params = replicate(params)"}}),Be=new M({props:{code:"cHJvbXB0X2lkcyUyMCUzRCUyMHNoYXJkKHByb21wdF9pZHMpJTBBcHJvbXB0X2lkcy5zaGFwZQ==",highlighted:`prompt_ids = shard(prompt_ids)
prompt_ids.shape`}}),We=new M({props:{code:"KDglMkMlMjAxJTJDJTIwNzcp",highlighted:'(<span class="hljs-number">8</span>, <span class="hljs-number">1</span>, <span class="hljs-number">77</span>)'}}),Ce=new M({props:{code:"ZGVmJTIwY3JlYXRlX2tleShzZWVkJTNEMCklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBqYXgucmFuZG9tLlBSTkdLZXkoc2VlZCk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_key</span>(<span class="hljs-params">seed=<span class="hljs-number">0</span></span>):
    <span class="hljs-keyword">return</span> jax.random.PRNGKey(seed)`}}),Ge=new M({props:{code:"cm5nJTIwJTNEJTIwY3JlYXRlX2tleSgwKSUwQXJuZyUyMCUzRCUyMGpheC5yYW5kb20uc3BsaXQocm5nJTJDJTIwamF4LmRldmljZV9jb3VudCgpKQ==",highlighted:`rng = create_key(<span class="hljs-number">0</span>)
rng = jax.random.split(rng, jax.device_count())`}}),Ze=new M({props:{code:"JTI1JTI1dGltZSUwQWltYWdlcyUyMCUzRCUyMHBpcGVsaW5lKHByb21wdF9pZHMlMkMlMjBwX3BhcmFtcyUyQyUyMHJuZyUyQyUyMGppdCUzRFRydWUpJTVCMCU1RA==",highlighted:`%%time
images = pipeline(prompt_ids, p_params, rng, <span class="hljs-attribute">jit</span>=<span class="hljs-literal">True</span>)[0]`}}),Xe=new M({props:{code:"Q1BVJTIwdGltZXMlM0ElMjB1c2VyJTIwNTYuMiUyMHMlMkMlMjBzeXMlM0ElMjA0Mi41JTIwcyUyQyUyMHRvdGFsJTNBJTIwMW1pbiUyMDM4cyUwQVdhbGwlMjB0aW1lJTNBJTIwMW1pbiUyMDI5cw==",highlighted:`CPU times: user <span class="hljs-number">56.2</span> s, sys: <span class="hljs-number">42.5</span> s, total: 1<span class="hljs-built_in">min</span> 38s
Wall time: 1<span class="hljs-built_in">min</span> 29s`}}),xe=new M({props:{code:"aW1hZ2VzJTIwJTNEJTIwaW1hZ2VzLnJlc2hhcGUoKGltYWdlcy5zaGFwZSU1QjAlNUQlMjAqJTIwaW1hZ2VzLnNoYXBlJTVCMSU1RCUyQyklMjAlMkIlMjBpbWFnZXMuc2hhcGUlNUItMyUzQSU1RCklMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZS5udW1weV90b19waWwoaW1hZ2VzKQ==",highlighted:`images = images.reshape((images.shape[<span class="hljs-number">0</span>] * images.shape[<span class="hljs-number">1</span>],) + images.shape[-<span class="hljs-number">3</span>:])
images = pipeline.numpy_to_pil(images)`}}),Ae=new ce({}),Fe=new M({props:{code:"ZGVmJTIwaW1hZ2VfZ3JpZChpbWdzJTJDJTIwcm93cyUyQyUyMGNvbHMpJTNBJTBBJTIwJTIwJTIwJTIwdyUyQyUyMGglMjAlM0QlMjBpbWdzJTVCMCU1RC5zaXplJTBBJTIwJTIwJTIwJTIwZ3JpZCUyMCUzRCUyMEltYWdlLm5ldyglMjJSR0IlMjIlMkMlMjBzaXplJTNEKGNvbHMlMjAqJTIwdyUyQyUyMHJvd3MlMjAqJTIwaCkpJTBBJTIwJTIwJTIwJTIwZm9yJTIwaSUyQyUyMGltZyUyMGluJTIwZW51bWVyYXRlKGltZ3MpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ3JpZC5wYXN0ZShpbWclMkMlMjBib3glM0QoaSUyMCUyNSUyMGNvbHMlMjAqJTIwdyUyQyUyMGklMjAlMkYlMkYlMjBjb2xzJTIwKiUyMGgpKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGdyaWQ=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">image_grid</span>(<span class="hljs-params">imgs, rows, cols</span>):
    w, h = imgs[<span class="hljs-number">0</span>].size
    grid = Image.new(<span class="hljs-string">&quot;RGB&quot;</span>, size=(cols * w, rows * h))
    <span class="hljs-keyword">for</span> i, img <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(imgs):
        grid.paste(img, box=(i % cols * w, i // cols * h))
    <span class="hljs-keyword">return</span> grid`}}),ze=new M({props:{code:"aW1hZ2VfZ3JpZChpbWFnZXMlMkMlMjAyJTJDJTIwNCk=",highlighted:'image_grid(images, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>)'}}),Se=new ce({}),Ne=new M({props:{code:"cHJvbXB0cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMkxhYnJhZG9yJTIwaW4lMjB0aGUlMjBzdHlsZSUyMG9mJTIwSG9rdXNhaSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMlBhaW50aW5nJTIwb2YlMjBhJTIwc3F1aXJyZWwlMjBza2F0aW5nJTIwaW4lMjBOZXclMjBZb3JrJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIySEFMLTkwMDAlMjBpbiUyMHRoZSUyMHN0eWxlJTIwb2YlMjBWYW4lMjBHb2doJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyVGltZXMlMjBTcXVhcmUlMjB1bmRlciUyMHdhdGVyJTJDJTIwd2l0aCUyMGZpc2glMjBhbmQlMjBhJTIwZG9scGhpbiUyMHN3aW1taW5nJTIwYXJvdW5kJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyQW5jaWVudCUyMFJvbWFuJTIwZnJlc2NvJTIwc2hvd2luZyUyMGElMjBtYW4lMjB3b3JraW5nJTIwb24lMjBoaXMlMjBsYXB0b3AlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJDbG9zZS11cCUyMHBob3RvZ3JhcGglMjBvZiUyMHlvdW5nJTIwYmxhY2slMjB3b21hbiUyMGFnYWluc3QlMjB1cmJhbiUyMGJhY2tncm91bmQlMkMlMjBoaWdoJTIwcXVhbGl0eSUyQyUyMGJva2VoJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyQXJtY2hhaXIlMjBpbiUyMHRoZSUyMHNoYXBlJTIwb2YlMjBhbiUyMGF2b2NhZG8lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJDbG93biUyMGFzdHJvbmF1dCUyMGluJTIwc3BhY2UlMkMlMjB3aXRoJTIwRWFydGglMjBpbiUyMHRoZSUyMGJhY2tncm91bmQlMjIlMkMlMEElNUQ=",highlighted:`prompts = [
    <span class="hljs-string">&quot;Labrador in the style of Hokusai&quot;</span>,
    <span class="hljs-string">&quot;Painting of a squirrel skating in New York&quot;</span>,
    <span class="hljs-string">&quot;HAL-9000 in the style of Van Gogh&quot;</span>,
    <span class="hljs-string">&quot;Times Square under water, with fish and a dolphin swimming around&quot;</span>,
    <span class="hljs-string">&quot;Ancient Roman fresco showing a man working on his laptop&quot;</span>,
    <span class="hljs-string">&quot;Close-up photograph of young black woman against urban background, high quality, bokeh&quot;</span>,
    <span class="hljs-string">&quot;Armchair in the shape of an avocado&quot;</span>,
    <span class="hljs-string">&quot;Clown astronaut in space, with Earth in the background&quot;</span>,
]`}}),Pe=new M({props:{code:"cHJvbXB0X2lkcyUyMCUzRCUyMHBpcGVsaW5lLnByZXBhcmVfaW5wdXRzKHByb21wdHMpJTBBcHJvbXB0X2lkcyUyMCUzRCUyMHNoYXJkKHByb21wdF9pZHMpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0X2lkcyUyQyUyMHBfcGFyYW1zJTJDJTIwcm5nJTJDJTIwaml0JTNEVHJ1ZSkuaW1hZ2VzJTBBaW1hZ2VzJTIwJTNEJTIwaW1hZ2VzLnJlc2hhcGUoKGltYWdlcy5zaGFwZSU1QjAlNUQlMjAqJTIwaW1hZ2VzLnNoYXBlJTVCMSU1RCUyQyklMjAlMkIlMjBpbWFnZXMuc2hhcGUlNUItMyUzQSU1RCklMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZS5udW1weV90b19waWwoaW1hZ2VzKSUwQSUwQWltYWdlX2dyaWQoaW1hZ2VzJTJDJTIwMiUyQyUyMDQp",highlighted:`prompt_ids = pipeline.prepare_inputs(prompts)
prompt_ids = shard(prompt_ids)

images = pipeline(prompt_ids, p_params, rng, jit=<span class="hljs-literal">True</span>).images
images = images.reshape((images.shape[<span class="hljs-number">0</span>] * images.shape[<span class="hljs-number">1</span>],) + images.shape[-<span class="hljs-number">3</span>:])
images = pipeline.numpy_to_pil(images)

image_grid(images, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>)`}}),Ye=new ce({}),Qe=new M({props:{code:"cF9nZW5lcmF0ZSUyMCUzRCUyMHBtYXAocGlwZWxpbmUuX2dlbmVyYXRlKQ==",highlighted:"p_generate = pmap(pipeline._generate)"}}),Re=new M({props:{code:"JTI1JTI1dGltZSUwQWltYWdlcyUyMCUzRCUyMHBfZ2VuZXJhdGUocHJvbXB0X2lkcyUyQyUyMHBfcGFyYW1zJTJDJTIwcm5nKSUwQWltYWdlcyUyMCUzRCUyMGltYWdlcy5ibG9ja191bnRpbF9yZWFkeSgpJTBBaW1hZ2VzLnNoYXBl",highlighted:`%%time
images = p<span class="hljs-constructor">_generate(<span class="hljs-params">prompt_ids</span>, <span class="hljs-params">p_params</span>, <span class="hljs-params">rng</span>)</span>
images = images.block<span class="hljs-constructor">_until_ready()</span>
images.shape`}}),qe=new M({props:{code:"Q1BVJTIwdGltZXMlM0ElMjB1c2VyJTIwMW1pbiUyMDE1cyUyQyUyMHN5cyUzQSUyMDE4LjIlMjBzJTJDJTIwdG90YWwlM0ElMjAxbWluJTIwMzRzJTBBV2FsbCUyMHRpbWUlM0ElMjAxbWluJTIwMTVz",highlighted:`CPU times: user 1<span class="hljs-built_in">min</span> 15s, sys: <span class="hljs-number">18.2</span> s, total: 1<span class="hljs-built_in">min</span> 34s
Wall time: 1<span class="hljs-built_in">min</span> 15s`}}),Le=new M({props:{code:"aW1hZ2VzLnNoYXBl",highlighted:"images.shape"}}),Oe=new M({props:{code:"KDglMkMlMjAxJTJDJTIwNTEyJTJDJTIwNTEyJTJDJTIwMyk=",highlighted:'(<span class="hljs-number">8</span>, <span class="hljs-number">1</span>, <span class="hljs-number">512</span>, <span class="hljs-number">512</span>, <span class="hljs-number">3</span>)'}}),{c(){G=i("meta"),$l=h(),Z=i("h1"),P=i("a"),vt=i("span"),d(de.$$.fragment),is=h(),Jt=i("span"),ns=s("\u{1F9E8} Stable Diffusion in JAX / Flax !"),_l=h(),d(me.$$.fragment),Ul=h(),k=i("p"),rs=s("\u{1F917} Hugging Face "),ue=i("a"),ps=s("Diffusers"),hs=s(" supports Flax since version "),Tt=i("code"),fs=s("0.5.1"),cs=s("! This allows for super fast inference on Google TPUs, such as those available in Colab, Kaggle or Google Cloud Platform."),kl=h(),Y=i("p"),ds=s("This notebook shows how to run inference using JAX / Flax. If you want more details about how Stable Diffusion works or want to run it in GPU, please refer to "),we=i("a"),ms=s("this notebook"),us=s("."),El=h(),T=i("p"),ws=s("First, make sure you are using a TPU backend. If you are running this notebook in Colab, select "),jt=i("code"),ys=s("Runtime"),bs=s(" in the menu above, then select the option \u201CChange runtime type\u201D and then select "),gt=i("code"),Ms=s("TPU"),vs=s(" under the "),$t=i("code"),Js=s("Hardware accelerator"),Ts=s(" setting."),Il=h(),Ke=i("p"),js=s("Note that JAX is not exclusive to TPUs, but it shines on that hardware because each TPU server has 8 TPU accelerators working in parallel."),Bl=h(),X=i("h2"),H=i("a"),_t=i("span"),d(ye.$$.fragment),gs=h(),Ut=i("span"),$s=s("Setup"),Wl=h(),et=i("p"),_s=s("First make sure diffusers is installed."),Cl=h(),d(be.$$.fragment),Gl=h(),d(Me.$$.fragment),Zl=h(),d(ve.$$.fragment),Xl=h(),d(Je.$$.fragment),xl=h(),tt=i("p"),Us=s("Then we import all the dependencies."),Al=h(),d(Te.$$.fragment),Fl=h(),x=i("h2"),V=i("a"),kt=i("span"),d(je.$$.fragment),ks=h(),Et=i("span"),Es=s("Model Loading"),zl=h(),E=i("p"),Is=s("TPU devices support "),It=i("code"),Bs=s("bfloat16"),Ws=s(", an efficient half-float type. We\u2019ll use it for our tests, but you can also use "),Bt=i("code"),Cs=s("float32"),Gs=s(" to use full precision instead."),Sl=h(),d(ge.$$.fragment),Nl=h(),Q=i("p"),Zs=s("Flax is a functional framework, so models are stateless and parameters are stored outside them. Loading the pre-trained Flax pipeline will return both the pipeline itself and the model weights (or parameters). We are using a "),Wt=i("code"),Xs=s("bf16"),xs=s(" version of the weights, which leads to type warnings that you can safely ignore."),Pl=h(),d($e.$$.fragment),Yl=h(),A=i("h2"),D=i("a"),Ct=i("span"),d(_e.$$.fragment),As=h(),Gt=i("span"),Fs=s("Inference"),Hl=h(),lt=i("p"),zs=s("Since TPUs usually have 8 devices working in parallel, we\u2019ll replicate our prompt as many times as devices we have. Then we\u2019ll perform inference on the 8 devices at once, each responsible for generating one image. Thus, we\u2019ll get 8 images in the same amount of time it takes for one chip to generate a single one."),Vl=h(),R=i("p"),Ss=s("After replicating the prompt, we obtain the tokenized text ids by invoking the "),Zt=i("code"),Ns=s("prepare_inputs"),Ps=s(" function of the pipeline. The length of the tokenized text is set to 77 tokens, as required by the configuration of the underlying CLIP Text model."),Ql=h(),d(Ue.$$.fragment),Dl=h(),d(ke.$$.fragment),Rl=h(),F=i("h3"),q=i("a"),Xt=i("span"),d(Ee.$$.fragment),Ys=h(),xt=i("span"),Hs=s("Replication and parallelization"),ql=h(),I=i("p"),Vs=s("Model parameters and inputs have to be replicated across the 8 parallel devices we have. The parameters dictionary is replicated using "),At=i("code"),Qs=s("flax.jax_utils.replicate"),Ds=s(", which traverses the dictionary and changes the shape of the weights so they are repeated 8 times. Arrays are replicated using "),Ft=i("code"),Rs=s("shard"),qs=s("."),Ll=h(),d(Ie.$$.fragment),Ol=h(),d(Be.$$.fragment),Kl=h(),d(We.$$.fragment),ea=h(),v=i("p"),Ls=s("That shape means that each one of the "),zt=i("code"),Os=s("8"),Ks=s(" devices will receive as an input a "),St=i("code"),eo=s("jnp"),to=s(" array with shape "),Nt=i("code"),lo=s("(1, 77)"),ao=s(". "),Pt=i("code"),so=s("1"),oo=s(" is therefore the batch size per device. In TPUs with sufficient memory, it could be larger than "),Yt=i("code"),io=s("1"),no=s(" if we wanted to generate multiple images (per chip) at once."),ta=h(),at=i("p"),ro=s("We are almost ready to generate images! We just need to create a random number generator to pass to the generation function. This is the standard procedure in Flax, which is very serious and opinionated about random numbers \u2013 all functions that deal with random numbers are expected to receive a generator. This ensures reproducibility, even when we are training across multiple distributed devices."),la=h(),st=i("p"),po=s("The helper function below uses a seed to initialize a random number generator. As long as we use the same seed, we\u2019ll get the exact same results. Feel free to use different seeds when exploring results later in the notebook."),aa=h(),d(Ce.$$.fragment),sa=h(),ot=i("p"),ho=s("We obtain a rng and then \u201Csplit\u201D it 8 times so each device receives a different generator. Therefore, each device will create a different image, and the full process is reproducible."),oa=h(),d(Ge.$$.fragment),ia=h(),it=i("p"),fo=s("JAX code can be compiled to an efficient representation that runs very fast. However, we need to ensure that all inputs have the same shape in subsequent calls; otherwise, JAX will have to recompile the code, and we wouldn\u2019t be able to take advantage of the optimized speed."),na=h(),L=i("p"),co=s("The Flax pipeline can compile the code for us if we pass "),Ht=i("code"),mo=s("jit = True"),uo=s(" as an argument. It will also ensure that the model runs in parallel in the 8 available devices."),ra=h(),O=i("p"),wo=s("The first time we run the following cell it will take a long time to compile, but subequent calls (even with different inputs) will be much faster. For example, it took more than a minute to compile in a TPU v2-8 when I tested, but then it takes about "),Vt=i("strong"),Qt=i("code"),yo=s("7s"),bo=s(" for future inference runs."),pa=h(),d(Ze.$$.fragment),ha=h(),d(Xe.$$.fragment),fa=h(),B=i("p"),Mo=s("The returned array has shape "),Dt=i("code"),vo=s("(8, 1, 512, 512, 3)"),Jo=s(". We reshape it to get rid of the second dimension and obtain 8 images of "),Rt=i("code"),To=s("512 \xD7 512 \xD7 3"),jo=s(" and then convert them to PIL."),ca=h(),d(xe.$$.fragment),da=h(),z=i("h3"),K=i("a"),qt=i("span"),d(Ae.$$.fragment),go=h(),Lt=i("span"),$o=s("Visualization"),ma=h(),nt=i("p"),_o=s("Let\u2019s create a helper function to display images in a grid."),ua=h(),d(Fe.$$.fragment),wa=h(),d(ze.$$.fragment),ya=h(),rt=i("p"),pt=i("img"),ba=h(),S=i("h2"),ee=i("a"),Ot=i("span"),d(Se.$$.fragment),Uo=h(),Kt=i("span"),ko=s("Using different prompts"),Ma=h(),te=i("p"),Eo=s("We don\u2019t have to replicate the "),el=i("em"),Io=s("same"),Bo=s(" prompt in all the devices. We can do whatever we want: generate 2 prompts 4 times each, or even generate 8 different prompts at once. Let\u2019s do that!"),va=h(),ht=i("p"),Wo=s("First, we\u2019ll refactor the input preparation code into a handy function:"),Ja=h(),d(Ne.$$.fragment),Ta=h(),d(Pe.$$.fragment),ja=h(),ft=i("p"),ct=i("img"),ga=h(),N=i("h2"),le=i("a"),tl=i("span"),d(Ye.$$.fragment),Co=h(),ll=i("span"),Go=s("How does parallelization work?"),$a=h(),ae=i("p"),Zo=s("We said before that the "),al=i("code"),Xo=s("diffusers"),xo=s(" Flax pipeline automatically compiles the model and runs it in parallel on all available devices. We\u2019ll now briefly look inside that process to show how it works."),_a=h(),j=i("p"),Ao=s("JAX parallelization can be done in multiple ways. The easiest one revolves around using the "),sl=i("code"),Fo=s("jax.pmap"),zo=s(" function to achieve single-program, multiple-data (SPMD) parallelization. It means we\u2019ll run several copies of the same code, each on different data inputs. More sophisticated approaches are possible, we invite you to go over the "),He=i("a"),So=s("JAX documentation"),No=s(" and the "),se=i("a"),ol=i("code"),Po=s("pjit"),Yo=s(" pages"),Ho=s(" to explore this topic if you are interested!"),Ua=h(),Ve=i("p"),il=i("code"),Vo=s("jax.pmap"),Qo=s(" does two things for us:"),ka=h(),oe=i("ul"),U=i("li"),Do=s("Compiles (or "),nl=i("code"),Ro=s("jit"),qo=s("s) the code, as if we had invoked "),rl=i("code"),Lo=s("jax.jit()"),Oo=s(". This does not happen when we call "),pl=i("code"),Ko=s("pmap"),ei=s(", but the first time the pmapped function is invoked."),ti=h(),hl=i("li"),li=s("Ensures the compiled code runs in parallel in all the available devices."),Ea=h(),g=i("p"),ai=s("To show how it works we "),fl=i("code"),si=s("pmap"),oi=s(" the "),cl=i("code"),ii=s("_generate"),ni=s(" method of the pipeline, which is the private method that runs generates images. Please, note that this method may be renamed or removed in future releases of "),dl=i("code"),ri=s("diffusers"),pi=s("."),Ia=h(),d(Qe.$$.fragment),Ba=h(),W=i("p"),hi=s("After we use "),ml=i("code"),fi=s("pmap"),ci=s(", the prepared function "),ul=i("code"),di=s("p_generate"),mi=s(" will conceptually do the following:"),Wa=h(),ie=i("ul"),De=i("li"),ui=s("Invoke a copy of the underlying function "),wl=i("code"),wi=s("pipeline._generate"),yi=s(" in each device."),bi=h(),J=i("li"),Mi=s("Send each device a different portion of the input arguments. That\u2019s what sharding is used for. In our case, "),yl=i("code"),vi=s("prompt_ids"),Ji=s(" has shape "),bl=i("code"),Ti=s("(8, 1, 77, 768)"),ji=s(". This array will be split in "),Ml=i("code"),gi=s("8"),$i=s(" and each copy of "),vl=i("code"),_i=s("_generate"),Ui=s(" will receive an input with shape "),Jl=i("code"),ki=s("(1, 77, 768)"),Ei=s("."),Ca=h(),C=i("p"),Ii=s("We can code "),Tl=i("code"),Bi=s("_generate"),Wi=s(" completely ignoring the fact that it will be invoked in parallel. We just care about our batch size ("),jl=i("code"),Ci=s("1"),Gi=s(" in this example) and the dimensions that make sense for our code, and don\u2019t have to change anything to make it work in parallel."),Ga=h(),dt=i("p"),Zi=s("The same way as when we used the pipeline call, the first time we run the following cell it will take a while, but then it will be much faster."),Za=h(),d(Re.$$.fragment),Xa=h(),d(qe.$$.fragment),xa=h(),d(Le.$$.fragment),Aa=h(),d(Oe.$$.fragment),Fa=h(),ne=i("p"),Xi=s("We use "),gl=i("code"),xi=s("block_until_ready()"),Ai=s(" to correctly measure inference time, because JAX uses asynchronous dispatch and returns control to the Python loop as soon as it can. You don\u2019t need to use that in your code; blocking will occur automatically when you want to use the result of a computation that has not yet been materialized."),this.h()},l(e){const a=gr('[data-svelte="svelte-1phssyn"]',document.head);G=n(a,"META",{name:!0,content:!0}),a.forEach(t),$l=f(e),Z=n(e,"H1",{class:!0});var Sa=r(Z);P=n(Sa,"A",{id:!0,class:!0,href:!0});var Yi=r(P);vt=n(Yi,"SPAN",{});var Hi=r(vt);m(de.$$.fragment,Hi),Hi.forEach(t),Yi.forEach(t),is=f(Sa),Jt=n(Sa,"SPAN",{});var Vi=r(Jt);ns=o(Vi,"\u{1F9E8} Stable Diffusion in JAX / Flax !"),Vi.forEach(t),Sa.forEach(t),_l=f(e),m(me.$$.fragment,e),Ul=f(e),k=n(e,"P",{});var mt=r(k);rs=o(mt,"\u{1F917} Hugging Face "),ue=n(mt,"A",{href:!0,rel:!0});var Qi=r(ue);ps=o(Qi,"Diffusers"),Qi.forEach(t),hs=o(mt," supports Flax since version "),Tt=n(mt,"CODE",{});var Di=r(Tt);fs=o(Di,"0.5.1"),Di.forEach(t),cs=o(mt,"! This allows for super fast inference on Google TPUs, such as those available in Colab, Kaggle or Google Cloud Platform."),mt.forEach(t),kl=f(e),Y=n(e,"P",{});var Na=r(Y);ds=o(Na,"This notebook shows how to run inference using JAX / Flax. If you want more details about how Stable Diffusion works or want to run it in GPU, please refer to "),we=n(Na,"A",{href:!0,rel:!0});var Ri=r(we);ms=o(Ri,"this notebook"),Ri.forEach(t),us=o(Na,"."),Na.forEach(t),El=f(e),T=n(e,"P",{});var re=r(T);ws=o(re,"First, make sure you are using a TPU backend. If you are running this notebook in Colab, select "),jt=n(re,"CODE",{});var qi=r(jt);ys=o(qi,"Runtime"),qi.forEach(t),bs=o(re," in the menu above, then select the option \u201CChange runtime type\u201D and then select "),gt=n(re,"CODE",{});var Li=r(gt);Ms=o(Li,"TPU"),Li.forEach(t),vs=o(re," under the "),$t=n(re,"CODE",{});var Oi=r($t);Js=o(Oi,"Hardware accelerator"),Oi.forEach(t),Ts=o(re," setting."),re.forEach(t),Il=f(e),Ke=n(e,"P",{});var Ki=r(Ke);js=o(Ki,"Note that JAX is not exclusive to TPUs, but it shines on that hardware because each TPU server has 8 TPU accelerators working in parallel."),Ki.forEach(t),Bl=f(e),X=n(e,"H2",{class:!0});var Pa=r(X);H=n(Pa,"A",{id:!0,class:!0,href:!0});var en=r(H);_t=n(en,"SPAN",{});var tn=r(_t);m(ye.$$.fragment,tn),tn.forEach(t),en.forEach(t),gs=f(Pa),Ut=n(Pa,"SPAN",{});var ln=r(Ut);$s=o(ln,"Setup"),ln.forEach(t),Pa.forEach(t),Wl=f(e),et=n(e,"P",{});var an=r(et);_s=o(an,"First make sure diffusers is installed."),an.forEach(t),Cl=f(e),m(be.$$.fragment,e),Gl=f(e),m(Me.$$.fragment,e),Zl=f(e),m(ve.$$.fragment,e),Xl=f(e),m(Je.$$.fragment,e),xl=f(e),tt=n(e,"P",{});var sn=r(tt);Us=o(sn,"Then we import all the dependencies."),sn.forEach(t),Al=f(e),m(Te.$$.fragment,e),Fl=f(e),x=n(e,"H2",{class:!0});var Ya=r(x);V=n(Ya,"A",{id:!0,class:!0,href:!0});var on=r(V);kt=n(on,"SPAN",{});var nn=r(kt);m(je.$$.fragment,nn),nn.forEach(t),on.forEach(t),ks=f(Ya),Et=n(Ya,"SPAN",{});var rn=r(Et);Es=o(rn,"Model Loading"),rn.forEach(t),Ya.forEach(t),zl=f(e),E=n(e,"P",{});var ut=r(E);Is=o(ut,"TPU devices support "),It=n(ut,"CODE",{});var pn=r(It);Bs=o(pn,"bfloat16"),pn.forEach(t),Ws=o(ut,", an efficient half-float type. We\u2019ll use it for our tests, but you can also use "),Bt=n(ut,"CODE",{});var hn=r(Bt);Cs=o(hn,"float32"),hn.forEach(t),Gs=o(ut," to use full precision instead."),ut.forEach(t),Sl=f(e),m(ge.$$.fragment,e),Nl=f(e),Q=n(e,"P",{});var Ha=r(Q);Zs=o(Ha,"Flax is a functional framework, so models are stateless and parameters are stored outside them. Loading the pre-trained Flax pipeline will return both the pipeline itself and the model weights (or parameters). We are using a "),Wt=n(Ha,"CODE",{});var fn=r(Wt);Xs=o(fn,"bf16"),fn.forEach(t),xs=o(Ha," version of the weights, which leads to type warnings that you can safely ignore."),Ha.forEach(t),Pl=f(e),m($e.$$.fragment,e),Yl=f(e),A=n(e,"H2",{class:!0});var Va=r(A);D=n(Va,"A",{id:!0,class:!0,href:!0});var cn=r(D);Ct=n(cn,"SPAN",{});var dn=r(Ct);m(_e.$$.fragment,dn),dn.forEach(t),cn.forEach(t),As=f(Va),Gt=n(Va,"SPAN",{});var mn=r(Gt);Fs=o(mn,"Inference"),mn.forEach(t),Va.forEach(t),Hl=f(e),lt=n(e,"P",{});var un=r(lt);zs=o(un,"Since TPUs usually have 8 devices working in parallel, we\u2019ll replicate our prompt as many times as devices we have. Then we\u2019ll perform inference on the 8 devices at once, each responsible for generating one image. Thus, we\u2019ll get 8 images in the same amount of time it takes for one chip to generate a single one."),un.forEach(t),Vl=f(e),R=n(e,"P",{});var Qa=r(R);Ss=o(Qa,"After replicating the prompt, we obtain the tokenized text ids by invoking the "),Zt=n(Qa,"CODE",{});var wn=r(Zt);Ns=o(wn,"prepare_inputs"),wn.forEach(t),Ps=o(Qa," function of the pipeline. The length of the tokenized text is set to 77 tokens, as required by the configuration of the underlying CLIP Text model."),Qa.forEach(t),Ql=f(e),m(Ue.$$.fragment,e),Dl=f(e),m(ke.$$.fragment,e),Rl=f(e),F=n(e,"H3",{class:!0});var Da=r(F);q=n(Da,"A",{id:!0,class:!0,href:!0});var yn=r(q);Xt=n(yn,"SPAN",{});var bn=r(Xt);m(Ee.$$.fragment,bn),bn.forEach(t),yn.forEach(t),Ys=f(Da),xt=n(Da,"SPAN",{});var Mn=r(xt);Hs=o(Mn,"Replication and parallelization"),Mn.forEach(t),Da.forEach(t),ql=f(e),I=n(e,"P",{});var wt=r(I);Vs=o(wt,"Model parameters and inputs have to be replicated across the 8 parallel devices we have. The parameters dictionary is replicated using "),At=n(wt,"CODE",{});var vn=r(At);Qs=o(vn,"flax.jax_utils.replicate"),vn.forEach(t),Ds=o(wt,", which traverses the dictionary and changes the shape of the weights so they are repeated 8 times. Arrays are replicated using "),Ft=n(wt,"CODE",{});var Jn=r(Ft);Rs=o(Jn,"shard"),Jn.forEach(t),qs=o(wt,"."),wt.forEach(t),Ll=f(e),m(Ie.$$.fragment,e),Ol=f(e),m(Be.$$.fragment,e),Kl=f(e),m(We.$$.fragment,e),ea=f(e),v=n(e,"P",{});var $=r(v);Ls=o($,"That shape means that each one of the "),zt=n($,"CODE",{});var Tn=r(zt);Os=o(Tn,"8"),Tn.forEach(t),Ks=o($," devices will receive as an input a "),St=n($,"CODE",{});var jn=r(St);eo=o(jn,"jnp"),jn.forEach(t),to=o($," array with shape "),Nt=n($,"CODE",{});var gn=r(Nt);lo=o(gn,"(1, 77)"),gn.forEach(t),ao=o($,". "),Pt=n($,"CODE",{});var $n=r(Pt);so=o($n,"1"),$n.forEach(t),oo=o($," is therefore the batch size per device. In TPUs with sufficient memory, it could be larger than "),Yt=n($,"CODE",{});var _n=r(Yt);io=o(_n,"1"),_n.forEach(t),no=o($," if we wanted to generate multiple images (per chip) at once."),$.forEach(t),ta=f(e),at=n(e,"P",{});var Un=r(at);ro=o(Un,"We are almost ready to generate images! We just need to create a random number generator to pass to the generation function. This is the standard procedure in Flax, which is very serious and opinionated about random numbers \u2013 all functions that deal with random numbers are expected to receive a generator. This ensures reproducibility, even when we are training across multiple distributed devices."),Un.forEach(t),la=f(e),st=n(e,"P",{});var kn=r(st);po=o(kn,"The helper function below uses a seed to initialize a random number generator. As long as we use the same seed, we\u2019ll get the exact same results. Feel free to use different seeds when exploring results later in the notebook."),kn.forEach(t),aa=f(e),m(Ce.$$.fragment,e),sa=f(e),ot=n(e,"P",{});var En=r(ot);ho=o(En,"We obtain a rng and then \u201Csplit\u201D it 8 times so each device receives a different generator. Therefore, each device will create a different image, and the full process is reproducible."),En.forEach(t),oa=f(e),m(Ge.$$.fragment,e),ia=f(e),it=n(e,"P",{});var In=r(it);fo=o(In,"JAX code can be compiled to an efficient representation that runs very fast. However, we need to ensure that all inputs have the same shape in subsequent calls; otherwise, JAX will have to recompile the code, and we wouldn\u2019t be able to take advantage of the optimized speed."),In.forEach(t),na=f(e),L=n(e,"P",{});var Ra=r(L);co=o(Ra,"The Flax pipeline can compile the code for us if we pass "),Ht=n(Ra,"CODE",{});var Bn=r(Ht);mo=o(Bn,"jit = True"),Bn.forEach(t),uo=o(Ra," as an argument. It will also ensure that the model runs in parallel in the 8 available devices."),Ra.forEach(t),ra=f(e),O=n(e,"P",{});var qa=r(O);wo=o(qa,"The first time we run the following cell it will take a long time to compile, but subequent calls (even with different inputs) will be much faster. For example, it took more than a minute to compile in a TPU v2-8 when I tested, but then it takes about "),Vt=n(qa,"STRONG",{});var Wn=r(Vt);Qt=n(Wn,"CODE",{});var Cn=r(Qt);yo=o(Cn,"7s"),Cn.forEach(t),Wn.forEach(t),bo=o(qa," for future inference runs."),qa.forEach(t),pa=f(e),m(Ze.$$.fragment,e),ha=f(e),m(Xe.$$.fragment,e),fa=f(e),B=n(e,"P",{});var yt=r(B);Mo=o(yt,"The returned array has shape "),Dt=n(yt,"CODE",{});var Gn=r(Dt);vo=o(Gn,"(8, 1, 512, 512, 3)"),Gn.forEach(t),Jo=o(yt,". We reshape it to get rid of the second dimension and obtain 8 images of "),Rt=n(yt,"CODE",{});var Zn=r(Rt);To=o(Zn,"512 \xD7 512 \xD7 3"),Zn.forEach(t),jo=o(yt," and then convert them to PIL."),yt.forEach(t),ca=f(e),m(xe.$$.fragment,e),da=f(e),z=n(e,"H3",{class:!0});var La=r(z);K=n(La,"A",{id:!0,class:!0,href:!0});var Xn=r(K);qt=n(Xn,"SPAN",{});var xn=r(qt);m(Ae.$$.fragment,xn),xn.forEach(t),Xn.forEach(t),go=f(La),Lt=n(La,"SPAN",{});var An=r(Lt);$o=o(An,"Visualization"),An.forEach(t),La.forEach(t),ma=f(e),nt=n(e,"P",{});var Fn=r(nt);_o=o(Fn,"Let\u2019s create a helper function to display images in a grid."),Fn.forEach(t),ua=f(e),m(Fe.$$.fragment,e),wa=f(e),m(ze.$$.fragment,e),ya=f(e),rt=n(e,"P",{});var zn=r(rt);pt=n(zn,"IMG",{src:!0,alt:!0}),zn.forEach(t),ba=f(e),S=n(e,"H2",{class:!0});var Oa=r(S);ee=n(Oa,"A",{id:!0,class:!0,href:!0});var Sn=r(ee);Ot=n(Sn,"SPAN",{});var Nn=r(Ot);m(Se.$$.fragment,Nn),Nn.forEach(t),Sn.forEach(t),Uo=f(Oa),Kt=n(Oa,"SPAN",{});var Pn=r(Kt);ko=o(Pn,"Using different prompts"),Pn.forEach(t),Oa.forEach(t),Ma=f(e),te=n(e,"P",{});var Ka=r(te);Eo=o(Ka,"We don\u2019t have to replicate the "),el=n(Ka,"EM",{});var Yn=r(el);Io=o(Yn,"same"),Yn.forEach(t),Bo=o(Ka," prompt in all the devices. We can do whatever we want: generate 2 prompts 4 times each, or even generate 8 different prompts at once. Let\u2019s do that!"),Ka.forEach(t),va=f(e),ht=n(e,"P",{});var Hn=r(ht);Wo=o(Hn,"First, we\u2019ll refactor the input preparation code into a handy function:"),Hn.forEach(t),Ja=f(e),m(Ne.$$.fragment,e),Ta=f(e),m(Pe.$$.fragment,e),ja=f(e),ft=n(e,"P",{});var Vn=r(ft);ct=n(Vn,"IMG",{src:!0,alt:!0}),Vn.forEach(t),ga=f(e),N=n(e,"H2",{class:!0});var es=r(N);le=n(es,"A",{id:!0,class:!0,href:!0});var Qn=r(le);tl=n(Qn,"SPAN",{});var Dn=r(tl);m(Ye.$$.fragment,Dn),Dn.forEach(t),Qn.forEach(t),Co=f(es),ll=n(es,"SPAN",{});var Rn=r(ll);Go=o(Rn,"How does parallelization work?"),Rn.forEach(t),es.forEach(t),$a=f(e),ae=n(e,"P",{});var ts=r(ae);Zo=o(ts,"We said before that the "),al=n(ts,"CODE",{});var qn=r(al);Xo=o(qn,"diffusers"),qn.forEach(t),xo=o(ts," Flax pipeline automatically compiles the model and runs it in parallel on all available devices. We\u2019ll now briefly look inside that process to show how it works."),ts.forEach(t),_a=f(e),j=n(e,"P",{});var pe=r(j);Ao=o(pe,"JAX parallelization can be done in multiple ways. The easiest one revolves around using the "),sl=n(pe,"CODE",{});var Ln=r(sl);Fo=o(Ln,"jax.pmap"),Ln.forEach(t),zo=o(pe," function to achieve single-program, multiple-data (SPMD) parallelization. It means we\u2019ll run several copies of the same code, each on different data inputs. More sophisticated approaches are possible, we invite you to go over the "),He=n(pe,"A",{href:!0,rel:!0});var On=r(He);So=o(On,"JAX documentation"),On.forEach(t),No=o(pe," and the "),se=n(pe,"A",{href:!0,rel:!0});var Fi=r(se);ol=n(Fi,"CODE",{});var Kn=r(ol);Po=o(Kn,"pjit"),Kn.forEach(t),Yo=o(Fi," pages"),Fi.forEach(t),Ho=o(pe," to explore this topic if you are interested!"),pe.forEach(t),Ua=f(e),Ve=n(e,"P",{});var zi=r(Ve);il=n(zi,"CODE",{});var er=r(il);Vo=o(er,"jax.pmap"),er.forEach(t),Qo=o(zi," does two things for us:"),zi.forEach(t),ka=f(e),oe=n(e,"UL",{});var ls=r(oe);U=n(ls,"LI",{});var he=r(U);Do=o(he,"Compiles (or "),nl=n(he,"CODE",{});var tr=r(nl);Ro=o(tr,"jit"),tr.forEach(t),qo=o(he,"s) the code, as if we had invoked "),rl=n(he,"CODE",{});var lr=r(rl);Lo=o(lr,"jax.jit()"),lr.forEach(t),Oo=o(he,". This does not happen when we call "),pl=n(he,"CODE",{});var ar=r(pl);Ko=o(ar,"pmap"),ar.forEach(t),ei=o(he,", but the first time the pmapped function is invoked."),he.forEach(t),ti=f(ls),hl=n(ls,"LI",{});var sr=r(hl);li=o(sr,"Ensures the compiled code runs in parallel in all the available devices."),sr.forEach(t),ls.forEach(t),Ea=f(e),g=n(e,"P",{});var fe=r(g);ai=o(fe,"To show how it works we "),fl=n(fe,"CODE",{});var or=r(fl);si=o(or,"pmap"),or.forEach(t),oi=o(fe," the "),cl=n(fe,"CODE",{});var ir=r(cl);ii=o(ir,"_generate"),ir.forEach(t),ni=o(fe," method of the pipeline, which is the private method that runs generates images. Please, note that this method may be renamed or removed in future releases of "),dl=n(fe,"CODE",{});var nr=r(dl);ri=o(nr,"diffusers"),nr.forEach(t),pi=o(fe,"."),fe.forEach(t),Ia=f(e),m(Qe.$$.fragment,e),Ba=f(e),W=n(e,"P",{});var bt=r(W);hi=o(bt,"After we use "),ml=n(bt,"CODE",{});var rr=r(ml);fi=o(rr,"pmap"),rr.forEach(t),ci=o(bt,", the prepared function "),ul=n(bt,"CODE",{});var pr=r(ul);di=o(pr,"p_generate"),pr.forEach(t),mi=o(bt," will conceptually do the following:"),bt.forEach(t),Wa=f(e),ie=n(e,"UL",{});var as=r(ie);De=n(as,"LI",{});var ss=r(De);ui=o(ss,"Invoke a copy of the underlying function "),wl=n(ss,"CODE",{});var hr=r(wl);wi=o(hr,"pipeline._generate"),hr.forEach(t),yi=o(ss," in each device."),ss.forEach(t),bi=f(as),J=n(as,"LI",{});var _=r(J);Mi=o(_,"Send each device a different portion of the input arguments. That\u2019s what sharding is used for. In our case, "),yl=n(_,"CODE",{});var fr=r(yl);vi=o(fr,"prompt_ids"),fr.forEach(t),Ji=o(_," has shape "),bl=n(_,"CODE",{});var cr=r(bl);Ti=o(cr,"(8, 1, 77, 768)"),cr.forEach(t),ji=o(_,". This array will be split in "),Ml=n(_,"CODE",{});var dr=r(Ml);gi=o(dr,"8"),dr.forEach(t),$i=o(_," and each copy of "),vl=n(_,"CODE",{});var mr=r(vl);_i=o(mr,"_generate"),mr.forEach(t),Ui=o(_," will receive an input with shape "),Jl=n(_,"CODE",{});var ur=r(Jl);ki=o(ur,"(1, 77, 768)"),ur.forEach(t),Ei=o(_,"."),_.forEach(t),as.forEach(t),Ca=f(e),C=n(e,"P",{});var Mt=r(C);Ii=o(Mt,"We can code "),Tl=n(Mt,"CODE",{});var wr=r(Tl);Bi=o(wr,"_generate"),wr.forEach(t),Wi=o(Mt," completely ignoring the fact that it will be invoked in parallel. We just care about our batch size ("),jl=n(Mt,"CODE",{});var yr=r(jl);Ci=o(yr,"1"),yr.forEach(t),Gi=o(Mt," in this example) and the dimensions that make sense for our code, and don\u2019t have to change anything to make it work in parallel."),Mt.forEach(t),Ga=f(e),dt=n(e,"P",{});var br=r(dt);Zi=o(br,"The same way as when we used the pipeline call, the first time we run the following cell it will take a while, but then it will be much faster."),br.forEach(t),Za=f(e),m(Re.$$.fragment,e),Xa=f(e),m(qe.$$.fragment,e),xa=f(e),m(Le.$$.fragment,e),Aa=f(e),m(Oe.$$.fragment,e),Fa=f(e),ne=n(e,"P",{});var os=r(ne);Xi=o(os,"We use "),gl=n(os,"CODE",{});var Mr=r(gl);xi=o(Mr,"block_until_ready()"),Mr.forEach(t),Ai=o(os," to correctly measure inference time, because JAX uses asynchronous dispatch and returns control to the Python loop as soon as it can. You don\u2019t need to use that in your code; blocking will occur automatically when you want to use the result of a computation that has not yet been materialized."),os.forEach(t),this.h()},h(){c(G,"name","hf:doc:metadata"),c(G,"content",JSON.stringify(Er)),c(P,"id","stable-diffusion-in-jax-flax"),c(P,"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"),c(P,"href","#stable-diffusion-in-jax-flax"),c(Z,"class","relative group"),c(ue,"href","https://github.com/huggingface/diffusers"),c(ue,"rel","nofollow"),c(we,"href","https://huggingface.co/docs/diffusers/stable_diffusion"),c(we,"rel","nofollow"),c(H,"id","setup"),c(H,"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"),c(H,"href","#setup"),c(X,"class","relative group"),c(V,"id","model-loading"),c(V,"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"),c(V,"href","#model-loading"),c(x,"class","relative group"),c(D,"id","inference"),c(D,"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"),c(D,"href","#inference"),c(A,"class","relative group"),c(q,"id","replication-and-parallelization"),c(q,"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"),c(q,"href","#replication-and-parallelization"),c(F,"class","relative group"),c(K,"id","visualization"),c(K,"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"),c(K,"href","#visualization"),c(z,"class","relative group"),vr(pt.src,Ni="https://huggingface.co/datasets/YiYiXu/test-doc-assets/resolve/main/stable_diffusion_jax_how_to_cell_38_output_0.jpeg")||c(pt,"src",Ni),c(pt,"alt","img"),c(ee,"id","using-different-prompts"),c(ee,"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"),c(ee,"href","#using-different-prompts"),c(S,"class","relative group"),vr(ct.src,Pi="https://huggingface.co/datasets/YiYiXu/test-doc-assets/resolve/main/stable_diffusion_jax_how_to_cell_43_output_0.jpeg")||c(ct,"src",Pi),c(ct,"alt","img"),c(le,"id","how-does-parallelization-work"),c(le,"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"),c(le,"href","#how-does-parallelization-work"),c(N,"class","relative group"),c(He,"href","https://jax.readthedocs.io/en/latest/index.html"),c(He,"rel","nofollow"),c(se,"href","https://jax.readthedocs.io/en/latest/jax-101/08-pjit.html?highlight=pjit"),c(se,"rel","nofollow")},m(e,a){l(document.head,G),p(e,$l,a),p(e,Z,a),l(Z,P),l(P,vt),u(de,vt,null),l(Z,is),l(Z,Jt),l(Jt,ns),p(e,_l,a),u(me,e,a),p(e,Ul,a),p(e,k,a),l(k,rs),l(k,ue),l(ue,ps),l(k,hs),l(k,Tt),l(Tt,fs),l(k,cs),p(e,kl,a),p(e,Y,a),l(Y,ds),l(Y,we),l(we,ms),l(Y,us),p(e,El,a),p(e,T,a),l(T,ws),l(T,jt),l(jt,ys),l(T,bs),l(T,gt),l(gt,Ms),l(T,vs),l(T,$t),l($t,Js),l(T,Ts),p(e,Il,a),p(e,Ke,a),l(Ke,js),p(e,Bl,a),p(e,X,a),l(X,H),l(H,_t),u(ye,_t,null),l(X,gs),l(X,Ut),l(Ut,$s),p(e,Wl,a),p(e,et,a),l(et,_s),p(e,Cl,a),u(be,e,a),p(e,Gl,a),u(Me,e,a),p(e,Zl,a),u(ve,e,a),p(e,Xl,a),u(Je,e,a),p(e,xl,a),p(e,tt,a),l(tt,Us),p(e,Al,a),u(Te,e,a),p(e,Fl,a),p(e,x,a),l(x,V),l(V,kt),u(je,kt,null),l(x,ks),l(x,Et),l(Et,Es),p(e,zl,a),p(e,E,a),l(E,Is),l(E,It),l(It,Bs),l(E,Ws),l(E,Bt),l(Bt,Cs),l(E,Gs),p(e,Sl,a),u(ge,e,a),p(e,Nl,a),p(e,Q,a),l(Q,Zs),l(Q,Wt),l(Wt,Xs),l(Q,xs),p(e,Pl,a),u($e,e,a),p(e,Yl,a),p(e,A,a),l(A,D),l(D,Ct),u(_e,Ct,null),l(A,As),l(A,Gt),l(Gt,Fs),p(e,Hl,a),p(e,lt,a),l(lt,zs),p(e,Vl,a),p(e,R,a),l(R,Ss),l(R,Zt),l(Zt,Ns),l(R,Ps),p(e,Ql,a),u(Ue,e,a),p(e,Dl,a),u(ke,e,a),p(e,Rl,a),p(e,F,a),l(F,q),l(q,Xt),u(Ee,Xt,null),l(F,Ys),l(F,xt),l(xt,Hs),p(e,ql,a),p(e,I,a),l(I,Vs),l(I,At),l(At,Qs),l(I,Ds),l(I,Ft),l(Ft,Rs),l(I,qs),p(e,Ll,a),u(Ie,e,a),p(e,Ol,a),u(Be,e,a),p(e,Kl,a),u(We,e,a),p(e,ea,a),p(e,v,a),l(v,Ls),l(v,zt),l(zt,Os),l(v,Ks),l(v,St),l(St,eo),l(v,to),l(v,Nt),l(Nt,lo),l(v,ao),l(v,Pt),l(Pt,so),l(v,oo),l(v,Yt),l(Yt,io),l(v,no),p(e,ta,a),p(e,at,a),l(at,ro),p(e,la,a),p(e,st,a),l(st,po),p(e,aa,a),u(Ce,e,a),p(e,sa,a),p(e,ot,a),l(ot,ho),p(e,oa,a),u(Ge,e,a),p(e,ia,a),p(e,it,a),l(it,fo),p(e,na,a),p(e,L,a),l(L,co),l(L,Ht),l(Ht,mo),l(L,uo),p(e,ra,a),p(e,O,a),l(O,wo),l(O,Vt),l(Vt,Qt),l(Qt,yo),l(O,bo),p(e,pa,a),u(Ze,e,a),p(e,ha,a),u(Xe,e,a),p(e,fa,a),p(e,B,a),l(B,Mo),l(B,Dt),l(Dt,vo),l(B,Jo),l(B,Rt),l(Rt,To),l(B,jo),p(e,ca,a),u(xe,e,a),p(e,da,a),p(e,z,a),l(z,K),l(K,qt),u(Ae,qt,null),l(z,go),l(z,Lt),l(Lt,$o),p(e,ma,a),p(e,nt,a),l(nt,_o),p(e,ua,a),u(Fe,e,a),p(e,wa,a),u(ze,e,a),p(e,ya,a),p(e,rt,a),l(rt,pt),p(e,ba,a),p(e,S,a),l(S,ee),l(ee,Ot),u(Se,Ot,null),l(S,Uo),l(S,Kt),l(Kt,ko),p(e,Ma,a),p(e,te,a),l(te,Eo),l(te,el),l(el,Io),l(te,Bo),p(e,va,a),p(e,ht,a),l(ht,Wo),p(e,Ja,a),u(Ne,e,a),p(e,Ta,a),u(Pe,e,a),p(e,ja,a),p(e,ft,a),l(ft,ct),p(e,ga,a),p(e,N,a),l(N,le),l(le,tl),u(Ye,tl,null),l(N,Co),l(N,ll),l(ll,Go),p(e,$a,a),p(e,ae,a),l(ae,Zo),l(ae,al),l(al,Xo),l(ae,xo),p(e,_a,a),p(e,j,a),l(j,Ao),l(j,sl),l(sl,Fo),l(j,zo),l(j,He),l(He,So),l(j,No),l(j,se),l(se,ol),l(ol,Po),l(se,Yo),l(j,Ho),p(e,Ua,a),p(e,Ve,a),l(Ve,il),l(il,Vo),l(Ve,Qo),p(e,ka,a),p(e,oe,a),l(oe,U),l(U,Do),l(U,nl),l(nl,Ro),l(U,qo),l(U,rl),l(rl,Lo),l(U,Oo),l(U,pl),l(pl,Ko),l(U,ei),l(oe,ti),l(oe,hl),l(hl,li),p(e,Ea,a),p(e,g,a),l(g,ai),l(g,fl),l(fl,si),l(g,oi),l(g,cl),l(cl,ii),l(g,ni),l(g,dl),l(dl,ri),l(g,pi),p(e,Ia,a),u(Qe,e,a),p(e,Ba,a),p(e,W,a),l(W,hi),l(W,ml),l(ml,fi),l(W,ci),l(W,ul),l(ul,di),l(W,mi),p(e,Wa,a),p(e,ie,a),l(ie,De),l(De,ui),l(De,wl),l(wl,wi),l(De,yi),l(ie,bi),l(ie,J),l(J,Mi),l(J,yl),l(yl,vi),l(J,Ji),l(J,bl),l(bl,Ti),l(J,ji),l(J,Ml),l(Ml,gi),l(J,$i),l(J,vl),l(vl,_i),l(J,Ui),l(J,Jl),l(Jl,ki),l(J,Ei),p(e,Ca,a),p(e,C,a),l(C,Ii),l(C,Tl),l(Tl,Bi),l(C,Wi),l(C,jl),l(jl,Ci),l(C,Gi),p(e,Ga,a),p(e,dt,a),l(dt,Zi),p(e,Za,a),u(Re,e,a),p(e,Xa,a),u(qe,e,a),p(e,xa,a),u(Le,e,a),p(e,Aa,a),u(Oe,e,a),p(e,Fa,a),p(e,ne,a),l(ne,Xi),l(ne,gl),l(gl,xi),l(ne,Ai),za=!0},p:$r,i(e){za||(w(de.$$.fragment,e),w(me.$$.fragment,e),w(ye.$$.fragment,e),w(be.$$.fragment,e),w(Me.$$.fragment,e),w(ve.$$.fragment,e),w(Je.$$.fragment,e),w(Te.$$.fragment,e),w(je.$$.fragment,e),w(ge.$$.fragment,e),w($e.$$.fragment,e),w(_e.$$.fragment,e),w(Ue.$$.fragment,e),w(ke.$$.fragment,e),w(Ee.$$.fragment,e),w(Ie.$$.fragment,e),w(Be.$$.fragment,e),w(We.$$.fragment,e),w(Ce.$$.fragment,e),w(Ge.$$.fragment,e),w(Ze.$$.fragment,e),w(Xe.$$.fragment,e),w(xe.$$.fragment,e),w(Ae.$$.fragment,e),w(Fe.$$.fragment,e),w(ze.$$.fragment,e),w(Se.$$.fragment,e),w(Ne.$$.fragment,e),w(Pe.$$.fragment,e),w(Ye.$$.fragment,e),w(Qe.$$.fragment,e),w(Re.$$.fragment,e),w(qe.$$.fragment,e),w(Le.$$.fragment,e),w(Oe.$$.fragment,e),za=!0)},o(e){y(de.$$.fragment,e),y(me.$$.fragment,e),y(ye.$$.fragment,e),y(be.$$.fragment,e),y(Me.$$.fragment,e),y(ve.$$.fragment,e),y(Je.$$.fragment,e),y(Te.$$.fragment,e),y(je.$$.fragment,e),y(ge.$$.fragment,e),y($e.$$.fragment,e),y(_e.$$.fragment,e),y(Ue.$$.fragment,e),y(ke.$$.fragment,e),y(Ee.$$.fragment,e),y(Ie.$$.fragment,e),y(Be.$$.fragment,e),y(We.$$.fragment,e),y(Ce.$$.fragment,e),y(Ge.$$.fragment,e),y(Ze.$$.fragment,e),y(Xe.$$.fragment,e),y(xe.$$.fragment,e),y(Ae.$$.fragment,e),y(Fe.$$.fragment,e),y(ze.$$.fragment,e),y(Se.$$.fragment,e),y(Ne.$$.fragment,e),y(Pe.$$.fragment,e),y(Ye.$$.fragment,e),y(Qe.$$.fragment,e),y(Re.$$.fragment,e),y(qe.$$.fragment,e),y(Le.$$.fragment,e),y(Oe.$$.fragment,e),za=!1},d(e){t(G),e&&t($l),e&&t(Z),b(de),e&&t(_l),b(me,e),e&&t(Ul),e&&t(k),e&&t(kl),e&&t(Y),e&&t(El),e&&t(T),e&&t(Il),e&&t(Ke),e&&t(Bl),e&&t(X),b(ye),e&&t(Wl),e&&t(et),e&&t(Cl),b(be,e),e&&t(Gl),b(Me,e),e&&t(Zl),b(ve,e),e&&t(Xl),b(Je,e),e&&t(xl),e&&t(tt),e&&t(Al),b(Te,e),e&&t(Fl),e&&t(x),b(je),e&&t(zl),e&&t(E),e&&t(Sl),b(ge,e),e&&t(Nl),e&&t(Q),e&&t(Pl),b($e,e),e&&t(Yl),e&&t(A),b(_e),e&&t(Hl),e&&t(lt),e&&t(Vl),e&&t(R),e&&t(Ql),b(Ue,e),e&&t(Dl),b(ke,e),e&&t(Rl),e&&t(F),b(Ee),e&&t(ql),e&&t(I),e&&t(Ll),b(Ie,e),e&&t(Ol),b(Be,e),e&&t(Kl),b(We,e),e&&t(ea),e&&t(v),e&&t(ta),e&&t(at),e&&t(la),e&&t(st),e&&t(aa),b(Ce,e),e&&t(sa),e&&t(ot),e&&t(oa),b(Ge,e),e&&t(ia),e&&t(it),e&&t(na),e&&t(L),e&&t(ra),e&&t(O),e&&t(pa),b(Ze,e),e&&t(ha),b(Xe,e),e&&t(fa),e&&t(B),e&&t(ca),b(xe,e),e&&t(da),e&&t(z),b(Ae),e&&t(ma),e&&t(nt),e&&t(ua),b(Fe,e),e&&t(wa),b(ze,e),e&&t(ya),e&&t(rt),e&&t(ba),e&&t(S),b(Se),e&&t(Ma),e&&t(te),e&&t(va),e&&t(ht),e&&t(Ja),b(Ne,e),e&&t(Ta),b(Pe,e),e&&t(ja),e&&t(ft),e&&t(ga),e&&t(N),b(Ye),e&&t($a),e&&t(ae),e&&t(_a),e&&t(j),e&&t(Ua),e&&t(Ve),e&&t(ka),e&&t(oe),e&&t(Ea),e&&t(g),e&&t(Ia),b(Qe,e),e&&t(Ba),e&&t(W),e&&t(Wa),e&&t(ie),e&&t(Ca),e&&t(C),e&&t(Ga),e&&t(dt),e&&t(Za),b(Re,e),e&&t(Xa),b(qe,e),e&&t(xa),b(Le,e),e&&t(Aa),b(Oe,e),e&&t(Fa),e&&t(ne)}}}const Er={local:"stable-diffusion-in-jax-flax",sections:[{local:"setup",title:"Setup"},{local:"model-loading",title:"Model Loading"},{local:"inference",sections:[{local:"replication-and-parallelization",title:"Replication and parallelization"},{local:"visualization",title:"Visualization"}],title:"Inference"},{local:"using-different-prompts",title:"Using different prompts"},{local:"how-does-parallelization-work",title:"How does parallelization work?"}],title:"\u{1F9E8} Stable Diffusion in JAX / Flax !"};function Ir(Si){return _r(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Zr extends Jr{constructor(G){super();Tr(this,G,Ir,kr,jr,{})}}export{Zr as default,Er as metadata};
