Buckets:
| import"../chunks/DsnmJJEf.js";import{i as B,h as V,C as X,H as Z,D as i,E as R,s as z,a as h}from"../chunks/BtE7mKSK.js";import{p as F,o as S,s as e,f as r,a,b as N,c as d,d as l,r as c,n as U}from"../chunks/jDjavuwI.js";import{E as f}from"../chunks/SrSJA0zO.js";const Q='{"title":"Textual Inversion","local":"textual-inversion","sections":[{"title":"TextualInversionLoaderMixin","local":"diffusers.loaders.TextualInversionLoaderMixin","sections":[],"depth":2}],"depth":1}';var E=l('<meta name="hf:doc:metadata"/>'),q=l("<p>To load a Textual Inversion embedding vector in 🤗 Diffusers format:</p> <!>",1),Y=l("<p>locally:</p> <!>",1),C=l("<p>Example:</p> <!>",1),L=l(`<p></p> <!> <!> <p>Textual Inversion is a training method for personalizing models by learning new text embeddings from a few example images. The file produced from training is extremely small (a few KBs) and the new embeddings can be loaded into the text encoder.</p> <p><code>TextualInversionLoaderMixin</code> provides a function for loading Textual Inversion embeddings from Diffusers and Automatic1111 into the text encoder and loading a special token to activate the embeddings.</p> <blockquote class="tip"><p>To learn more about how to load Textual Inversion embeddings, see the <a href="../../using-diffusers/textual_inversion_inference">Textual Inversion</a> loading guide.</p></blockquote> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load Textual Inversion tokens and embeddings to the tokenizer and text encoder.</p> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Load Textual Inversion embeddings into the text encoder of <a href="/docs/diffusers/pr_13881/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> (both 🤗 Diffusers and | |
| Automatic1111 formats are supported).</p> <p>Example:</p> <!> <p>To load a Textual Inversion embedding vector in Automatic1111 format, make sure to download the vector first | |
| (for example from <a href="https://civitai.com/models/3036?modelVersionId=9857" rel="nofollow">civitAI</a>) and then load the vector</p> <!></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Processes prompts that include a special token corresponding to a multi-vector textual inversion embedding to | |
| be replaced with multiple special tokens each corresponding to one of the vectors. If the prompt has no textual | |
| inversion token or if the textual inversion token is a single vector, the input prompt is returned.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Unload Textual Inversion embeddings from the text encoder of <a href="/docs/diffusers/pr_13881/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a></p> <!></div></div> <!> <p></p>`,1);function K(j,w){F(w,!1),S(()=>{new URLSearchParams(window.location.search).get("fw")}),B();var M=L();V("pgdv4a",o=>{var t=E();z(t,"content",Q),a(o,t)});var b=e(r(M),2);X(b,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var y=e(b,2);Z(y,{title:"Textual Inversion",local:"textual-inversion",headingTag:"h1"});var x=e(y,8);Z(x,{title:"TextualInversionLoaderMixin",local:"diffusers.loaders.TextualInversionLoaderMixin",headingTag:"h2"});var p=e(x,2),g=d(p);i(g,{name:"class diffusers.loaders.TextualInversionLoaderMixin",anchor:"diffusers.loaders.TextualInversionLoaderMixin",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/loaders/textual_inversion.py#L118",parameters:[]});var m=e(g,4),v=d(m);i(v,{name:"load_textual_inversion",anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/loaders/textual_inversion.py#L271",parameters:[{name:"pretrained_model_name_or_path",val:": str | list[str] | dict[str, torch.Tensor] | list[dict[str, torch.Tensor]]"},{name:"token",val:": str | list[str] | None = None"},{name:"tokenizer",val:": 'PreTrainedTokenizer' | None = None"},{name:"text_encoder",val:": 'PreTrainedModel' | None = None"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.pretrained_model_name_or_path",description:`<strong>pretrained_model_name_or_path</strong> (<code>str</code> or <code>os.PathLike</code> or <code>list[str or os.PathLike]</code> or <code>Dict</code> or <code>list[Dict]</code>) — | |
| Can be either one of the following or a list of them:</p> | |
| <ul> | |
| <li>A string, the <em>model id</em> (for example <code>sd-concepts-library/low-poly-hd-logos-icons</code>) of a | |
| pretrained model hosted on the Hub.</li> | |
| <li>A path to a <em>directory</em> (for example <code>./my_text_inversion_directory/</code>) containing the textual | |
| inversion weights.</li> | |
| <li>A path to a <em>file</em> (for example <code>./my_text_inversions.pt</code>) containing textual inversion weights.</li> | |
| <li>A <a href="https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict" rel="nofollow">torch state | |
| dict</a>.</li> | |
| </ul>`,name:"pretrained_model_name_or_path"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.token",description:`<strong>token</strong> (<code>str</code> or <code>list[str]</code>, <em>optional</em>) — | |
| Override the token to use for the textual inversion weights. If <code>pretrained_model_name_or_path</code> is a | |
| list, then <code>token</code> must also be a list of equal length.`,name:"token"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>, <em>optional</em>) — | |
| Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a>). | |
| If not specified, function will take self.tokenizer.`,name:"text_encoder"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>, <em>optional</em>) — | |
| A <code>CLIPTokenizer</code> to tokenize text. If not specified, function will take self.tokenizer.`,name:"tokenizer"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.weight_name",description:`<strong>weight_name</strong> (<code>str</code>, <em>optional</em>) — | |
| Name of a custom weight file. This should be used when:</p> | |
| <ul> | |
| <li>The saved textual inversion file is in 🤗 Diffusers format, but was saved under a specific weight | |
| name such as <code>text_inv.bin</code>.</li> | |
| <li>The saved textual inversion file is in the Automatic1111 format.</li> | |
| </ul>`,name:"weight_name"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.cache_dir",description:`<strong>cache_dir</strong> (<code>str | os.PathLike</code>, <em>optional</em>) — | |
| Path to a directory where a downloaded pretrained model configuration is cached if the standard cache | |
| is not used.`,name:"cache_dir"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.force_download",description:`<strong>force_download</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether or not to force the (re-)download of the model weights and configuration files, overriding the | |
| cached versions if they exist.`,name:"force_download"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.proxies",description:`<strong>proxies</strong> (<code>dict[str, str]</code>, <em>optional</em>) — | |
| A dictionary of proxy servers to use by protocol or endpoint, for example, <code>{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}</code>. The proxies are used on each request.`,name:"proxies"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.local_files_only",description:`<strong>local_files_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Whether to only load local model weights and configuration files or not. If set to <code>True</code>, the model | |
| won’t be downloaded from the Hub.`,name:"local_files_only"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.hf_token",description:`<strong>hf_token</strong> (<code>str</code> or <em>bool</em>, <em>optional</em>) — | |
| The token to use as HTTP bearer authorization for remote files. If <code>True</code>, the token generated from | |
| <code>diffusers-cli login</code> (stored in <code>~/.huggingface</code>) is used.`,name:"hf_token"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.revision",description:`<strong>revision</strong> (<code>str</code>, <em>optional</em>, defaults to <code>"main"</code>) — | |
| The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier | |
| allowed by Git.`,name:"revision"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.subfolder",description:`<strong>subfolder</strong> (<code>str</code>, <em>optional</em>, defaults to <code>""</code>) — | |
| The subfolder location of a model file within a larger model repository on the Hub or locally.`,name:"subfolder"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.mirror",description:`<strong>mirror</strong> (<code>str</code>, <em>optional</em>) — | |
| Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not | |
| guarantee the timeliness or safety of the source, and you should refer to the mirror site for more | |
| information.`,name:"mirror"}]});var T=e(v,6);f(T,{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example",children:(o,t)=>{var n=q(),s=e(r(n),2);h(s,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBJTBBcGlwZS5sb2FkX3RleHR1YWxfaW52ZXJzaW9uKCUyMnNkLWNvbmNlcHRzLWxpYnJhcnklMkZjYXQtdG95JTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjAlM0NjYXQtdG95JTNFJTIwYmFja3BhY2slMjIlMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJjYXQtYmFja3BhY2sucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline | |
| <span class="hljs-keyword">import</span> torch | |
| model_id = <span class="hljs-string">"stable-diffusion-v1-5/stable-diffusion-v1-5"</span> | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">"cuda"</span>) | |
| pipe.load_textual_inversion(<span class="hljs-string">"sd-concepts-library/cat-toy"</span>) | |
| prompt = <span class="hljs-string">"A <cat-toy> backpack"</span> | |
| image = pipe(prompt, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"cat-backpack.png"</span>)`,lang:"py",wrap:!1}),a(o,n)},$$slots:{default:!0}});var I=e(T,4);f(I,{anchor:"diffusers.loaders.TextualInversionLoaderMixin.load_textual_inversion.example-2",children:(o,t)=>{var n=Y(),s=e(r(n),2);h(s,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBJTBBcGlwZS5sb2FkX3RleHR1YWxfaW52ZXJzaW9uKCUyMi4lMkZjaGFydHVybmVydjIucHQlMjIlMkMlMjB0b2tlbiUzRCUyMmNoYXJ0dXJuZXJ2MiUyMiklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJjaGFydHVybmVydjIlMkMlMjBtdWx0aXBsZSUyMHZpZXdzJTIwb2YlMjB0aGUlMjBzYW1lJTIwY2hhcmFjdGVyJTIwaW4lMjB0aGUlMjBzYW1lJTIwb3V0Zml0JTJDJTIwYSUyMGNoYXJhY3RlciUyMHR1cm5hcm91bmQlMjBvZiUyMGElMjB3b21hbiUyMHdlYXJpbmclMjBhJTIwYmxhY2slMjBqYWNrZXQlMjBhbmQlMjByZWQlMjBzaGlydCUyQyUyMGJlc3QlMjBxdWFsaXR5JTJDJTIwaW50cmljYXRlJTIwZGV0YWlscy4lMjIlMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJjaGFyYWN0ZXIucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline | |
| <span class="hljs-keyword">import</span> torch | |
| model_id = <span class="hljs-string">"stable-diffusion-v1-5/stable-diffusion-v1-5"</span> | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">"cuda"</span>) | |
| pipe.load_textual_inversion(<span class="hljs-string">"./charturnerv2.pt"</span>, token=<span class="hljs-string">"charturnerv2"</span>) | |
| prompt = <span class="hljs-string">"charturnerv2, multiple views of the same character in the same outfit, a character turnaround of a woman wearing a black jacket and red shirt, best quality, intricate details."</span> | |
| image = pipe(prompt, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"character.png"</span>)`,lang:"py",wrap:!1}),a(o,n)},$$slots:{default:!0}}),c(m);var u=e(m,2),G=d(u);i(G,{name:"maybe_convert_prompt",anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/loaders/textual_inversion.py#L123",parameters:[{name:"prompt",val:": str | list[str]"},{name:"tokenizer",val:": 'PreTrainedTokenizer'"}],parametersDescription:[{anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or list of <code>str</code>) — | |
| The prompt or prompts to guide the image generation.`,name:"prompt"},{anchor:"diffusers.loaders.TextualInversionLoaderMixin.maybe_convert_prompt.tokenizer",description:`<strong>tokenizer</strong> (<code>PreTrainedTokenizer</code>) — | |
| The tokenizer responsible for encoding the prompt into input tokens.`,name:"tokenizer"}],returnDescription:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p>The converted prompt</p> | |
| `,returnType:`<script context="module">export const metadata = 'undefined';<\/script> | |
| <p><code>str</code> or list of <code>str</code></p> | |
| `}),U(2),c(u);var _=e(u,2),J=d(_);i(J,{name:"unload_textual_inversion",anchor:"diffusers.loaders.TextualInversionLoaderMixin.unload_textual_inversion",source:"https://github.com/huggingface/diffusers/blob/vr_13881/src/diffusers/loaders/textual_inversion.py#L467",parameters:[{name:"tokens",val:": str | list[str] | None = None"},{name:"tokenizer",val:": 'PreTrainedTokenizer' | None = None"},{name:"text_encoder",val:": 'PreTrainedModel' | None = None"}]});var W=e(J,4);f(W,{anchor:"diffusers.loaders.TextualInversionLoaderMixin.unload_textual_inversion.example",children:(o,t)=>{var n=C(),s=e(r(n),2);h(s,{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9QaXBlbGluZUZvclRleHQySW1hZ2UlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwQXV0b1BpcGVsaW5lRm9yVGV4dDJJbWFnZS5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS01JTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyKSUwQSU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G9rZW5pemVyJTNEcGlwZWxpbmUudG9rZW5pemVyXzIlMkMlMEEpJTBBJTBBJTIzJTIwVW5sb2FkJTIwZXhwbGljaXRseSUyMGZyb20lMjBib3RoJTIwdGV4dCUyMGVuY29kZXJzJTIwYW5kJTIwdG9rZW5pemVycyUwQXBpcGVsaW5lLnVubG9hZF90ZXh0dWFsX2ludmVyc2lvbiglMEElMjAlMjAlMjAlMjB0b2tlbnMlM0QlNUIlMjIlM0NzMCUzRSUyMiUyQyUyMCUyMiUzQ3MxJTNFJTIyJTVEJTJDJTIwdGV4dF9lbmNvZGVyJTNEcGlwZWxpbmUudGV4dF9lbmNvZGVyJTJDJTIwdG9rZW5pemVyJTNEcGlwZWxpbmUudG9rZW5pemVyJTBBKSUwQXBpcGVsaW5lLnVubG9hZF90ZXh0dWFsX2ludmVyc2lvbiglMEElMjAlMjAlMjAlMjB0b2tlbnMlM0QlNUIlMjIlM0NzMCUzRSUyMiUyQyUyMCUyMiUzQ3MxJTNFJTIyJTVEJTJDJTIwdGV4dF9lbmNvZGVyJTNEcGlwZWxpbmUudGV4dF9lbmNvZGVyXzIlMkMlMjB0b2tlbml6ZXIlM0RwaXBlbGluZS50b2tlbml6ZXJfMiUwQSk=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoPipelineForText2Image | |
| <span class="hljs-keyword">import</span> torch | |
| pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">"stable-diffusion-v1-5/stable-diffusion-v1-5"</span>) | |
| <span class="hljs-comment"># Example 1</span> | |
| pipeline.load_textual_inversion(<span class="hljs-string">"sd-concepts-library/gta5-artwork"</span>) | |
| pipeline.load_textual_inversion(<span class="hljs-string">"sd-concepts-library/moeb-style"</span>) | |
| <span class="hljs-comment"># Remove all token embeddings</span> | |
| pipeline.unload_textual_inversion() | |
| <span class="hljs-comment"># Example 2</span> | |
| pipeline.load_textual_inversion(<span class="hljs-string">"sd-concepts-library/moeb-style"</span>) | |
| pipeline.load_textual_inversion(<span class="hljs-string">"sd-concepts-library/gta5-artwork"</span>) | |
| <span class="hljs-comment"># Remove just one token</span> | |
| pipeline.unload_textual_inversion(<span class="hljs-string">"<moe-bius>"</span>) | |
| <span class="hljs-comment"># Example 3: unload from SDXL</span> | |
| pipeline = AutoPipelineForText2Image.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>) | |
| embedding_path = hf_hub_download( | |
| repo_id=<span class="hljs-string">"linoyts/web_y2k"</span>, filename=<span class="hljs-string">"web_y2k_emb.safetensors"</span>, repo_type=<span class="hljs-string">"model"</span> | |
| ) | |
| <span class="hljs-comment"># load embeddings to the text encoders</span> | |
| state_dict = load_file(embedding_path) | |
| <span class="hljs-comment"># load embeddings of text_encoder 1 (CLIP ViT-L/14)</span> | |
| pipeline.load_textual_inversion( | |
| state_dict[<span class="hljs-string">"clip_l"</span>], | |
| tokens=[<span class="hljs-string">"<s0>"</span>, <span class="hljs-string">"<s1>"</span>], | |
| text_encoder=pipeline.text_encoder, | |
| tokenizer=pipeline.tokenizer, | |
| ) | |
| <span class="hljs-comment"># load embeddings of text_encoder 2 (CLIP ViT-G/14)</span> | |
| pipeline.load_textual_inversion( | |
| state_dict[<span class="hljs-string">"clip_g"</span>], | |
| tokens=[<span class="hljs-string">"<s0>"</span>, <span class="hljs-string">"<s1>"</span>], | |
| text_encoder=pipeline.text_encoder_2, | |
| tokenizer=pipeline.tokenizer_2, | |
| ) | |
| <span class="hljs-comment"># Unload explicitly from both text encoders and tokenizers</span> | |
| pipeline.unload_textual_inversion( | |
| tokens=[<span class="hljs-string">"<s0>"</span>, <span class="hljs-string">"<s1>"</span>], text_encoder=pipeline.text_encoder, tokenizer=pipeline.tokenizer | |
| ) | |
| pipeline.unload_textual_inversion( | |
| tokens=[<span class="hljs-string">"<s0>"</span>, <span class="hljs-string">"<s1>"</span>], text_encoder=pipeline.text_encoder_2, tokenizer=pipeline.tokenizer_2 | |
| )`,lang:"py",wrap:!1}),a(o,n)},$$slots:{default:!0}}),c(_),c(p);var k=e(p,2);R(k,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/loaders/textual_inversion.md"}),U(2),a(j,M),N()}export{K as component}; | |
Xet Storage Details
- Size:
- 22 kB
- Xet hash:
- 98179e20854251e78e01e057aa88f232e6ba5f092fd041b13aed181517db8279
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.