import{s as F,a as z,n as P,o as D}from"../chunks/scheduler.56725da7.js";import{S as O,i as K,e as p,s as a,c as E,h as ee,a as r,d as s,b as n,f as L,g as x,j as v,k as J,l as te,m as l,n as N,t as R,o as V,p as k}from"../chunks/index.18a26576.js";import{C as se}from"../chunks/CopyLLMTxtMenu.f644b58a.js";import{C as le}from"../chunks/CodeBlock.a5342303.js";import{H}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.401933eb.js";function ae($){let i,g,j,T,m,b,c,U,u,q="There are several training techniques for personalizing diffusion models to generate images of a specific subject or images in certain styles. Each of these training methods produces a different type of adapter. Some of the adapters generate an entirely new model, while other adapters only modify a smaller set of embeddings or weights. This means the loading process for each adapter is also different.",_,M,A="This guide will show you how to load LoRA weights.",Z,h,B,d,Q="Low-Rank Adaptation is the fastest way for Stable Diffusion to adapt the styles of the generated images. In Optimum Neuron, we support using one or multiple LoRA adapters by fusing their parameters into the original parameters of the text encoder(s) and the unet during the compilation. Here below is an example of compiling stable diffusion models with LoRA adapters of your choice and using the compiled artifacts to generate styled images:",I,f,W,o,S,X,y,Y='Are there any other diffusion features that you want us to support in 🤗<code>Optimum-neuron</code>? Please file an issue to <a href="https://github.com/huggingface/optimum-neuron" rel="nofollow"><code>Optimum-neuron</code> Github repo</a> or discuss with us on <a href="https://discuss.huggingface.co/c/optimum/" rel="nofollow">HuggingFace’s community forum</a>, cheers 🤗 !',C,w,G;return m=new se({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),c=new H({props:{title:"Load adapters",local:"load-adapters",headingTag:"h1"}}),h=new H({props:{title:"LoRA",local:"lora",headingTag:"h2"}}),f=new le({props:{code:"JTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMExDTVNjaGVkdWxlciUwQWZyb20lMjBvcHRpbXVtLm5ldXJvbiUyMGltcG9ydCUyME5ldXJvblN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBJTBBbW9kZWxfaWQlMj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FmZXRlbnNvcnMlMjIlMkMlMEElMjAlMjAlMjAlMjBsb3JhX2FkYXB0ZXJfbmFtZXMlM0QlMjJsY20lMjIlMkMlMEElMjAlMjAlMjAlMjAqKmlucHV0X3NoYXBlcyUyQyUwQSUyMCUyMCUyMCUyMCoqY29tcGlsZXJfYXJncyUyQyUwQSklMEFwaXBlLnNjaGVkdWxlciUyMCUzRCUyMExDTVNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWcpJTBBJTBBJTIzJTIwU2F2ZSUyMGxvY2FsbHklMjBvciUyMHVwbG9hZCUyMHRvJTIwdGhlJTIwSHVnZ2luZ0ZhY2UlMjBIdWIlMEFwaXBlLnNhdmVfcHJldHJhaW5lZCglMjJkcmVhbXNoYXBlcl83X2xjbV9sb3JhX25ldXJvbiUyRiUyMiklMEElMEElMEElMjMlMjBJbmZlcmVuY2UlMEFwcm9tcHQlMjAlM0QlMjAlMjJTZWxmLXBvcnRyYWl0JTIwb2lsJTIwcGFpbnRpbmclMkMlMjBhJTIwYmVhdXRpZnVsJTIwY3lib3JnJTIwd2l0aCUyMGdvbGRlbiUyMGhhaXIlMkMlMjA4ayUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNEMCkuaW1hZ2VzJTVCMCU1RA==",highlighted:`
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> LCMScheduler
<span class="hljs-keyword">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronStableDiffusionPipeline


model_id = <span class="hljs-string">&quot;Lykon/dreamshaper-7&quot;</span>
adapter_id = <span class="hljs-string">&quot;latent-consistency/lcm-lora-sdv1-5&quot;</span>
input_shapes = {<span class="hljs-string">&quot;batch_size&quot;</span>: <span class="hljs-number">1</span>, <span class="hljs-string">&quot;height&quot;</span>: <span class="hljs-number">512</span>, <span class="hljs-string">&quot;width&quot;</span>: <span class="hljs-number">512</span>, <span class="hljs-string">&quot;num_images_per_prompt&quot;</span>: <span class="hljs-number">1</span>}
compiler_args = {<span class="hljs-string">&quot;auto_cast&quot;</span>: <span class="hljs-string">&quot;matmul&quot;</span>, <span class="hljs-string">&quot;auto_cast_type&quot;</span>: <span class="hljs-string">&quot;bf16&quot;</span>}

<span class="hljs-comment"># Compile</span>
pipe = NeuronStableDiffusionPipeline.from_pretrained(
    model_id,
    export=<span class="hljs-literal">True</span>,
    inline_weights_to_neff=<span class="hljs-literal">True</span>,  <span class="hljs-comment"># caveat: performance drop if neff/weights separated, will be improved by a future Neuron sdk release.</span>
    lora_model_ids=adapter_id,
    lora_weight_names=<span class="hljs-string">&quot;pytorch_lora_weights.safetensors&quot;</span>,
    lora_adapter_names=<span class="hljs-string">&quot;lcm&quot;</span>,
    **input_shapes,
    **compiler_args,
)
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

<span class="hljs-comment"># Save locally or upload to the HuggingFace Hub</span>
pipe.save_pretrained(<span class="hljs-string">&quot;dreamshaper_7_lcm_lora_neuron/&quot;</span>)


<span class="hljs-comment"># Inference</span>
prompt = <span class="hljs-string">&quot;Self-portrait oil painting, a beautiful cyborg with golden hair, 8k&quot;</span>
image = pipe(prompt, num_inference_steps=<span class="hljs-number">4</span>, guidance_scale=<span class="hljs-number">0</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){i=p("meta"),g=a(),j=p("p"),T=a(),E(m.$$.fragment),b=a(),E(c.$$.fragment),U=a(),u=p("p"),u.textContent=q,_=a(),M=p("p"),M.textContent=A,Z=a(),E(h.$$.fragment),B=a(),d=p("p"),d.textContent=Q,I=a(),E(f.$$.fragment),W=a(),o=p("img"),X=a(),y=p("p"),y.innerHTML=Y,C=a(),w=p("p"),this.h()},l(e){const t=ee("svelte-u9bgzb",document.head);i=r(t,"META",{name:!0,content:!0}),t.forEach(s),g=n(e),j=r(e,"P",{}),L(j).forEach(s),T=n(e),x(m.$$.fragment,e),b=n(e),x(c.$$.fragment,e),U=n(e),u=r(e,"P",{"data-svelte-h":!0}),v(u)!=="svelte-1p7c5ip"&&(u.textContent=q),_=n(e),M=r(e,"P",{"data-svelte-h":!0}),v(M)!=="svelte-3y0v6y"&&(M.textContent=A),Z=n(e),x(h.$$.fragment,e),B=n(e),d=r(e,"P",{"data-svelte-h":!0}),v(d)!=="svelte-w90myx"&&(d.textContent=Q),I=n(e),x(f.$$.fragment,e),W=n(e),o=r(e,"IMG",{src:!0,width:!0,height:!0,alt:!0}),X=n(e),y=r(e,"P",{"data-svelte-h":!0}),v(y)!=="svelte-1wos5lv"&&(y.innerHTML=Y),C=n(e),w=r(e,"P",{}),L(w).forEach(s),this.h()},h(){J(i,"name","hf:doc:metadata"),J(i,"content",ne),z(o.src,S="https://raw.githubusercontent.com/huggingface/optimum-neuron/main/docs/assets/guides/models/03-sd-lora.png")||J(o,"src",S),J(o,"width","256"),J(o,"height","256"),J(o,"alt","stable diffusion generated image with LoRA adapter.")},m(e,t){te(document.head,i),l(e,g,t),l(e,j,t),l(e,T,t),N(m,e,t),l(e,b,t),N(c,e,t),l(e,U,t),l(e,u,t),l(e,_,t),l(e,M,t),l(e,Z,t),N(h,e,t),l(e,B,t),l(e,d,t),l(e,I,t),N(f,e,t),l(e,W,t),l(e,o,t),l(e,X,t),l(e,y,t),l(e,C,t),l(e,w,t),G=!0},p:P,i(e){G||(R(m.$$.fragment,e),R(c.$$.fragment,e),R(h.$$.fragment,e),R(f.$$.fragment,e),G=!0)},o(e){V(m.$$.fragment,e),V(c.$$.fragment,e),V(h.$$.fragment,e),V(f.$$.fragment,e),G=!1},d(e){e&&(s(g),s(j),s(T),s(b),s(U),s(u),s(_),s(M),s(Z),s(B),s(d),s(I),s(W),s(o),s(X),s(y),s(C),s(w)),s(i),k(m,e),k(c,e),k(h,e),k(f,e)}}}const ne='{"title":"Load adapters","local":"load-adapters","sections":[{"title":"LoRA","local":"lora","sections":[],"depth":2}],"depth":1}';function ie($){return D(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ue extends O{constructor(i){super(),K(this,i,ie,ae,F,{})}}export{ue as component};
