Buckets:

download
raw
12.7 kB
import{s as be,n as we,o as ye}from"../chunks/scheduler.56725da7.js";import{S as Te,i as ve,e as o,s as l,c as m,h as Ne,a,d as n,b as s,f as le,g as u,j as g,k as se,l as ae,m as i,n as c,t as d,o as f,p as h}from"../chunks/index.18a26576.js";import{C as xe}from"../chunks/CopyLLMTxtMenu.4513c8ed.js";import{D as _e}from"../chunks/Docstring.6448db33.js";import{C as Je}from"../chunks/CodeBlock.58e3e98b.js";import{H as E}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.049405bf.js";function $e(re){let r,H,W,L,M,z,_,G,b,B,w,pe='<a href="https://huggingface.co/papers/2211.09800" rel="nofollow">InstructPix2Pix: Learning to Follow Image Editing Instructions</a> is by Tim Brooks, Aleksander Holynski and Alexei A. Efros.',Q,y,me="🤗 <code>Optimum</code> extends <code>Diffusers</code> to support inference on the second generation of Neuron devices(powering Trainium and Inferentia 2). It aims at inheriting the ease of Diffusers on Neuron.",V,T,X,v,ue="To deploy models, you will need to compile them to TorchScript optimized for AWS Neuron. In the case of Stable Diffusion, there are four components which need to be exported to the <code>.neuron</code> format to boost the performance:",D,N,ce="<li>Text encoder</li> <li>U-Net</li> <li>VAE encoder</li> <li>VAE decoder</li>",F,x,de="You can either compile and export a Stable Diffusion Checkpoint via CLI or <code>NeuronStableDiffusionInstructPix2PixPipeline</code> class.",q,J,R,$,fe="With the <code>NeuronStableDiffusionInstructPix2PixPipeline</code> class, you can apply instruction-based image editing using both text guidance and image guidance.",Y,U,A,I,he='<thead><tr><th align="center"><code>image</code></th> <th align="center"><code>prompt</code></th> <th align="right">output</th></tr></thead> <tbody><tr><td align="center"><img src="https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png" alt="drawing" width="250"/></td> <td align="center"><strong><em>Add a beautiful sunset</em></strong></td> <td align="right"><img src="https://huggingface.co/datasets/optimum/documentation-images/resolve/main/neuron/models/11-sd-ip2p.png" alt="drawing" width="250"/></td></tr></tbody>',K,P,O,p,j,oe,Z,S,ee,k,ge='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 🤗 !',te,C,ne;return M=new xe({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),_=new E({props:{title:"InstructPix2Pix",local:"instructpix2pix",headingTag:"h1"}}),b=new E({props:{title:"Overview",local:"overview",headingTag:"h2"}}),T=new E({props:{title:"Export to Neuron",local:"export-to-neuron",headingTag:"h2"}}),J=new E({props:{title:"Usage Example",local:"usage-example",headingTag:"h2"}}),U=new Je({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjBQSUwlMEFmcm9tJTIwaW8lMjBpbXBvcnQlMjBCeXRlc0lPJTBBZnJvbSUyMG9wdGltdW0ubmV1cm9uJTIwaW1wb3J0JTIwTmV1cm9uU3RhYmxlRGlmZnVzaW9uSW5zdHJ1Y3RQaXgyUGl4UGlwZWxpbmUlMEElMEFkZWYlMjBkb3dubG9hZF9pbWFnZSh1cmwpJTNBJTBBJTIwJTIwJTIwJTIwcmVzcG9uc2UlMjAlM0QlMjByZXF1ZXN0cy5nZXQodXJsKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMFBJTC5JbWFnZS5vcGVuKEJ5dGVzSU8ocmVzcG9uc2UuY29udGVudCkpLmNvbnZlcnQoJTIyUkdCJTIyKSUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIydGltYnJvb2tzJTJGaW5zdHJ1Y3QtcGl4MnBpeCUyMiUwQWlucHV0X3NoYXBlcyUyMCUzRCUyMCU3QiUyMmJhdGNoX3NpemUlMjIlM0ElMjAxJTJDJTIwJTIyaGVpZ2h0JTIyJTNBJTIwNTEyJTJDJTIwJTIyd2lkdGglMjIlM0ElMjA1MTIlN0QlMEElMEFwaXBlJTIwJTNEJTIwTmV1cm9uU3RhYmxlRGlmZnVzaW9uSW5zdHJ1Y3RQaXgyUGl4UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMG1vZGVsX2lkJTJDJTIwZXhwb3J0JTNEVHJ1ZSUyQyUyMGR5bmFtaWNfYmF0Y2hfc2l6ZSUzRFRydWUlMkMlMjAqKmlucHV0X3NoYXBlcyUyQyUwQSklMEFwaXBlLnNhdmVfcHJldHJhaW5lZCglMjJzZF9pcDJwJTJGJTIyKSUwQSUwQWltZ191cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZkaWZmdXNlcnMlMkZkaWZmdXNlcnMtaW1hZ2VzLWRvY3MlMkZyZXNvbHZlJTJGbWFpbiUyRm1vdW50YWluLnBuZyUyMiUwQWluaXRfaW1hZ2UlMjAlM0QlMjBkb3dubG9hZF9pbWFnZShpbWdfdXJsKS5yZXNpemUoKDUxMiUyQyUyMDUxMikpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQWRkJTIwYSUyMGJlYXV0aWZ1bCUyMHN1bnNldCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjBpbWFnZSUzRGluaXRfaW1hZ2UpLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMnN1bnNldF9tb3VudGFpbi5wbmclMjIp",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> PIL
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<span class="hljs-keyword">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronStableDiffusionInstructPix2PixPipeline
<span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
response = requests.get(url)
<span class="hljs-keyword">return</span> PIL.Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
model_id = <span class="hljs-string">&quot;timbrooks/instruct-pix2pix&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>}
pipe = NeuronStableDiffusionInstructPix2PixPipeline.from_pretrained(
model_id, export=<span class="hljs-literal">True</span>, dynamic_batch_size=<span class="hljs-literal">True</span>, **input_shapes,
)
pipe.save_pretrained(<span class="hljs-string">&quot;sd_ip2p/&quot;</span>)
img_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png&quot;</span>
init_image = download_image(img_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
prompt = <span class="hljs-string">&quot;Add a beautiful sunset&quot;</span>
image = pipe(prompt=prompt, image=init_image).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;sunset_mountain.png&quot;</span>)`,wrap:!1}}),P=new E({props:{title:"NeuronStableDiffusionInstructPix2PixPipeline",local:"optimum.neuron.NeuronStableDiffusionInstructPix2PixPipeline",headingTag:"h4"}}),j=new _e({props:{name:"class optimum.neuron.NeuronStableDiffusionInstructPix2PixPipeline",anchor:"optimum.neuron.NeuronStableDiffusionInstructPix2PixPipeline",parameters:[{name:"config",val:": dict[str, typing.Any]"},{name:"configs",val:": dict[str, 'PretrainedConfig']"},{name:"neuron_configs",val:": dict[str, 'NeuronDefaultConfig']"},{name:"data_parallel_mode",val:": typing.Literal['none', 'unet', 'transformer', 'all']"},{name:"scheduler",val:": diffusers.schedulers.scheduling_utils.SchedulerMixin | None"},{name:"vae_decoder",val:": torch.jit._script.ScriptModule | NeuronModelVaeDecoder"},{name:"text_encoder",val:": torch.jit._script.ScriptModule | NeuronModelTextEncoder | None = None"},{name:"text_encoder_2",val:": torch.jit._script.ScriptModule | NeuronModelTextEncoder | None = None"},{name:"unet",val:": torch.jit._script.ScriptModule | NeuronModelUnet | None = None"},{name:"transformer",val:": torch.jit._script.ScriptModule | NeuronModelTransformer | None = None"},{name:"vae_encoder",val:": torch.jit._script.ScriptModule | NeuronModelVaeEncoder | None = None"},{name:"image_encoder",val:": torch.jit._script.ScriptModule | None = None"},{name:"safety_checker",val:": torch.jit._script.ScriptModule | None = None"},{name:"tokenizer",val:": transformers.models.clip.tokenization_clip.CLIPTokenizer | transformers.models.t5.tokenization_t5.T5Tokenizer | None = None"},{name:"tokenizer_2",val:": transformers.models.clip.tokenization_clip.CLIPTokenizer | transformers.models.t5.tokenization_t5.T5Tokenizer | None = None"},{name:"feature_extractor",val:": transformers.models.clip.feature_extraction_clip.CLIPFeatureExtractor | None = None"},{name:"controlnet",val:": torch.jit._script.ScriptModule | list[torch.jit._script.ScriptModule]| NeuronControlNetModel | NeuronMultiControlNetModel | None = None"},{name:"requires_aesthetics_score",val:": bool = False"},{name:"force_zeros_for_empty_prompt",val:": bool = True"},{name:"add_watermarker",val:": bool | None = None"},{name:"model_save_dir",val:": str | pathlib.Path | tempfile.TemporaryDirectory | None = None"},{name:"model_and_config_save_paths",val:": dict[str, tuple[str, pathlib.Path]] | None = None"}],source:"https://github.com/huggingface/optimum-neuron/blob/v0.4.4/optimum/neuron/modeling_diffusion.py#L1548"}}),S=new _e({props:{name:"__call__",anchor:"optimum.neuron.NeuronStableDiffusionInstructPix2PixPipeline.__call__",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}],source:"https://github.com/huggingface/optimum-neuron/blob/v0.4.4/optimum/neuron/modeling_diffusion.py#L1094"}}),{c(){r=o("meta"),H=l(),W=o("p"),L=l(),m(M.$$.fragment),z=l(),m(_.$$.fragment),G=l(),m(b.$$.fragment),B=l(),w=o("p"),w.innerHTML=pe,Q=l(),y=o("p"),y.innerHTML=me,V=l(),m(T.$$.fragment),X=l(),v=o("p"),v.innerHTML=ue,D=l(),N=o("ul"),N.innerHTML=ce,F=l(),x=o("p"),x.innerHTML=de,q=l(),m(J.$$.fragment),R=l(),$=o("p"),$.innerHTML=fe,Y=l(),m(U.$$.fragment),A=l(),I=o("table"),I.innerHTML=he,K=l(),m(P.$$.fragment),O=l(),p=o("div"),m(j.$$.fragment),oe=l(),Z=o("div"),m(S.$$.fragment),ee=l(),k=o("p"),k.innerHTML=ge,te=l(),C=o("p"),this.h()},l(e){const t=Ne("svelte-u9bgzb",document.head);r=a(t,"META",{name:!0,content:!0}),t.forEach(n),H=s(e),W=a(e,"P",{}),le(W).forEach(n),L=s(e),u(M.$$.fragment,e),z=s(e),u(_.$$.fragment,e),G=s(e),u(b.$$.fragment,e),B=s(e),w=a(e,"P",{"data-svelte-h":!0}),g(w)!=="svelte-1tl4gnd"&&(w.innerHTML=pe),Q=s(e),y=a(e,"P",{"data-svelte-h":!0}),g(y)!=="svelte-1g87d8z"&&(y.innerHTML=me),V=s(e),u(T.$$.fragment,e),X=s(e),v=a(e,"P",{"data-svelte-h":!0}),g(v)!=="svelte-3qllio"&&(v.innerHTML=ue),D=s(e),N=a(e,"UL",{"data-svelte-h":!0}),g(N)!=="svelte-1c1t3y0"&&(N.innerHTML=ce),F=s(e),x=a(e,"P",{"data-svelte-h":!0}),g(x)!=="svelte-xuclry"&&(x.innerHTML=de),q=s(e),u(J.$$.fragment,e),R=s(e),$=a(e,"P",{"data-svelte-h":!0}),g($)!=="svelte-1836mxv"&&($.innerHTML=fe),Y=s(e),u(U.$$.fragment,e),A=s(e),I=a(e,"TABLE",{"data-svelte-h":!0}),g(I)!=="svelte-w6yzym"&&(I.innerHTML=he),K=s(e),u(P.$$.fragment,e),O=s(e),p=a(e,"DIV",{class:!0});var ie=le(p);u(j.$$.fragment,ie),oe=s(ie),Z=a(ie,"DIV",{class:!0});var Me=le(Z);u(S.$$.fragment,Me),Me.forEach(n),ie.forEach(n),ee=s(e),k=a(e,"P",{"data-svelte-h":!0}),g(k)!=="svelte-1wos5lv"&&(k.innerHTML=ge),te=s(e),C=a(e,"P",{}),le(C).forEach(n),this.h()},h(){se(r,"name","hf:doc:metadata"),se(r,"content",Ue),se(Z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),se(p,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){ae(document.head,r),i(e,H,t),i(e,W,t),i(e,L,t),c(M,e,t),i(e,z,t),c(_,e,t),i(e,G,t),c(b,e,t),i(e,B,t),i(e,w,t),i(e,Q,t),i(e,y,t),i(e,V,t),c(T,e,t),i(e,X,t),i(e,v,t),i(e,D,t),i(e,N,t),i(e,F,t),i(e,x,t),i(e,q,t),c(J,e,t),i(e,R,t),i(e,$,t),i(e,Y,t),c(U,e,t),i(e,A,t),i(e,I,t),i(e,K,t),c(P,e,t),i(e,O,t),i(e,p,t),c(j,p,null),ae(p,oe),ae(p,Z),c(S,Z,null),i(e,ee,t),i(e,k,t),i(e,te,t),i(e,C,t),ne=!0},p:we,i(e){ne||(d(M.$$.fragment,e),d(_.$$.fragment,e),d(b.$$.fragment,e),d(T.$$.fragment,e),d(J.$$.fragment,e),d(U.$$.fragment,e),d(P.$$.fragment,e),d(j.$$.fragment,e),d(S.$$.fragment,e),ne=!0)},o(e){f(M.$$.fragment,e),f(_.$$.fragment,e),f(b.$$.fragment,e),f(T.$$.fragment,e),f(J.$$.fragment,e),f(U.$$.fragment,e),f(P.$$.fragment,e),f(j.$$.fragment,e),f(S.$$.fragment,e),ne=!1},d(e){e&&(n(H),n(W),n(L),n(z),n(G),n(B),n(w),n(Q),n(y),n(V),n(X),n(v),n(D),n(N),n(F),n(x),n(q),n(R),n($),n(Y),n(A),n(I),n(K),n(O),n(p),n(ee),n(k),n(te),n(C)),n(r),h(M,e),h(_,e),h(b,e),h(T,e),h(J,e),h(U,e),h(P,e),h(j),h(S)}}}const Ue='{"title":"InstructPix2Pix","local":"instructpix2pix","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Export to Neuron","local":"export-to-neuron","sections":[],"depth":2},{"title":"Usage Example","local":"usage-example","sections":[{"title":"NeuronStableDiffusionInstructPix2PixPipeline","local":"optimum.neuron.NeuronStableDiffusionInstructPix2PixPipeline","sections":[],"depth":4}],"depth":2}],"depth":1}';function Ie(re){return ye(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ce extends Te{constructor(r){super(),ve(this,r,Ie,$e,be,{})}}export{Ce as component};

Xet Storage Details

Size:
12.7 kB
·
Xet hash:
468786d5cdfad07637311e8fc28cc5916973c7d8cd8ad68cbc9c2483a8f0f4ae

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.