import{s as bo,o as Mo,n as k}from"../chunks/scheduler.6062bdaf.js";import{S as jo,i as wo,g as p,s as o,r as m,A as $o,h,f as n,c as l,j as J,u as f,x as b,k as Z,y as d,a as i,v as g,d as u,t as _,w as y}from"../chunks/index.4bca734e.js";import{T as de}from"../chunks/Tip.b9ac1f03.js";import{D as G}from"../chunks/Docstring.ff53aa02.js";import{C as z}from"../chunks/CodeBlock.cbbddafc.js";import{E as se}from"../chunks/ExampleCodeBlock.d2834193.js";import{H as I,E as vo}from"../chunks/index.60dd99e8.js";function To($){let t,M="This is a very early version of the parser. The API and implementation can evolve in the near future.",r,c,j='The parser currently does very little validation. For more details about the file format, check out <a href="https://github.com/huggingface/huggingface.js/tree/main/packages/dduf" rel="nofollow">https://github.com/huggingface/huggingface.js/tree/main/packages/dduf</a>.';return{c(){t=p("p"),t.textContent=M,r=o(),c=p("p"),c.innerHTML=j},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-f3wy5h"&&(t.textContent=M),r=l(s),c=h(s,"P",{"data-svelte-h":!0}),b(c)!=="svelte-23b1pm"&&(c.innerHTML=j)},m(s,w){i(s,t,w),i(s,r,w),i(s,c,w)},p:k,d(s){s&&(n(t),n(r),n(c))}}}function xo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGV4cG9ydF9lbnRyaWVzX2FzX2RkdWYlMEFleHBvcnRfZW50cmllc19hc19kZHVmKCUwQSUyMCUyMCUyMCUyMGRkdWZfcGF0aCUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNC1GUDE2LmRkdWYlMjIlMkMlMEElMjAlMjAlMjAlMjBlbnRyaWVzJTNEJTVCJTIwJTIzJTIwTGlzdCUyMGVudHJpZXMlMjB0byUyMGFkZCUyMHRvJTIwdGhlJTIwRERVRiUyMGZpbGUlMjAoaGVyZSUyQyUyMG9ubHklMjBGUDE2JTIwd2VpZ2h0cyklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAoJTIybW9kZWxfaW5kZXguanNvbiUyMiUyQyUyMCUyMnBhdGglMkZ0byUyRm1vZGVsX2luZGV4Lmpzb24lMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKCUyMnZhZSUyRmNvbmZpZy5qc29uJTIyJTJDJTIwJTIycGF0aCUyRnRvJTJGdmFlJTJGY29uZmlnLmpzb24lMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKCUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLmZwMTYuc2FmZXRlbnNvcnMlMjIlMkMlMjAlMjJwYXRoJTJGdG8lMkZ2YWUlMkZkaWZmdXNpb25fcHl0b3JjaF9tb2RlbC5mcDE2LnNhZmV0ZW5zb3JzJTIyKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCglMjJ0ZXh0X2VuY29kZXIlMkZjb25maWcuanNvbiUyMiUyQyUyMCUyMnBhdGglMkZ0byUyRnRleHRfZW5jb2RlciUyRmNvbmZpZy5qc29uJTIyKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCglMjJ0ZXh0X2VuY29kZXIlMkZtb2RlbC5mcDE2LnNhZmV0ZW5zb3JzJTIyJTJDJTIwJTIycGF0aCUyRnRvJTJGdGV4dF9lbmNvZGVyJTJGbW9kZWwuZnAxNi5zYWZldGVuc29ycyUyMiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjAuLi4lMjBhZGQlMjBtb3JlJTIwZW50cmllcyUyMGhlcmUlMEElMjAlMjAlMjAlMjAlNUQlMEEp",highlighted:`<span class="hljs-comment"># Export specific files from the local disk.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_entries_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>export_entries_as_dduf(
<span class="hljs-meta">... </span>    dduf_path=<span class="hljs-string">&quot;stable-diffusion-v1-4-FP16.dduf&quot;</span>,
<span class="hljs-meta">... </span>    entries=[ <span class="hljs-comment"># List entries to add to the DDUF file (here, only FP16 weights)</span>
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;model_index.json&quot;</span>, <span class="hljs-string">&quot;path/to/model_index.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;vae/config.json&quot;</span>, <span class="hljs-string">&quot;path/to/vae/config.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;vae/diffusion_pytorch_model.fp16.safetensors&quot;</span>, <span class="hljs-string">&quot;path/to/vae/diffusion_pytorch_model.fp16.safetensors&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;text_encoder/config.json&quot;</span>, <span class="hljs-string">&quot;path/to/text_encoder/config.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;text_encoder/model.fp16.safetensors&quot;</span>, <span class="hljs-string">&quot;path/to/text_encoder/model.fp16.safetensors&quot;</span>),
<span class="hljs-meta">... </span>        <span class="hljs-comment"># ... add more entries here</span>
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Uo($){let t,M;return t=new z({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMEdlbmVyYXRvciUyQyUyMFR1cGxlJTBBaW1wb3J0JTIwc2FmZXRlbnNvcnMudG9yY2glMEFmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwZXhwb3J0X2VudHJpZXNfYXNfZGR1ZiUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiklMEElMjMlMjAuLi4lMjBkbyUyMHNvbWUlMjB3b3JrJTIwd2l0aCUyMHRoZSUyMHBpcGVsaW5lJTBBJTBBZGVmJTIwYXNfZW50cmllcyhwaXBlJTNBJTIwRGlmZnVzaW9uUGlwZWxpbmUpJTIwLSUzRSUyMEdlbmVyYXRvciU1QlR1cGxlJTVCc3RyJTJDJTIwYnl0ZXMlNUQlMkMlMjBOb25lJTJDJTIwTm9uZSU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEJ1aWxkJTIwYW4lMjBnZW5lcmF0b3IlMjB0aGF0JTIweWllbGRzJTIwdGhlJTIwZW50cmllcyUyMHRvJTIwYWRkJTIwdG8lMjB0aGUlMjBERFVGJTIwZmlsZS4lMEElMjAlMjAlMjAlMjAlMjMlMjBUaGUlMjBmaXJzdCUyMGVsZW1lbnQlMjBvZiUyMHRoZSUyMHR1cGxlJTIwaXMlMjB0aGUlMjBmaWxlbmFtZSUyMGluJTIwdGhlJTIwRERVRiUyMGFyY2hpdmUlMjAobXVzdCUyMHVzZSUyMFVOSVglMjBzZXBhcmF0b3IhKS4lMjBUaGUlMjBzZWNvbmQlMjBlbGVtZW50JTIwaXMlMjB0aGUlMjBjb250ZW50JTIwb2YlMjB0aGUlMjBmaWxlLiUwQSUyMCUyMCUyMCUyMCUyMyUyMEVudHJpZXMlMjB3aWxsJTIwYmUlMjBldmFsdWF0ZWQlMjBsYXppbHklMjB3aGVuJTIwdGhlJTIwRERVRiUyMGZpbGUlMjBpcyUyMGNyZWF0ZWQlMjAob25seSUyMDElMjBlbnRyeSUyMGlzJTIwbG9hZGVkJTIwaW4lMjBtZW1vcnklMjBhdCUyMGElMjB0aW1lKSUwQSUyMCUyMCUyMCUyMHlpZWxkJTIwJTIydmFlJTJGY29uZmlnLmpzb24lMjIlMkMlMjBwaXBlLnZhZS50b19qc29uX3N0cmluZygpLmVuY29kZSgpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ2YWUlMkZkaWZmdXNpb25fcHl0b3JjaF9tb2RlbC5zYWZldGVuc29ycyUyMiUyQyUyMHNhZmV0ZW5zb3JzLnRvcmNoLnNhdmUocGlwZS52YWUuc3RhdGVfZGljdCgpKSUwQSUyMCUyMCUyMCUyMHlpZWxkJTIwJTIydGV4dF9lbmNvZGVyJTJGY29uZmlnLmpzb24lMjIlMkMlMjBwaXBlLnRleHRfZW5jb2Rlci5jb25maWcudG9fanNvbl9zdHJpbmcoKS5lbmNvZGUoKSUwQSUyMCUyMCUyMCUyMHlpZWxkJTIwJTIydGV4dF9lbmNvZGVyJTJGbW9kZWwuc2FmZXRlbnNvcnMlMjIlMkMlMjBzYWZldGVuc29ycy50b3JjaC5zYXZlKHBpcGUudGV4dF9lbmNvZGVyLnN0YXRlX2RpY3QoKSklMEElMjAlMjAlMjAlMjAlMjMlMjAuLi4lMjBhZGQlMjBtb3JlJTIwZW50cmllcyUyMGhlcmUlMEElMEFleHBvcnRfZW50cmllc19hc19kZHVmKGRkdWZfcGF0aCUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNC5kZHVmJTIyJTJDJTIwZW50cmllcyUzRGFzX2VudHJpZXMocGlwZSkp",highlighted:`<span class="hljs-comment"># Export state_dicts one by one from a loaded pipeline</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> Generator, <span class="hljs-type">Tuple</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> safetensors.torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_entries_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
<span class="hljs-meta">... </span><span class="hljs-comment"># ... do some work with the pipeline</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">as_entries</span>(<span class="hljs-params">pipe: DiffusionPipeline</span>) -&gt; Generator[<span class="hljs-type">Tuple</span>[<span class="hljs-built_in">str</span>, <span class="hljs-built_in">bytes</span>], <span class="hljs-literal">None</span>, <span class="hljs-literal">None</span>]:
<span class="hljs-meta">... </span>    <span class="hljs-comment"># Build an generator that yields the entries to add to the DDUF file.</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># The first element of the tuple is the filename in the DDUF archive (must use UNIX separator!). The second element is the content of the file.</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># Entries will be evaluated lazily when the DDUF file is created (only 1 entry is loaded in memory at a time)</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;vae/config.json&quot;</span>, pipe.vae.to_json_string().encode()
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;vae/diffusion_pytorch_model.safetensors&quot;</span>, safetensors.torch.save(pipe.vae.state_dict())
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;text_encoder/config.json&quot;</span>, pipe.text_encoder.config.to_json_string().encode()
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;text_encoder/model.safetensors&quot;</span>, safetensors.torch.save(pipe.text_encoder.state_dict())
<span class="hljs-meta">... </span>    <span class="hljs-comment"># ... add more entries here</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>export_entries_as_dduf(dduf_path=<span class="hljs-string">&quot;stable-diffusion-v1-4.dduf&quot;</span>, entries=as_entries(pipe))`,wrap:!1}}),{c(){m(t.$$.fragment)},l(r){f(t.$$.fragment,r)},m(r,c){g(t,r,c),M=!0},p:k,i(r){M||(u(t.$$.fragment,r),M=!0)},o(r){_(t.$$.fragment,r),M=!1},d(r){y(t,r)}}}function Jo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGV4cG9ydF9mb2xkZXJfYXNfZGR1ZiUwQWV4cG9ydF9mb2xkZXJfYXNfZGR1ZihkZHVmX3BhdGglM0QlMjJGTFVYLjEtZGV2LmRkdWYlMjIlMkMlMjBmb2xkZXJfcGF0aCUzRCUyMnBhdGglMkZ0byUyRkZMVVguMS1kZXYlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_folder_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>export_folder_as_dduf(dduf_path=<span class="hljs-string">&quot;FLUX.1-dev.dduf&quot;</span>, folder_path=<span class="hljs-string">&quot;path/to/FLUX.1-dev&quot;</span>)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Zo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"aW1wb3J0JTIwanNvbiUwQWltcG9ydCUyMHNhZmV0ZW5zb3JzLnRvcmNoJTBBZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHJlYWRfZGR1Zl9maWxlJTBBJTBBZGR1Zl9lbnRyaWVzJTIwJTNEJTIwcmVhZF9kZHVmX2ZpbGUoJTIyRkxVWC4xLWRldi5kZHVmJTIyKSUwQSUwQWRkdWZfZW50cmllcyU1QiUyMm1vZGVsX2luZGV4Lmpzb24lMjIlNUQlMEElMEFqc29uLmxvYWRzKGRkdWZfZW50cmllcyU1QiUyMm1vZGVsX2luZGV4Lmpzb24lMjIlNUQucmVhZF90ZXh0KCkpJTBBJTBBd2l0aCUyMGRkdWZfZW50cmllcyU1QiUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLnNhZmV0ZW5zb3JzJTIyJTVELmFzX21tYXAoKSUyMGFzJTIwbW0lM0ElMEElMjAlMjAlMjAlMjBzdGF0ZV9kaWN0JTIwJTNEJTIwc2FmZXRlbnNvcnMudG9yY2gubG9hZChtbSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> safetensors.torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> read_dduf_file

<span class="hljs-comment"># Read DDUF metadata</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dduf_entries = read_dduf_file(<span class="hljs-string">&quot;FLUX.1-dev.dduf&quot;</span>)

<span class="hljs-comment"># Returns a mapping filename &lt;&gt; DDUFEntry</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dduf_entries[<span class="hljs-string">&quot;model_index.json&quot;</span>]
DDUFEntry(filename=<span class="hljs-string">&#x27;model_index.json&#x27;</span>, offset=<span class="hljs-number">66</span>, length=<span class="hljs-number">587</span>)

<span class="hljs-comment"># Load model index as JSON</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>json.loads(dduf_entries[<span class="hljs-string">&quot;model_index.json&quot;</span>].read_text())
{<span class="hljs-string">&#x27;_class_name&#x27;</span>: <span class="hljs-string">&#x27;FluxPipeline&#x27;</span>, <span class="hljs-string">&#x27;_diffusers_version&#x27;</span>: <span class="hljs-string">&#x27;0.32.0.dev0&#x27;</span>, <span class="hljs-string">&#x27;_name_or_path&#x27;</span>: <span class="hljs-string">&#x27;black-forest-labs/FLUX.1-dev&#x27;</span>, ...

<span class="hljs-comment"># Load VAE weights using safetensors</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> dduf_entries[<span class="hljs-string">&quot;vae/diffusion_pytorch_model.safetensors&quot;</span>].as_mmap() <span class="hljs-keyword">as</span> mm:
<span class="hljs-meta">... </span>    state_dict = safetensors.torch.load(mm)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function ko($){let t,M="Example:",r,c,j;return c=new z({props:{code:"aW1wb3J0JTIwc2FmZXRlbnNvcnMudG9yY2glMEF3aXRoJTIwZW50cnkuYXNfbW1hcCgpJTIwYXMlMjBtbSUzQSUwQSUyMCUyMCUyMCUyMHRlbnNvcnMlMjAlM0QlMjBzYWZldGVuc29ycy50b3JjaC5sb2FkKG1tKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> safetensors.torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> entry.as_mmap() <span class="hljs-keyword">as</span> mm:
<span class="hljs-meta">... </span>    tensors = safetensors.torch.load(mm)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Go($){let t,M="Example:",r,c,j;return c=new z({props:{code:"aW1wb3J0JTIwanNvbiUwQWluZGV4JTIwJTNEJTIwanNvbi5sb2FkcyhlbnRyeS5yZWFkX3RleHQoKSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json
<span class="hljs-meta">&gt;&gt;&gt; </span>index = json.loads(entry.read_text())`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Io($){let t,M=`If one of the model’s tensor is bigger than <code>max_shard_size</code>, it will end up in its own shard which will have a
size greater than <code>max_shard_size</code>.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-16sq104"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Co($){let t,M="If your model is a <code>transformers.PreTrainedModel</code>, you should pass <code>model._tied_weights_keys</code> as <code>shared_tensors_to_discard</code> to properly handle shared tensors saving. This ensures the correct duplicate tensors are discarded during saving.";return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-zilo2z"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Ro($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHNhdmVfdG9yY2hfbW9kZWwlMEFtb2RlbCUyMCUzRCUyMC4uLiUyMCUyMyUyMEElMjBQeVRvcmNoJTIwbW9kZWwlMEElMEFzYXZlX3RvcmNoX21vZGVsKG1vZGVsJTJDJTIwJTIycGF0aCUyRnRvJTJGZm9sZGVyJTIyKSUwQSUwQWZyb20lMjBodWdnaW5nZmFjZV9odWIlMjBpbXBvcnQlMjBsb2FkX3RvcmNoX21vZGVsJTIwJTIwJTIzJTIwVE9ETyUwQWxvYWRfdG9yY2hfbW9kZWwobW9kZWwlMkMlMjAlMjJwYXRoJTJGdG8lMkZmb2xkZXIlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> save_torch_model
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ... <span class="hljs-comment"># A PyTorch model</span>

<span class="hljs-comment"># Save state dict to &quot;path/to/folder&quot;. The model will be split into shards of 5GB each and saved as safetensors.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>save_torch_model(model, <span class="hljs-string">&quot;path/to/folder&quot;</span>)

<span class="hljs-comment"># Load model back</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> load_torch_model  <span class="hljs-comment"># TODO</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>load_torch_model(model, <span class="hljs-string">&quot;path/to/folder&quot;</span>)
&gt;&gt;&gt;`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Bo($){let t,M=`If one of the model’s tensor is bigger than <code>max_shard_size</code>, it will end up in its own shard which will have a
size greater than <code>max_shard_size</code>.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-16sq104"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Wo($){let t,M="If your model is a <code>transformers.PreTrainedModel</code>, you should pass <code>model._tied_weights_keys</code> as <code>shared_tensors_to_discard</code> to properly handle shared tensors saving. This ensures the correct duplicate tensors are discarded during saving.";return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-zilo2z"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function zo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHNhdmVfdG9yY2hfc3RhdGVfZGljdCUwQW1vZGVsJTIwJTNEJTIwLi4uJTIwJTIzJTIwQSUyMFB5VG9yY2glMjBtb2RlbCUwQSUwQXN0YXRlX2RpY3QlMjAlM0QlMjBtb2RlbF90b19zYXZlLnN0YXRlX2RpY3QoKSUwQXNhdmVfdG9yY2hfc3RhdGVfZGljdChzdGF0ZV9kaWN0JTJDJTIwJTIycGF0aCUyRnRvJTJGZm9sZGVyJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> save_torch_state_dict
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ... <span class="hljs-comment"># A PyTorch model</span>

<span class="hljs-comment"># Save state dict to &quot;path/to/folder&quot;. The model will be split into shards of 5GB each and saved as safetensors.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>state_dict = model_to_save.state_dict()
<span class="hljs-meta">&gt;&gt;&gt; </span>save_torch_state_dict(state_dict, <span class="hljs-string">&quot;path/to/folder&quot;</span>)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Fo($){let t,M=`If one of the model’s tensor is bigger than <code>max_shard_size</code>, it will end up in its own shard which will have a
size greater than <code>max_shard_size</code>.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-16sq104"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Do($){let t,M=`To save a model state dictionary to the disk, see <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.save_torch_state_dict">save_torch_state_dict()</a>. This helper uses
<code>split_torch_state_dict_into_shards</code> under the hood.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-6g0ega"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Eo($){let t,M=`If one of the model’s tensor is bigger than <code>max_shard_size</code>, it will end up in its own shard which will have a
size greater than <code>max_shard_size</code>.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-16sq104"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Vo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"aW1wb3J0JTIwanNvbiUwQWltcG9ydCUyMG9zJTBBZnJvbSUyMHNhZmV0ZW5zb3JzLnRvcmNoJTIwaW1wb3J0JTIwc2F2ZV9maWxlJTIwYXMlMjBzYWZlX3NhdmVfZmlsZSUwQWZyb20lMjBodWdnaW5nZmFjZV9odWIlMjBpbXBvcnQlMjBzcGxpdF90b3JjaF9zdGF0ZV9kaWN0X2ludG9fc2hhcmRzJTBBJTBBZGVmJTIwc2F2ZV9zdGF0ZV9kaWN0KHN0YXRlX2RpY3QlM0ElMjBEaWN0JTVCc3RyJTJDJTIwdG9yY2guVGVuc29yJTVEJTJDJTIwc2F2ZV9kaXJlY3RvcnklM0ElMjBzdHIpJTNBJTBBJTIwJTIwJTIwJTIwc3RhdGVfZGljdF9zcGxpdCUyMCUzRCUyMHNwbGl0X3RvcmNoX3N0YXRlX2RpY3RfaW50b19zaGFyZHMoc3RhdGVfZGljdCklMEElMjAlMjAlMjAlMjBmb3IlMjBmaWxlbmFtZSUyQyUyMHRlbnNvcnMlMjBpbiUyMHN0YXRlX2RpY3Rfc3BsaXQuZmlsZW5hbWVfdG9fdGVuc29ycy5pdGVtcygpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2hhcmQlMjAlM0QlMjAlN0J0ZW5zb3IlM0ElMjBzdGF0ZV9kaWN0JTVCdGVuc29yJTVEJTIwZm9yJTIwdGVuc29yJTIwaW4lMjB0ZW5zb3JzJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2FmZV9zYXZlX2ZpbGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2hhcmQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcy5wYXRoLmpvaW4oc2F2ZV9kaXJlY3RvcnklMkMlMjBmaWxlbmFtZSklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtZXRhZGF0YSUzRCU3QiUyMmZvcm1hdCUyMiUzQSUyMCUyMnB0JTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMGlmJTIwc3RhdGVfZGljdF9zcGxpdC5pc19zaGFyZGVkJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5kZXglMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtZXRhZGF0YSUyMiUzQSUyMHN0YXRlX2RpY3Rfc3BsaXQubWV0YWRhdGElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ3ZWlnaHRfbWFwJTIyJTNBJTIwc3RhdGVfZGljdF9zcGxpdC50ZW5zb3JfdG9fZmlsZW5hbWUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3aXRoJTIwb3Blbihvcy5wYXRoLmpvaW4oc2F2ZV9kaXJlY3RvcnklMkMlMjAlMjJtb2RlbC5zYWZldGVuc29ycy5pbmRleC5qc29uJTIyKSUyQyUyMCUyMnclMjIpJTIwYXMlMjBmJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZi53cml0ZShqc29uLmR1bXBzKGluZGV4JTJDJTIwaW5kZW50JTNEMikp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> os
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> safetensors.torch <span class="hljs-keyword">import</span> save_file <span class="hljs-keyword">as</span> safe_save_file
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> split_torch_state_dict_into_shards

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">save_state_dict</span>(<span class="hljs-params">state_dict: <span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, torch.Tensor], save_directory: <span class="hljs-built_in">str</span></span>):
<span class="hljs-meta">... </span>    state_dict_split = split_torch_state_dict_into_shards(state_dict)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> filename, tensors <span class="hljs-keyword">in</span> state_dict_split.filename_to_tensors.items():
<span class="hljs-meta">... </span>        shard = {tensor: state_dict[tensor] <span class="hljs-keyword">for</span> tensor <span class="hljs-keyword">in</span> tensors}
<span class="hljs-meta">... </span>        safe_save_file(
<span class="hljs-meta">... </span>            shard,
<span class="hljs-meta">... </span>            os.path.join(save_directory, filename),
<span class="hljs-meta">... </span>            metadata={<span class="hljs-string">&quot;format&quot;</span>: <span class="hljs-string">&quot;pt&quot;</span>},
<span class="hljs-meta">... </span>        )
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> state_dict_split.is_sharded:
<span class="hljs-meta">... </span>        index = {
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;metadata&quot;</span>: state_dict_split.metadata,
<span class="hljs-meta">... </span>            <span class="hljs-string">&quot;weight_map&quot;</span>: state_dict_split.tensor_to_filename,
<span class="hljs-meta">... </span>        }
<span class="hljs-meta">... </span>        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(os.path.join(save_directory, <span class="hljs-string">&quot;model.safetensors.index.json&quot;</span>), <span class="hljs-string">&quot;w&quot;</span>) <span class="hljs-keyword">as</span> f:
<span class="hljs-meta">... </span>            f.write(json.dumps(index, indent=<span class="hljs-number">2</span>))`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Xo($){let t,M=`If one of the model’s tensor is bigger than <code>max_shard_size</code>, it will end up in its own shard which will have a
size greater than <code>max_shard_size</code>.`;return{c(){t=p("p"),t.innerHTML=M},l(r){t=h(r,"P",{"data-svelte-h":!0}),b(t)!=="svelte-16sq104"&&(t.innerHTML=M)},m(r,c){i(r,t,c)},p:k,d(r){r&&n(t)}}}function Lo($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGxvYWRfdG9yY2hfbW9kZWwlMEFtb2RlbCUyMCUzRCUyMC4uLiUyMCUyMyUyMEElMjBQeVRvcmNoJTIwbW9kZWwlMEFsb2FkX3RvcmNoX21vZGVsKG1vZGVsJTJDJTIwJTIycGF0aCUyRnRvJTJGY2hlY2twb2ludCUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> load_torch_model
<span class="hljs-meta">&gt;&gt;&gt; </span>model = ... <span class="hljs-comment"># A PyTorch model</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>load_torch_model(model, <span class="hljs-string">&quot;path/to/checkpoint&quot;</span>)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function No($){let t,M="Example:",r,c,j;return c=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGxvYWRfc3RhdGVfZGljdF9mcm9tX2ZpbGUlMEElMEFzdGF0ZV9kaWN0JTIwJTNEJTIwbG9hZF9zdGF0ZV9kaWN0X2Zyb21fZmlsZSglMjJwYXRoJTJGdG8lMkZtb2RlbC5iaW4lMjIlMkMlMjBtYXBfbG9jYXRpb24lM0QlMjJjcHUlMjIpJTBBbW9kZWwubG9hZF9zdGF0ZV9kaWN0KHN0YXRlX2RpY3QpJTBBJTBBc3RhdGVfZGljdCUyMCUzRCUyMGxvYWRfc3RhdGVfZGljdF9mcm9tX2ZpbGUoJTIycGF0aCUyRnRvJTJGbW9kZWwuc2FmZXRlbnNvcnMlMjIpJTBBbW9kZWwubG9hZF9zdGF0ZV9kaWN0KHN0YXRlX2RpY3Qp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> load_state_dict_from_file

<span class="hljs-comment"># Load a PyTorch checkpoint</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>state_dict = load_state_dict_from_file(<span class="hljs-string">&quot;path/to/model.bin&quot;</span>, map_location=<span class="hljs-string">&quot;cpu&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.load_state_dict(state_dict)

<span class="hljs-comment"># Load a safetensors checkpoint</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>state_dict = load_state_dict_from_file(<span class="hljs-string">&quot;path/to/model.safetensors&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.load_state_dict(state_dict)`,wrap:!1}}),{c(){t=p("p"),t.textContent=M,r=o(),m(c.$$.fragment)},l(s){t=h(s,"P",{"data-svelte-h":!0}),b(t)!=="svelte-11lpom8"&&(t.textContent=M),r=l(s),f(c.$$.fragment,s)},m(s,w){i(s,t,w),i(s,r,w),g(c,s,w),j=!0},p:k,i(s){j||(u(c.$$.fragment,s),j=!0)},o(s){_(c.$$.fragment,s),j=!1},d(s){s&&(n(t),n(r)),y(c,s)}}}function Ao($){let t,M,r,c,j,s,w,wn="<code>huggingface_hub</code> provides helpers to save and load ML model weights in a standardized way. This part of the library is still under development and will be improved in future releases. The goal is to harmonize how weights are saved and loaded across the Hub, both to remove code duplication across libraries and to establish consistent conventions.",ys,Ge,bs,Ie,$n='DDUF is a file format designed for diffusion models. It allows saving all the information to run a model in a single file. This work is inspired by the <a href="https://github.com/ggerganov/ggml/blob/master/docs/gguf.md" rel="nofollow">GGUF</a> format. <code>huggingface_hub</code> provides helpers to save and load DDUF files, ensuring the file format is respected.',Ms,pe,js,Ce,ws,Re,vn='Here is how to export a folder containing different parts of a diffusion model using <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.export_folder_as_dduf">export_folder_as_dduf()</a>:',$s,Be,vs,We,Tn='For more flexibility, you can use <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.export_entries_as_dduf">export_entries_as_dduf()</a> and pass a list of files to include in the final DDUF file:',Ts,ze,xs,Fe,xn="The <code>entries</code> parameter also supports passing an iterable of paths or bytes. This can prove useful if you have a loaded model and want to serialize it directly into a DDUF file instead of having to serialize each component to disk first and then as a DDUF file. Here is an example of how a <code>StableDiffusionPipeline</code> can be serialized as DDUF:",Us,De,Js,Ee,Un="<strong>Note:</strong> in practice, <code>diffusers</code> provides a method to directly serialize a pipeline in a DDUF file. The snippet above is only meant as an example.",Zs,Ve,ks,Xe,Gs,Le,Is,R,Ne,ua,Ct,Jn="Write a DDUF file from an iterable of entries.",_a,Rt,Zn=`This is a lower-level helper than <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.export_folder_as_dduf">export_folder_as_dduf()</a> that allows more flexibility when serializing data.
In particular, you don’t need to save the data on disk before exporting it in the DDUF file.`,ya,he,ba,me,Cs,F,Ae,Ma,Bt,kn="Export a folder as a DDUF file.",ja,Wt,Gn='AUses <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.export_entries_as_dduf">export_entries_as_dduf()</a> under the hood.',wa,fe,Rs,D,Se,$a,zt,In="Read a DDUF file and return a dictionary of entries.",va,Ft,Cn="Only the metadata is read, the data is not loaded in memory.",Ta,ge,Bs,B,He,xa,Dt,Rn="Object representing a file entry in a DDUF file.",Ua,Et,Bn='See <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.read_dduf_file">read_dduf_file()</a> for how to read a DDUF file.',Ja,A,Ye,Za,Vt,Wn="Open the file as a memory-mapped file.",ka,Xt,zn="Useful to load safetensors directly from the file.",Ga,ue,Ia,S,qe,Ca,Lt,Fn="Read the file as text.",Ra,Nt,Dn="Useful for ‘.txt’ and ‘.json’ entries.",Ba,_e,Ws,Pe,zs,ae,Qe,Wa,At,En="Base exception for errors related to the DDUF format.",Fs,ne,Ke,za,St,Vn="Exception thrown when the DDUF file is corrupted.",Ds,oe,Oe,Fa,Ht,Xn="Base exception for errors during DDUF export.",Es,le,et,Da,Yt,Ln="Exception thrown when the entry name is invalid.",Vs,tt,Xs,st,Nn='The main helper of the <code>serialization</code> module takes a torch <code>nn.Module</code> as input and saves it to disk. It handles the logic to save shared tensors (see <a href="https://huggingface.co/docs/safetensors/torch_shared_tensors" rel="nofollow">safetensors explanation</a>) as well as logic to split the state dictionary into shards, using <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.split_torch_state_dict_into_shards">split_torch_state_dict_into_shards()</a> under the hood. At the moment, only <code>torch</code> framework is supported.',Ls,at,An='If you want to save a state dictionary (e.g. a mapping between layer names and related tensors) instead of a <code>nn.Module</code>, you can use <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.save_torch_state_dict">save_torch_state_dict()</a> which provides the same features. This is useful for example if you want to apply custom logic to the state dict before saving it.',Ns,nt,As,v,ot,Ea,qt,Sn="Saves a given torch model to disk, handling sharding and shared tensors issues.",Va,Pt,Hn='See also <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.save_torch_state_dict">save_torch_state_dict()</a> to save a state dict with more flexibility.',Xa,Qt,Yn='For more information about tensor sharing, check out <a href="https://huggingface.co/docs/safetensors/torch_shared_tensors" rel="nofollow">this guide</a>.',La,Kt,qn=`The model state dictionary is split into shards so that each shard is smaller than a given size. The shards are
saved in the <code>save_directory</code> with the given <code>filename_pattern</code>. If the model is too big to fit in a single shard,
an index file is saved in the <code>save_directory</code> to indicate where each tensor is saved. This helper uses
<a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.split_torch_state_dict_into_shards">split_torch_state_dict_into_shards()</a> under the hood. If <code>safe_serialization</code> is <code>True</code>, the shards are saved as
safetensors (the default). Otherwise, the shards are saved as pickle.`,Na,Ot,Pn="Before saving the model, the <code>save_directory</code> is cleaned from any previous shard files.",Aa,ye,Sa,be,Ha,Me,Ss,lt,Hs,T,rt,Ya,es,Qn="Save a model state dictionary to the disk, handling sharding and shared tensors issues.",qa,ts,Kn='See also <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.save_torch_model">save_torch_model()</a> to directly save a PyTorch model.',Pa,ss,On='For more information about tensor sharing, check out <a href="https://huggingface.co/docs/safetensors/torch_shared_tensors" rel="nofollow">this guide</a>.',Qa,as,eo=`The model state dictionary is split into shards so that each shard is smaller than a given size. The shards are
saved in the <code>save_directory</code> with the given <code>filename_pattern</code>. If the model is too big to fit in a single shard,
an index file is saved in the <code>save_directory</code> to indicate where each tensor is saved. This helper uses
<a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.split_torch_state_dict_into_shards">split_torch_state_dict_into_shards()</a> under the hood. If <code>safe_serialization</code> is <code>True</code>, the shards are saved as
safetensors (the default). Otherwise, the shards are saved as pickle.`,Ka,ns,to="Before saving the model, the <code>save_directory</code> is cleaned from any previous shard files.",Oa,je,en,we,tn,$e,Ys,it,so="The <code>serialization</code> module also contains low-level helpers to split a state dictionary into several shards, while creating a proper index in the process. These helpers are available for <code>torch</code> and <code>tensorflow</code> tensors and are designed to be easily extended to any other ML frameworks.",qs,ct,Ps,E,dt,sn,os,ao="Split a model state dictionary in shards so that each shard is smaller than a given size.",an,ls,no=`The shards are determined by iterating through the <code>state_dict</code> in the order of its keys. There is no optimization
made to make each shard as close as possible to the maximum size passed. For example, if the limit is 10GB and we
have tensors of sizes [6GB, 6GB, 2GB, 6GB, 2GB, 2GB] they will get sharded as [6GB], [6+2GB], [6+2+2GB] and not
[6+2+2GB], [6+2GB], [6GB].`,nn,ve,Qs,pt,Ks,C,ht,on,rs,oo="Split a model state dictionary in shards so that each shard is smaller than a given size.",ln,is,lo=`The shards are determined by iterating through the <code>state_dict</code> in the order of its keys. There is no optimization
made to make each shard as close as possible to the maximum size passed. For example, if the limit is 10GB and we
have tensors of sizes [6GB, 6GB, 2GB, 6GB, 2GB, 2GB] they will get sharded as [6GB], [6+2GB], [6+2+2GB] and not
[6+2+2GB], [6+2GB], [6GB].`,rn,Te,cn,xe,dn,Ue,Os,mt,ea,ft,ro='This is the underlying factory from which each framework-specific helper is derived. In practice, you are not expected to use this factory directly except if you need to adapt it to a framework that is not yet supported. If that is the case, please let us know by <a href="https://github.com/huggingface/huggingface_hub/issues/new" rel="nofollow">opening a new issue</a> on the <code>huggingface_hub</code> repo.',ta,V,gt,pn,cs,io="Split a model state dictionary in shards so that each shard is smaller than a given size.",hn,ds,co=`The shards are determined by iterating through the <code>state_dict</code> in the order of its keys. There is no optimization
made to make each shard as close as possible to the maximum size passed. For example, if the limit is 10GB and we
have tensors of sizes [6GB, 6GB, 2GB, 6GB, 2GB, 2GB] they will get sharded as [6GB], [6+2GB], [6+2+2GB] and not
[6+2+2GB], [6+2GB], [6GB].`,mn,Je,sa,ut,aa,_t,po='The loading helpers support both single-file and sharded checkpoints in either safetensors or pickle format. <a href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.load_torch_model">load_torch_model()</a> takes a <code>nn.Module</code> and a checkpoint path (either a single file or a directory) as input and load the weights into the model.',na,yt,oa,H,bt,fn,ps,ho="Load a checkpoint into a model, handling both sharded and non-sharded checkpoints.",gn,Ze,la,Mt,ra,Y,jt,un,hs,mo="Loads a checkpoint file, handling both safetensors and pickle checkpoint formats.",_n,ke,ia,wt,ca,$t,da,X,vt,yn,ms,fo="Return unique identifier to a tensor storage.",bn,fs,go=`Multiple different tensors can share the same underlying storage. This identifier is
guaranteed to be unique and constant for this tensor’s storage during its lifetime. Two tensor storages with
non-overlapping lifetimes may have the same id.
In the case of meta tensors, we return None since we can’t tell if they share the same storage.`,Mn,gs,uo='Taken from <a href="https://github.com/huggingface/transformers/blob/1ecf5f7c982d761b4daaa96719d162c324187c64/src/transformers/pytorch_utils.py#L278" rel="nofollow">https://github.com/huggingface/transformers/blob/1ecf5f7c982d761b4daaa96719d162c324187c64/src/transformers/pytorch_utils.py#L278</a>.',pa,Tt,ha,re,xt,jn,us,_o='Taken from <a href="https://github.com/huggingface/safetensors/blob/08db34094e9e59e2f9218f2df133b7b4aaff5a99/bindings/python/py_src/safetensors/torch.py#L31C1-L41C59" rel="nofollow">https://github.com/huggingface/safetensors/blob/08db34094e9e59e2f9218f2df133b7b4aaff5a99/bindings/python/py_src/safetensors/torch.py#L31C1-L41C59</a>',ma,Ut,fa,_s,ga;return j=new I({props:{title:"Serialization",local:"serialization",headingTag:"h1"}}),Ge=new I({props:{title:"DDUF file format",local:"dduf-file-format",headingTag:"h2"}}),pe=new de({props:{warning:!0,$$slots:{default:[To]},$$scope:{ctx:$}}}),Ce=new I({props:{title:"How to write a DDUF file?",local:"how-to-write-a-dduf-file",headingTag:"h3"}}),Be=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGV4cG9ydF9mb2xkZXJfYXNfZGR1ZiUwQWV4cG9ydF9mb2xkZXJfYXNfZGR1ZiglMjJGTFVYLjEtZGV2LmRkdWYlMjIlMkMlMjBmb2xkZXJfcGF0aCUzRCUyMnBhdGglMkZ0byUyRkZMVVguMS1kZXYlMjIp",highlighted:`<span class="hljs-comment"># Export a folder as a DDUF file</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_folder_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>export_folder_as_dduf(<span class="hljs-string">&quot;FLUX.1-dev.dduf&quot;</span>, folder_path=<span class="hljs-string">&quot;path/to/FLUX.1-dev&quot;</span>)`,wrap:!1}}),ze=new z({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGV4cG9ydF9lbnRyaWVzX2FzX2RkdWYlMEFleHBvcnRfZW50cmllc19hc19kZHVmKCUwQSUyMCUyMCUyMCUyMGRkdWZfcGF0aCUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNC1GUDE2LmRkdWYlMjIlMkMlMEElMjAlMjAlMjAlMjBlbnRyaWVzJTNEJTVCJTIwJTIzJTIwTGlzdCUyMGVudHJpZXMlMjB0byUyMGFkZCUyMHRvJTIwdGhlJTIwRERVRiUyMGZpbGUlMjAoaGVyZSUyQyUyMG9ubHklMjBGUDE2JTIwd2VpZ2h0cyklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAoJTIybW9kZWxfaW5kZXguanNvbiUyMiUyQyUyMCUyMnBhdGglMkZ0byUyRm1vZGVsX2luZGV4Lmpzb24lMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKCUyMnZhZSUyRmNvbmZpZy5qc29uJTIyJTJDJTIwJTIycGF0aCUyRnRvJTJGdmFlJTJGY29uZmlnLmpzb24lMjIpJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKCUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLmZwMTYuc2FmZXRlbnNvcnMlMjIlMkMlMjAlMjJwYXRoJTJGdG8lMkZ2YWUlMkZkaWZmdXNpb25fcHl0b3JjaF9tb2RlbC5mcDE2LnNhZmV0ZW5zb3JzJTIyKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCglMjJ0ZXh0X2VuY29kZXIlMkZjb25maWcuanNvbiUyMiUyQyUyMCUyMnBhdGglMkZ0byUyRnRleHRfZW5jb2RlciUyRmNvbmZpZy5qc29uJTIyKSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCglMjJ0ZXh0X2VuY29kZXIlMkZtb2RlbC5mcDE2LnNhZmV0ZW5zb3JzJTIyJTJDJTIwJTIycGF0aCUyRnRvJTJGdGV4dF9lbmNvZGVyJTJGbW9kZWwuZnAxNi5zYWZldGVuc29ycyUyMiklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjAuLi4lMjBhZGQlMjBtb3JlJTIwZW50cmllcyUyMGhlcmUlMEElMjAlMjAlMjAlMjAlNUQlMEEp",highlighted:`<span class="hljs-comment"># Export specific files from the local disk.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_entries_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>export_entries_as_dduf(
<span class="hljs-meta">... </span>    dduf_path=<span class="hljs-string">&quot;stable-diffusion-v1-4-FP16.dduf&quot;</span>,
<span class="hljs-meta">... </span>    entries=[ <span class="hljs-comment"># List entries to add to the DDUF file (here, only FP16 weights)</span>
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;model_index.json&quot;</span>, <span class="hljs-string">&quot;path/to/model_index.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;vae/config.json&quot;</span>, <span class="hljs-string">&quot;path/to/vae/config.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;vae/diffusion_pytorch_model.fp16.safetensors&quot;</span>, <span class="hljs-string">&quot;path/to/vae/diffusion_pytorch_model.fp16.safetensors&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;text_encoder/config.json&quot;</span>, <span class="hljs-string">&quot;path/to/text_encoder/config.json&quot;</span>),
<span class="hljs-meta">... </span>        (<span class="hljs-string">&quot;text_encoder/model.fp16.safetensors&quot;</span>, <span class="hljs-string">&quot;path/to/text_encoder/model.fp16.safetensors&quot;</span>),
<span class="hljs-meta">... </span>        <span class="hljs-comment"># ... add more entries here</span>
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>)`,wrap:!1}}),De=new z({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMEdlbmVyYXRvciUyQyUyMFR1cGxlJTBBaW1wb3J0JTIwc2FmZXRlbnNvcnMudG9yY2glMEFmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwZXhwb3J0X2VudHJpZXNfYXNfZGR1ZiUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiklMEElMjMlMjAuLi4lMjBkbyUyMHNvbWUlMjB3b3JrJTIwd2l0aCUyMHRoZSUyMHBpcGVsaW5lJTBBJTBBZGVmJTIwYXNfZW50cmllcyhwaXBlJTNBJTIwRGlmZnVzaW9uUGlwZWxpbmUpJTIwLSUzRSUyMEdlbmVyYXRvciU1QlR1cGxlJTVCc3RyJTJDJTIwYnl0ZXMlNUQlMkMlMjBOb25lJTJDJTIwTm9uZSU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEJ1aWxkJTIwYSUyMGdlbmVyYXRvciUyMHRoYXQlMjB5aWVsZHMlMjB0aGUlMjBlbnRyaWVzJTIwdG8lMjBhZGQlMjB0byUyMHRoZSUyMEREVUYlMjBmaWxlLiUwQSUyMCUyMCUyMCUyMCUyMyUyMFRoZSUyMGZpcnN0JTIwZWxlbWVudCUyMG9mJTIwdGhlJTIwdHVwbGUlMjBpcyUyMHRoZSUyMGZpbGVuYW1lJTIwaW4lMjB0aGUlMjBERFVGJTIwYXJjaGl2ZSUyMChtdXN0JTIwdXNlJTIwVU5JWCUyMHNlcGFyYXRvciEpLiUyMFRoZSUyMHNlY29uZCUyMGVsZW1lbnQlMjBpcyUyMHRoZSUyMGNvbnRlbnQlMjBvZiUyMHRoZSUyMGZpbGUuJTBBJTIwJTIwJTIwJTIwJTIzJTIwRW50cmllcyUyMHdpbGwlMjBiZSUyMGV2YWx1YXRlZCUyMGxhemlseSUyMHdoZW4lMjB0aGUlMjBERFVGJTIwZmlsZSUyMGlzJTIwY3JlYXRlZCUyMChvbmx5JTIwMSUyMGVudHJ5JTIwaXMlMjBsb2FkZWQlMjBpbiUyMG1lbW9yeSUyMGF0JTIwYSUyMHRpbWUpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ2YWUlMkZjb25maWcuanNvbiUyMiUyQyUyMHBpcGUudmFlLnRvX2pzb25fc3RyaW5nKCkuZW5jb2RlKCklMEElMjAlMjAlMjAlMjB5aWVsZCUyMCUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLnNhZmV0ZW5zb3JzJTIyJTJDJTIwc2FmZXRlbnNvcnMudG9yY2guc2F2ZShwaXBlLnZhZS5zdGF0ZV9kaWN0KCkpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ0ZXh0X2VuY29kZXIlMkZjb25maWcuanNvbiUyMiUyQyUyMHBpcGUudGV4dF9lbmNvZGVyLmNvbmZpZy50b19qc29uX3N0cmluZygpLmVuY29kZSgpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ0ZXh0X2VuY29kZXIlMkZtb2RlbC5zYWZldGVuc29ycyUyMiUyQyUyMHNhZmV0ZW5zb3JzLnRvcmNoLnNhdmUocGlwZS50ZXh0X2VuY29kZXIuc3RhdGVfZGljdCgpKSUwQSUyMCUyMCUyMCUyMCUyMyUyMC4uLiUyMGFkZCUyMG1vcmUlMjBlbnRyaWVzJTIwaGVyZSUwQSUwQWV4cG9ydF9lbnRyaWVzX2FzX2RkdWYoZGR1Zl9wYXRoJTNEJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS00LmRkdWYlMjIlMkMlMjBlbnRyaWVzJTNEYXNfZW50cmllcyhwaXBlKSk=",highlighted:`<span class="hljs-comment"># Export state_dicts one by one from a loaded pipeline </span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> Generator, <span class="hljs-type">Tuple</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> safetensors.torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> export_entries_as_dduf
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
<span class="hljs-meta">... </span><span class="hljs-comment"># ... do some work with the pipeline</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">as_entries</span>(<span class="hljs-params">pipe: DiffusionPipeline</span>) -&gt; Generator[<span class="hljs-type">Tuple</span>[<span class="hljs-built_in">str</span>, <span class="hljs-built_in">bytes</span>], <span class="hljs-literal">None</span>, <span class="hljs-literal">None</span>]:
<span class="hljs-meta">... </span>    <span class="hljs-comment"># Build a generator that yields the entries to add to the DDUF file.</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># The first element of the tuple is the filename in the DDUF archive (must use UNIX separator!). The second element is the content of the file.</span>
<span class="hljs-meta">... </span>    <span class="hljs-comment"># Entries will be evaluated lazily when the DDUF file is created (only 1 entry is loaded in memory at a time)</span>
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;vae/config.json&quot;</span>, pipe.vae.to_json_string().encode()
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;vae/diffusion_pytorch_model.safetensors&quot;</span>, safetensors.torch.save(pipe.vae.state_dict())
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;text_encoder/config.json&quot;</span>, pipe.text_encoder.config.to_json_string().encode()
<span class="hljs-meta">... </span>    <span class="hljs-keyword">yield</span> <span class="hljs-string">&quot;text_encoder/model.safetensors&quot;</span>, safetensors.torch.save(pipe.text_encoder.state_dict())
<span class="hljs-meta">... </span>    <span class="hljs-comment"># ... add more entries here</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>export_entries_as_dduf(dduf_path=<span class="hljs-string">&quot;stable-diffusion-v1-4.dduf&quot;</span>, entries=as_entries(pipe))`,wrap:!1}}),Ve=new I({props:{title:"How to read a DDUF file?",local:"how-to-read-a-dduf-file",headingTag:"h3"}}),Xe=new z({props:{code:"aW1wb3J0JTIwanNvbiUwQWltcG9ydCUyMHNhZmV0ZW5zb3JzLnRvcmNoJTBBZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHJlYWRfZGR1Zl9maWxlJTBBJTBBZGR1Zl9lbnRyaWVzJTIwJTNEJTIwcmVhZF9kZHVmX2ZpbGUoJTIyRkxVWC4xLWRldi5kZHVmJTIyKSUwQSUwQWRkdWZfZW50cmllcyU1QiUyMm1vZGVsX2luZGV4Lmpzb24lMjIlNUQlMEElMEFqc29uLmxvYWRzKGRkdWZfZW50cmllcyU1QiUyMm1vZGVsX2luZGV4Lmpzb24lMjIlNUQucmVhZF90ZXh0KCkpJTBBJTBBd2l0aCUyMGRkdWZfZW50cmllcyU1QiUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLnNhZmV0ZW5zb3JzJTIyJTVELmFzX21tYXAoKSUyMGFzJTIwbW0lM0ElMEElMjAlMjAlMjAlMjBzdGF0ZV9kaWN0JTIwJTNEJTIwc2FmZXRlbnNvcnMudG9yY2gubG9hZChtbSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> json
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> safetensors.torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> read_dduf_file

<span class="hljs-comment"># Read DDUF metadata</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dduf_entries = read_dduf_file(<span class="hljs-string">&quot;FLUX.1-dev.dduf&quot;</span>)

<span class="hljs-comment"># Returns a mapping filename &lt;&gt; DDUFEntry</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dduf_entries[<span class="hljs-string">&quot;model_index.json&quot;</span>]
DDUFEntry(filename=<span class="hljs-string">&#x27;model_index.json&#x27;</span>, offset=<span class="hljs-number">66</span>, length=<span class="hljs-number">587</span>)

<span class="hljs-comment"># Load model index as JSON</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>json.loads(dduf_entries[<span class="hljs-string">&quot;model_index.json&quot;</span>].read_text())
{<span class="hljs-string">&#x27;_class_name&#x27;</span>: <span class="hljs-string">&#x27;FluxPipeline&#x27;</span>, <span class="hljs-string">&#x27;_diffusers_version&#x27;</span>: <span class="hljs-string">&#x27;0.32.0.dev0&#x27;</span>, <span class="hljs-string">&#x27;_name_or_path&#x27;</span>: <span class="hljs-string">&#x27;black-forest-labs/FLUX.1-dev&#x27;</span>, <span class="hljs-string">&#x27;scheduler&#x27;</span>: [<span class="hljs-string">&#x27;diffusers&#x27;</span>, <span class="hljs-string">&#x27;FlowMatchEulerDiscreteScheduler&#x27;</span>], <span class="hljs-string">&#x27;text_encoder&#x27;</span>: [<span class="hljs-string">&#x27;transformers&#x27;</span>, <span class="hljs-string">&#x27;CLIPTextModel&#x27;</span>], <span class="hljs-string">&#x27;text_encoder_2&#x27;</span>: [<span class="hljs-string">&#x27;transformers&#x27;</span>, <span class="hljs-string">&#x27;T5EncoderModel&#x27;</span>], <span class="hljs-string">&#x27;tokenizer&#x27;</span>: [<span class="hljs-string">&#x27;transformers&#x27;</span>, <span class="hljs-string">&#x27;CLIPTokenizer&#x27;</span>], <span class="hljs-string">&#x27;tokenizer_2&#x27;</span>: [<span class="hljs-string">&#x27;transformers&#x27;</span>, <span class="hljs-string">&#x27;T5TokenizerFast&#x27;</span>], <span class="hljs-string">&#x27;transformer&#x27;</span>: [<span class="hljs-string">&#x27;diffusers&#x27;</span>, <span class="hljs-string">&#x27;FluxTransformer2DModel&#x27;</span>], <span class="hljs-string">&#x27;vae&#x27;</span>: [<span class="hljs-string">&#x27;diffusers&#x27;</span>, <span class="hljs-string">&#x27;AutoencoderKL&#x27;</span>]}

<span class="hljs-comment"># Load VAE weights using safetensors</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> dduf_entries[<span class="hljs-string">&quot;vae/diffusion_pytorch_model.safetensors&quot;</span>].as_mmap() <span class="hljs-keyword">as</span> mm:
<span class="hljs-meta">... </span>    state_dict = safetensors.torch.load(mm)`,wrap:!1}}),Le=new I({props:{title:"Helpers",local:"huggingface_hub.export_entries_as_dduf",headingTag:"h3"}}),Ne=new G({props:{name:"huggingface_hub.export_entries_as_dduf",anchor:"huggingface_hub.export_entries_as_dduf",parameters:[{name:"dduf_path",val:": typing.Union[str, os.PathLike]"},{name:"entries",val:": typing.Iterable[typing.Tuple[str, typing.Union[str, pathlib.Path, bytes]]]"}],parametersDescription:[{anchor:"huggingface_hub.export_entries_as_dduf.dduf_path",description:`<strong>dduf_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
The path to the DDUF file to write.`,name:"dduf_path"},{anchor:"huggingface_hub.export_entries_as_dduf.entries",description:`<strong>entries</strong> (<code>Iterable[Tuple[str, Union[str, Path, bytes]]]</code>) &#x2014;
An iterable of entries to write in the DDUF file. Each entry is a tuple with the filename and the content.
The filename should be the path to the file in the DDUF archive.
The content can be a string or a pathlib.Path representing a path to a file on the local disk or directly the content as bytes.`,name:"entries"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L159",raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><ul>
<li>— <code>DDUFExportError</code>: If anything goes wrong during the export (e.g. invalid entry name, missing ‘model_index.json’, etc.).</li>
</ul></li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li></li>
</ul>
`}}),he=new se({props:{anchor:"huggingface_hub.export_entries_as_dduf.example",$$slots:{default:[xo]},$$scope:{ctx:$}}}),me=new se({props:{anchor:"huggingface_hub.export_entries_as_dduf.example-2",$$slots:{default:[Uo]},$$scope:{ctx:$}}}),Ae=new G({props:{name:"huggingface_hub.export_folder_as_dduf",anchor:"huggingface_hub.export_folder_as_dduf",parameters:[{name:"dduf_path",val:": typing.Union[str, os.PathLike]"},{name:"folder_path",val:": typing.Union[str, os.PathLike]"}],parametersDescription:[{anchor:"huggingface_hub.export_folder_as_dduf.dduf_path",description:`<strong>dduf_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
The path to the DDUF file to write.`,name:"dduf_path"},{anchor:"huggingface_hub.export_folder_as_dduf.folder_path",description:`<strong>folder_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
The path to the folder containing the diffusion model.`,name:"folder_path"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L250"}}),fe=new se({props:{anchor:"huggingface_hub.export_folder_as_dduf.example",$$slots:{default:[Jo]},$$scope:{ctx:$}}}),Se=new G({props:{name:"huggingface_hub.read_dduf_file",anchor:"huggingface_hub.read_dduf_file",parameters:[{name:"dduf_path",val:": typing.Union[os.PathLike, str]"}],parametersDescription:[{anchor:"huggingface_hub.read_dduf_file.dduf_path",description:`<strong>dduf_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
The path to the DDUF file to read.`,name:"dduf_path"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L90",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A dictionary of <a
  href="/docs/huggingface_hub/main/en/package_reference/serialization#huggingface_hub.DDUFEntry"
>DDUFEntry</a> indexed by filename.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>Dict[str, DDUFEntry]</code></p>
`,raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><ul>
<li>— <code>DDUFCorruptedFileError</code>: If the DDUF file is corrupted (i.e. doesn’t follow the DDUF format).</li>
</ul></li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li></li>
</ul>
`}}),ge=new se({props:{anchor:"huggingface_hub.read_dduf_file.example",$$slots:{default:[Zo]},$$scope:{ctx:$}}}),He=new G({props:{name:"class huggingface_hub.DDUFEntry",anchor:"huggingface_hub.DDUFEntry",parameters:[{name:"filename",val:": str"},{name:"length",val:": int"},{name:"offset",val:": int"},{name:"dduf_path",val:": Path"}],parametersDescription:[{anchor:"huggingface_hub.DDUFEntry.filename",description:`<strong>filename</strong> (str) &#x2014;
The name of the file in the DDUF archive.`,name:"filename"},{anchor:"huggingface_hub.DDUFEntry.offset",description:`<strong>offset</strong> (int) &#x2014;
The offset of the file in the DDUF archive.`,name:"offset"},{anchor:"huggingface_hub.DDUFEntry.length",description:`<strong>length</strong> (int) &#x2014;
The length of the file in the DDUF archive.`,name:"length"},{anchor:"huggingface_hub.DDUFEntry.dduf_path",description:`<strong>dduf_path</strong> (str) &#x2014;
The path to the DDUF archive (for internal use).`,name:"dduf_path"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L34"}}),Ye=new G({props:{name:"as_mmap",anchor:"huggingface_hub.DDUFEntry.as_mmap",parameters:[],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L57"}}),ue=new se({props:{anchor:"huggingface_hub.DDUFEntry.as_mmap.example",$$slots:{default:[ko]},$$scope:{ctx:$}}}),qe=new G({props:{name:"read_text",anchor:"huggingface_hub.DDUFEntry.read_text",parameters:[{name:"encoding",val:": str = 'utf-8'"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_dduf.py#L74"}}),_e=new se({props:{anchor:"huggingface_hub.DDUFEntry.read_text.example",$$slots:{default:[Go]},$$scope:{ctx:$}}}),Pe=new I({props:{title:"Errors",local:"huggingface_hub.errors.DDUFError",headingTag:"h3"}}),Qe=new G({props:{name:"class huggingface_hub.errors.DDUFError",anchor:"huggingface_hub.errors.DDUFError",parameters:"",source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/errors.py#L316"}}),Ke=new G({props:{name:"class huggingface_hub.errors.DDUFCorruptedFileError",anchor:"huggingface_hub.errors.DDUFCorruptedFileError",parameters:"",source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/errors.py#L320"}}),Oe=new G({props:{name:"class huggingface_hub.errors.DDUFExportError",anchor:"huggingface_hub.errors.DDUFExportError",parameters:"",source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/errors.py#L324"}}),et=new G({props:{name:"class huggingface_hub.errors.DDUFInvalidEntryNameError",anchor:"huggingface_hub.errors.DDUFInvalidEntryNameError",parameters:"",source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/errors.py#L328"}}),tt=new I({props:{title:"Saving tensors",local:"saving-tensors",headingTag:"h2"}}),nt=new I({props:{title:"save_torch_model",local:"huggingface_hub.save_torch_model",headingTag:"h3"}}),ot=new G({props:{name:"huggingface_hub.save_torch_model",anchor:"huggingface_hub.save_torch_model",parameters:[{name:"model",val:": torch.nn.Module"},{name:"save_directory",val:": typing.Union[str, pathlib.Path]"},{name:"filename_pattern",val:": typing.Optional[str] = None"},{name:"force_contiguous",val:": bool = True"},{name:"max_shard_size",val:": typing.Union[int, str] = '5GB'"},{name:"metadata",val:": typing.Optional[typing.Dict[str, str]] = None"},{name:"safe_serialization",val:": bool = True"},{name:"is_main_process",val:": bool = True"},{name:"shared_tensors_to_discard",val:": typing.Optional[typing.List[str]] = None"}],parametersDescription:[{anchor:"huggingface_hub.save_torch_model.model",description:`<strong>model</strong> (<code>torch.nn.Module</code>) &#x2014;
The model to save on disk.`,name:"model"},{anchor:"huggingface_hub.save_torch_model.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>Path</code>) &#x2014;
The directory in which the model will be saved.`,name:"save_directory"},{anchor:"huggingface_hub.save_torch_model.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to generate the files names in which the model will be saved. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>
Defaults to <code>&quot;model{suffix}.safetensors&quot;</code> or <code>pytorch_model{suffix}.bin</code> depending on <code>safe_serialization</code>
parameter.`,name:"filename_pattern"},{anchor:"huggingface_hub.save_torch_model.force_contiguous",description:`<strong>force_contiguous</strong> (<code>boolean</code>, <em>optional</em>) &#x2014;
Forcing the state_dict to be saved as contiguous tensors. This has no effect on the correctness of the
model, but it could potentially change performance if the layout of the tensor was chosen specifically for
that reason. Defaults to <code>True</code>.`,name:"force_contiguous"},{anchor:"huggingface_hub.save_torch_model.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, <em>optional</em>) &#x2014;
The maximum size of each shard, in bytes. Defaults to 5GB.`,name:"max_shard_size"},{anchor:"huggingface_hub.save_torch_model.metadata",description:`<strong>metadata</strong> (<code>Dict[str, str]</code>, <em>optional</em>) &#x2014;
Extra information to save along with the model. Some metadata will be added for each dropped tensors.
This information will not be enough to recover the entire shared structure but might help understanding
things.`,name:"metadata"},{anchor:"huggingface_hub.save_torch_model.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether to save as safetensors, which is the default behavior. If <code>False</code>, the shards are saved as pickle.
Safe serialization is recommended for security reasons. Saving as pickle is deprecated and will be removed
in a future version.`,name:"safe_serialization"},{anchor:"huggingface_hub.save_torch_model.is_main_process",description:`<strong>is_main_process</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether the process calling this is the main process or not. Useful when in distributed training like
TPUs and need to call this function from all processes. In this case, set <code>is_main_process=True</code> only on
the main process to avoid race conditions. Defaults to True.`,name:"is_main_process"},{anchor:"huggingface_hub.save_torch_model.shared_tensors_to_discard",description:`<strong>shared_tensors_to_discard</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
List of tensor names to drop when saving shared tensors. If not provided and shared tensors are
detected, it will drop the first name alphabetically.`,name:"shared_tensors_to_discard"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L39"}}),ye=new de({props:{warning:!0,$$slots:{default:[Io]},$$scope:{ctx:$}}}),be=new de({props:{warning:!0,$$slots:{default:[Co]},$$scope:{ctx:$}}}),Me=new se({props:{anchor:"huggingface_hub.save_torch_model.example",$$slots:{default:[Ro]},$$scope:{ctx:$}}}),lt=new I({props:{title:"save_torch_state_dict",local:"huggingface_hub.save_torch_state_dict",headingTag:"h3"}}),rt=new G({props:{name:"huggingface_hub.save_torch_state_dict",anchor:"huggingface_hub.save_torch_state_dict",parameters:[{name:"state_dict",val:": typing.Dict[str, ForwardRef('torch.Tensor')]"},{name:"save_directory",val:": typing.Union[str, pathlib.Path]"},{name:"filename_pattern",val:": typing.Optional[str] = None"},{name:"force_contiguous",val:": bool = True"},{name:"max_shard_size",val:": typing.Union[int, str] = '5GB'"},{name:"metadata",val:": typing.Optional[typing.Dict[str, str]] = None"},{name:"safe_serialization",val:": bool = True"},{name:"is_main_process",val:": bool = True"},{name:"shared_tensors_to_discard",val:": typing.Optional[typing.List[str]] = None"}],parametersDescription:[{anchor:"huggingface_hub.save_torch_state_dict.state_dict",description:`<strong>state_dict</strong> (<code>Dict[str, torch.Tensor]</code>) &#x2014;
The state dictionary to save.`,name:"state_dict"},{anchor:"huggingface_hub.save_torch_state_dict.save_directory",description:`<strong>save_directory</strong> (<code>str</code> or <code>Path</code>) &#x2014;
The directory in which the model will be saved.`,name:"save_directory"},{anchor:"huggingface_hub.save_torch_state_dict.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to generate the files names in which the model will be saved. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>
Defaults to <code>&quot;model{suffix}.safetensors&quot;</code> or <code>pytorch_model{suffix}.bin</code> depending on <code>safe_serialization</code>
parameter.`,name:"filename_pattern"},{anchor:"huggingface_hub.save_torch_state_dict.force_contiguous",description:`<strong>force_contiguous</strong> (<code>boolean</code>, <em>optional</em>) &#x2014;
Forcing the state_dict to be saved as contiguous tensors. This has no effect on the correctness of the
model, but it could potentially change performance if the layout of the tensor was chosen specifically for
that reason. Defaults to <code>True</code>.`,name:"force_contiguous"},{anchor:"huggingface_hub.save_torch_state_dict.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, <em>optional</em>) &#x2014;
The maximum size of each shard, in bytes. Defaults to 5GB.`,name:"max_shard_size"},{anchor:"huggingface_hub.save_torch_state_dict.metadata",description:`<strong>metadata</strong> (<code>Dict[str, str]</code>, <em>optional</em>) &#x2014;
Extra information to save along with the model. Some metadata will be added for each dropped tensors.
This information will not be enough to recover the entire shared structure but might help understanding
things.`,name:"metadata"},{anchor:"huggingface_hub.save_torch_state_dict.safe_serialization",description:`<strong>safe_serialization</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether to save as safetensors, which is the default behavior. If <code>False</code>, the shards are saved as pickle.
Safe serialization is recommended for security reasons. Saving as pickle is deprecated and will be removed
in a future version.`,name:"safe_serialization"},{anchor:"huggingface_hub.save_torch_state_dict.is_main_process",description:`<strong>is_main_process</strong> (<code>bool</code>, <em>optional</em>) &#x2014;
Whether the process calling this is the main process or not. Useful when in distributed training like
TPUs and need to call this function from all processes. In this case, set <code>is_main_process=True</code> only on
the main process to avoid race conditions. Defaults to True.`,name:"is_main_process"},{anchor:"huggingface_hub.save_torch_state_dict.shared_tensors_to_discard",description:`<strong>shared_tensors_to_discard</strong> (<code>List[str]</code>, <em>optional</em>) &#x2014;
List of tensor names to drop when saving shared tensors. If not provided and shared tensors are
detected, it will drop the first name alphabetically.`,name:"shared_tensors_to_discard"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L139"}}),je=new de({props:{warning:!0,$$slots:{default:[Bo]},$$scope:{ctx:$}}}),we=new de({props:{warning:!0,$$slots:{default:[Wo]},$$scope:{ctx:$}}}),$e=new se({props:{anchor:"huggingface_hub.save_torch_state_dict.example",$$slots:{default:[zo]},$$scope:{ctx:$}}}),ct=new I({props:{title:"split_tf_state_dict_into_shards",local:"huggingface_hub.split_tf_state_dict_into_shards",headingTag:"h3"}}),dt=new G({props:{name:"huggingface_hub.split_tf_state_dict_into_shards",anchor:"huggingface_hub.split_tf_state_dict_into_shards",parameters:[{name:"state_dict",val:": typing.Dict[str, ForwardRef('tf.Tensor')]"},{name:"filename_pattern",val:": str = 'tf_model{suffix}.h5'"},{name:"max_shard_size",val:": typing.Union[int, str] = '5GB'"}],parametersDescription:[{anchor:"huggingface_hub.split_tf_state_dict_into_shards.state_dict",description:`<strong>state_dict</strong> (<code>Dict[str, Tensor]</code>) &#x2014;
The state dictionary to save.`,name:"state_dict"},{anchor:"huggingface_hub.split_tf_state_dict_into_shards.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to generate the files names in which the model will be saved. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>
Defaults to <code>&quot;tf_model{suffix}.h5&quot;</code>.`,name:"filename_pattern"},{anchor:"huggingface_hub.split_tf_state_dict_into_shards.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, <em>optional</em>) &#x2014;
The maximum size of each shard, in bytes. Defaults to 5GB.`,name:"max_shard_size"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_tensorflow.py#L28",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>StateDictSplit</code> object containing the shards and the index to retrieve them.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>StateDictSplit</code></p>
`}}),ve=new de({props:{warning:!0,$$slots:{default:[Fo]},$$scope:{ctx:$}}}),pt=new I({props:{title:"split_torch_state_dict_into_shards",local:"huggingface_hub.split_torch_state_dict_into_shards",headingTag:"h3"}}),ht=new G({props:{name:"huggingface_hub.split_torch_state_dict_into_shards",anchor:"huggingface_hub.split_torch_state_dict_into_shards",parameters:[{name:"state_dict",val:": typing.Dict[str, ForwardRef('torch.Tensor')]"},{name:"filename_pattern",val:": str = 'model{suffix}.safetensors'"},{name:"max_shard_size",val:": typing.Union[int, str] = '5GB'"}],parametersDescription:[{anchor:"huggingface_hub.split_torch_state_dict_into_shards.state_dict",description:`<strong>state_dict</strong> (<code>Dict[str, torch.Tensor]</code>) &#x2014;
The state dictionary to save.`,name:"state_dict"},{anchor:"huggingface_hub.split_torch_state_dict_into_shards.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to generate the files names in which the model will be saved. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>
Defaults to <code>&quot;model{suffix}.safetensors&quot;</code>.`,name:"filename_pattern"},{anchor:"huggingface_hub.split_torch_state_dict_into_shards.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, <em>optional</em>) &#x2014;
The maximum size of each shard, in bytes. Defaults to 5GB.`,name:"max_shard_size"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L302",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>StateDictSplit</code> object containing the shards and the index to retrieve them.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>StateDictSplit</code></p>
`}}),Te=new de({props:{$$slots:{default:[Do]},$$scope:{ctx:$}}}),xe=new de({props:{warning:!0,$$slots:{default:[Eo]},$$scope:{ctx:$}}}),Ue=new se({props:{anchor:"huggingface_hub.split_torch_state_dict_into_shards.example",$$slots:{default:[Vo]},$$scope:{ctx:$}}}),mt=new I({props:{title:"split_state_dict_into_shards_factory",local:"huggingface_hub.split_state_dict_into_shards_factory",headingTag:"h3"}}),gt=new G({props:{name:"huggingface_hub.split_state_dict_into_shards_factory",anchor:"huggingface_hub.split_state_dict_into_shards_factory",parameters:[{name:"state_dict",val:": typing.Dict[str, ~TensorT]"},{name:"get_storage_size",val:": typing.Callable[[~TensorT], int]"},{name:"filename_pattern",val:": str"},{name:"get_storage_id",val:": typing.Callable[[~TensorT], typing.Optional[typing.Any]] = <function <lambda> at 0x7f857638f7f0>"},{name:"max_shard_size",val:": typing.Union[int, str] = '5GB'"}],parametersDescription:[{anchor:"huggingface_hub.split_state_dict_into_shards_factory.state_dict",description:`<strong>state_dict</strong> (<code>Dict[str, Tensor]</code>) &#x2014;
The state dictionary to save.`,name:"state_dict"},{anchor:"huggingface_hub.split_state_dict_into_shards_factory.get_storage_size",description:`<strong>get_storage_size</strong> (<code>Callable[[Tensor], int]</code>) &#x2014;
A function that returns the size of a tensor when saved on disk in bytes.`,name:"get_storage_size"},{anchor:"huggingface_hub.split_state_dict_into_shards_factory.get_storage_id",description:`<strong>get_storage_id</strong> (<code>Callable[[Tensor], Optional[Any]]</code>, <em>optional</em>) &#x2014;
A function that returns a unique identifier to a tensor storage. Multiple different tensors can share the
same underlying storage. This identifier is guaranteed to be unique and constant for this tensor&#x2019;s storage
during its lifetime. Two tensor storages with non-overlapping lifetimes may have the same id.`,name:"get_storage_id"},{anchor:"huggingface_hub.split_state_dict_into_shards_factory.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to generate the files names in which the model will be saved. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>`,name:"filename_pattern"},{anchor:"huggingface_hub.split_state_dict_into_shards_factory.max_shard_size",description:`<strong>max_shard_size</strong> (<code>int</code> or <code>str</code>, <em>optional</em>) &#x2014;
The maximum size of each shard, in bytes. Defaults to 5GB.`,name:"max_shard_size"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_base.py#L49",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A <code>StateDictSplit</code> object containing the shards and the index to retrieve them.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>StateDictSplit</code></p>
`}}),Je=new de({props:{warning:!0,$$slots:{default:[Xo]},$$scope:{ctx:$}}}),ut=new I({props:{title:"Loading tensors",local:"loading-tensors",headingTag:"h2"}}),yt=new I({props:{title:"load_torch_model",local:"huggingface_hub.load_torch_model",headingTag:"h3"}}),bt=new G({props:{name:"huggingface_hub.load_torch_model",anchor:"huggingface_hub.load_torch_model",parameters:[{name:"model",val:": torch.nn.Module"},{name:"checkpoint_path",val:": typing.Union[str, os.PathLike]"},{name:"strict",val:": bool = False"},{name:"safe",val:": bool = True"},{name:"weights_only",val:": bool = False"},{name:"map_location",val:": typing.Union[str, ForwardRef('torch.device'), NoneType] = None"},{name:"mmap",val:": bool = False"},{name:"filename_pattern",val:": typing.Optional[str] = None"}],parametersDescription:[{anchor:"huggingface_hub.load_torch_model.model",description:`<strong>model</strong> (<code>torch.nn.Module</code>) &#x2014;
The model in which to load the checkpoint.`,name:"model"},{anchor:"huggingface_hub.load_torch_model.checkpoint_path",description:`<strong>checkpoint_path</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Path to either the checkpoint file or directory containing the checkpoint(s).`,name:"checkpoint_path"},{anchor:"huggingface_hub.load_torch_model.strict",description:`<strong>strict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to strictly enforce that the keys in the model state dict match the keys in the checkpoint.`,name:"strict"},{anchor:"huggingface_hub.load_torch_model.safe",description:`<strong>safe</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
If <code>safe</code> is True, the safetensors files will be loaded. If <code>safe</code> is False, the function
will first attempt to load safetensors files if they are available, otherwise it will fall back to loading
pickle files. <code>filename_pattern</code> parameter takes precedence over <code>safe</code> parameter.`,name:"safe"},{anchor:"huggingface_hub.load_torch_model.weights_only",description:`<strong>weights_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
If True, only loads the model weights without optimizer states and other metadata.
Only supported in PyTorch &gt;= 1.13.`,name:"weights_only"},{anchor:"huggingface_hub.load_torch_model.map_location",description:`<strong>map_location</strong> (<code>str</code> or <code>torch.device</code>, <em>optional</em>) &#x2014;
A <code>torch.device</code> object, string or a dict specifying how to remap storage locations. It
indicates the location where all tensors should be loaded.`,name:"map_location"},{anchor:"huggingface_hub.load_torch_model.mmap",description:`<strong>mmap</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use memory-mapped file loading. Memory mapping can improve loading performance
for large models in PyTorch &gt;= 2.1.0 with zipfile-based checkpoints.`,name:"mmap"},{anchor:"huggingface_hub.load_torch_model.filename_pattern",description:`<strong>filename_pattern</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The pattern to look for the index file. Pattern must be a string that
can be formatted with <code>filename_pattern.format(suffix=...)</code> and must contain the keyword <code>suffix</code>
Defaults to <code>&quot;model{suffix}.safetensors&quot;</code>.`,name:"filename_pattern"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L381",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>A named tuple with <code>missing_keys</code> and <code>unexpected_keys</code> fields.</p>
<ul>
<li><code>missing_keys</code> is a list of str containing the missing keys, i.e. keys that are in the model but not in the checkpoint.</li>
<li><code>unexpected_keys</code> is a list of str containing the unexpected keys, i.e. keys that are in the checkpoint but not in the model.</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>NamedTuple</code></p>
`,raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#FileNotFoundError"
  rel="nofollow"
><code>FileNotFoundError</code></a> —
If the checkpoint file or directory does not exist.</li>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#ImportError"
  rel="nofollow"
><code>ImportError</code></a> —
If safetensors or torch is not installed when trying to load a .safetensors file or a PyTorch checkpoint respectively.</li>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#ValueError"
  rel="nofollow"
><code>ValueError</code></a> —
If the checkpoint path is invalid or if the checkpoint format cannot be determined.</li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>FileNotFoundError</code> or <code>ImportError</code> or <code>ValueError</code></p>
`}}),Ze=new se({props:{anchor:"huggingface_hub.load_torch_model.example",$$slots:{default:[Lo]},$$scope:{ctx:$}}}),Mt=new I({props:{title:"load_state_dict_from_file",local:"huggingface_hub.load_state_dict_from_file",headingTag:"h3"}}),jt=new G({props:{name:"huggingface_hub.load_state_dict_from_file",anchor:"huggingface_hub.load_state_dict_from_file",parameters:[{name:"checkpoint_file",val:": typing.Union[str, os.PathLike]"},{name:"map_location",val:": typing.Union[str, ForwardRef('torch.device'), NoneType] = None"},{name:"weights_only",val:": bool = False"},{name:"mmap",val:": bool = False"}],parametersDescription:[{anchor:"huggingface_hub.load_state_dict_from_file.checkpoint_file",description:`<strong>checkpoint_file</strong> (<code>str</code> or <code>os.PathLike</code>) &#x2014;
Path to the checkpoint file to load. Can be either a safetensors or pickle (<code>.bin</code>) checkpoint.`,name:"checkpoint_file"},{anchor:"huggingface_hub.load_state_dict_from_file.map_location",description:`<strong>map_location</strong> (<code>str</code> or <code>torch.device</code>, <em>optional</em>) &#x2014;
A <code>torch.device</code> object, string or a dict specifying how to remap storage locations. It
indicates the location where all tensors should be loaded.`,name:"map_location"},{anchor:"huggingface_hub.load_state_dict_from_file.weights_only",description:`<strong>weights_only</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
If True, only loads the model weights without optimizer states and other metadata.
Only supported for pickle (<code>.bin</code>) checkpoints with PyTorch &gt;= 1.13. Has no effect when
loading safetensors files.`,name:"weights_only"},{anchor:"huggingface_hub.load_state_dict_from_file.mmap",description:`<strong>mmap</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use memory-mapped file loading. Memory mapping can improve loading performance
for large models in PyTorch &gt;= 2.1.0 with zipfile-based checkpoints. Has no effect when
loading safetensors files, as the <code>safetensors</code> library uses memory mapping by default.`,name:"mmap"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L558",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>The loaded checkpoint.</p>
<ul>
<li>For safetensors files: always returns a dictionary mapping parameter names to tensors.</li>
<li>For pickle files: returns any Python object that was pickled (commonly a state dict, but could be
an entire model, optimizer state, or any other Python object).</li>
</ul>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>Union[Dict[str, "torch.Tensor"], Any]</code></p>
`,raiseDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<ul>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#FileNotFoundError"
  rel="nofollow"
><code>FileNotFoundError</code></a> —
If the checkpoint file does not exist.</li>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#ImportError"
  rel="nofollow"
><code>ImportError</code></a> —
If safetensors or torch is not installed when trying to load a .safetensors file or a PyTorch checkpoint respectively.</li>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#OSError"
  rel="nofollow"
><code>OSError</code></a> —
If the checkpoint file format is invalid or if git-lfs files are not properly downloaded.</li>
<li><a
  href="https://docs.python.org/3/library/exceptions.html#ValueError"
  rel="nofollow"
><code>ValueError</code></a> —
If the checkpoint file path is empty or invalid.</li>
</ul>
`,raiseType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>FileNotFoundError</code> or <code>ImportError</code> or <code>OSError</code> or <code>ValueError</code></p>
`}}),ke=new se({props:{anchor:"huggingface_hub.load_state_dict_from_file.example",$$slots:{default:[No]},$$scope:{ctx:$}}}),wt=new I({props:{title:"Tensors helpers",local:"tensors-helpers",headingTag:"h2"}}),$t=new I({props:{title:"get_torch_storage_id",local:"huggingface_hub.get_torch_storage_id",headingTag:"h3"}}),vt=new G({props:{name:"huggingface_hub.get_torch_storage_id",anchor:"huggingface_hub.get_torch_storage_id",parameters:[{name:"tensor",val:": torch.Tensor"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L744"}}),Tt=new I({props:{title:"get_torch_storage_size",local:"huggingface_hub.get_torch_storage_size",headingTag:"h3"}}),xt=new G({props:{name:"huggingface_hub.get_torch_storage_size",anchor:"huggingface_hub.get_torch_storage_size",parameters:[{name:"tensor",val:": torch.Tensor"}],source:"https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/serialization/_torch.py#L761"}}),Ut=new vo({props:{source:"https://github.com/huggingface/huggingface_hub/blob/main/docs/source/en/package_reference/serialization.md"}}),{c(){t=p("meta"),M=o(),r=p("p"),c=o(),m(j.$$.fragment),s=o(),w=p("p"),w.innerHTML=wn,ys=o(),m(Ge.$$.fragment),bs=o(),Ie=p("p"),Ie.innerHTML=$n,Ms=o(),m(pe.$$.fragment),js=o(),m(Ce.$$.fragment),ws=o(),Re=p("p"),Re.innerHTML=vn,$s=o(),m(Be.$$.fragment),vs=o(),We=p("p"),We.innerHTML=Tn,Ts=o(),m(ze.$$.fragment),xs=o(),Fe=p("p"),Fe.innerHTML=xn,Us=o(),m(De.$$.fragment),Js=o(),Ee=p("p"),Ee.innerHTML=Un,Zs=o(),m(Ve.$$.fragment),ks=o(),m(Xe.$$.fragment),Gs=o(),m(Le.$$.fragment),Is=o(),R=p("div"),m(Ne.$$.fragment),ua=o(),Ct=p("p"),Ct.textContent=Jn,_a=o(),Rt=p("p"),Rt.innerHTML=Zn,ya=o(),m(he.$$.fragment),ba=o(),m(me.$$.fragment),Cs=o(),F=p("div"),m(Ae.$$.fragment),Ma=o(),Bt=p("p"),Bt.textContent=kn,ja=o(),Wt=p("p"),Wt.innerHTML=Gn,wa=o(),m(fe.$$.fragment),Rs=o(),D=p("div"),m(Se.$$.fragment),$a=o(),zt=p("p"),zt.textContent=In,va=o(),Ft=p("p"),Ft.textContent=Cn,Ta=o(),m(ge.$$.fragment),Bs=o(),B=p("div"),m(He.$$.fragment),xa=o(),Dt=p("p"),Dt.textContent=Rn,Ua=o(),Et=p("p"),Et.innerHTML=Bn,Ja=o(),A=p("div"),m(Ye.$$.fragment),Za=o(),Vt=p("p"),Vt.textContent=Wn,ka=o(),Xt=p("p"),Xt.textContent=zn,Ga=o(),m(ue.$$.fragment),Ia=o(),S=p("div"),m(qe.$$.fragment),Ca=o(),Lt=p("p"),Lt.textContent=Fn,Ra=o(),Nt=p("p"),Nt.textContent=Dn,Ba=o(),m(_e.$$.fragment),Ws=o(),m(Pe.$$.fragment),zs=o(),ae=p("div"),m(Qe.$$.fragment),Wa=o(),At=p("p"),At.textContent=En,Fs=o(),ne=p("div"),m(Ke.$$.fragment),za=o(),St=p("p"),St.textContent=Vn,Ds=o(),oe=p("div"),m(Oe.$$.fragment),Fa=o(),Ht=p("p"),Ht.textContent=Xn,Es=o(),le=p("div"),m(et.$$.fragment),Da=o(),Yt=p("p"),Yt.textContent=Ln,Vs=o(),m(tt.$$.fragment),Xs=o(),st=p("p"),st.innerHTML=Nn,Ls=o(),at=p("p"),at.innerHTML=An,Ns=o(),m(nt.$$.fragment),As=o(),v=p("div"),m(ot.$$.fragment),Ea=o(),qt=p("p"),qt.textContent=Sn,Va=o(),Pt=p("p"),Pt.innerHTML=Hn,Xa=o(),Qt=p("p"),Qt.innerHTML=Yn,La=o(),Kt=p("p"),Kt.innerHTML=qn,Na=o(),Ot=p("p"),Ot.innerHTML=Pn,Aa=o(),m(ye.$$.fragment),Sa=o(),m(be.$$.fragment),Ha=o(),m(Me.$$.fragment),Ss=o(),m(lt.$$.fragment),Hs=o(),T=p("div"),m(rt.$$.fragment),Ya=o(),es=p("p"),es.textContent=Qn,qa=o(),ts=p("p"),ts.innerHTML=Kn,Pa=o(),ss=p("p"),ss.innerHTML=On,Qa=o(),as=p("p"),as.innerHTML=eo,Ka=o(),ns=p("p"),ns.innerHTML=to,Oa=o(),m(je.$$.fragment),en=o(),m(we.$$.fragment),tn=o(),m($e.$$.fragment),Ys=o(),it=p("p"),it.innerHTML=so,qs=o(),m(ct.$$.fragment),Ps=o(),E=p("div"),m(dt.$$.fragment),sn=o(),os=p("p"),os.textContent=ao,an=o(),ls=p("p"),ls.innerHTML=no,nn=o(),m(ve.$$.fragment),Qs=o(),m(pt.$$.fragment),Ks=o(),C=p("div"),m(ht.$$.fragment),on=o(),rs=p("p"),rs.textContent=oo,ln=o(),is=p("p"),is.innerHTML=lo,rn=o(),m(Te.$$.fragment),cn=o(),m(xe.$$.fragment),dn=o(),m(Ue.$$.fragment),Os=o(),m(mt.$$.fragment),ea=o(),ft=p("p"),ft.innerHTML=ro,ta=o(),V=p("div"),m(gt.$$.fragment),pn=o(),cs=p("p"),cs.textContent=io,hn=o(),ds=p("p"),ds.innerHTML=co,mn=o(),m(Je.$$.fragment),sa=o(),m(ut.$$.fragment),aa=o(),_t=p("p"),_t.innerHTML=po,na=o(),m(yt.$$.fragment),oa=o(),H=p("div"),m(bt.$$.fragment),fn=o(),ps=p("p"),ps.textContent=ho,gn=o(),m(Ze.$$.fragment),la=o(),m(Mt.$$.fragment),ra=o(),Y=p("div"),m(jt.$$.fragment),un=o(),hs=p("p"),hs.textContent=mo,_n=o(),m(ke.$$.fragment),ia=o(),m(wt.$$.fragment),ca=o(),m($t.$$.fragment),da=o(),X=p("div"),m(vt.$$.fragment),yn=o(),ms=p("p"),ms.textContent=fo,bn=o(),fs=p("p"),fs.textContent=go,Mn=o(),gs=p("p"),gs.innerHTML=uo,pa=o(),m(Tt.$$.fragment),ha=o(),re=p("div"),m(xt.$$.fragment),jn=o(),us=p("p"),us.innerHTML=_o,ma=o(),m(Ut.$$.fragment),fa=o(),_s=p("p"),this.h()},l(e){const a=$o("svelte-u9bgzb",document.head);t=h(a,"META",{name:!0,content:!0}),a.forEach(n),M=l(e),r=h(e,"P",{}),J(r).forEach(n),c=l(e),f(j.$$.fragment,e),s=l(e),w=h(e,"P",{"data-svelte-h":!0}),b(w)!=="svelte-8n5thw"&&(w.innerHTML=wn),ys=l(e),f(Ge.$$.fragment,e),bs=l(e),Ie=h(e,"P",{"data-svelte-h":!0}),b(Ie)!=="svelte-76eyi"&&(Ie.innerHTML=$n),Ms=l(e),f(pe.$$.fragment,e),js=l(e),f(Ce.$$.fragment,e),ws=l(e),Re=h(e,"P",{"data-svelte-h":!0}),b(Re)!=="svelte-wjz0ef"&&(Re.innerHTML=vn),$s=l(e),f(Be.$$.fragment,e),vs=l(e),We=h(e,"P",{"data-svelte-h":!0}),b(We)!=="svelte-94wwhy"&&(We.innerHTML=Tn),Ts=l(e),f(ze.$$.fragment,e),xs=l(e),Fe=h(e,"P",{"data-svelte-h":!0}),b(Fe)!=="svelte-10ghbb4"&&(Fe.innerHTML=xn),Us=l(e),f(De.$$.fragment,e),Js=l(e),Ee=h(e,"P",{"data-svelte-h":!0}),b(Ee)!=="svelte-1ia72u1"&&(Ee.innerHTML=Un),Zs=l(e),f(Ve.$$.fragment,e),ks=l(e),f(Xe.$$.fragment,e),Gs=l(e),f(Le.$$.fragment,e),Is=l(e),R=h(e,"DIV",{class:!0});var L=J(R);f(Ne.$$.fragment,L),ua=l(L),Ct=h(L,"P",{"data-svelte-h":!0}),b(Ct)!=="svelte-13au33d"&&(Ct.textContent=Jn),_a=l(L),Rt=h(L,"P",{"data-svelte-h":!0}),b(Rt)!=="svelte-7i3cxt"&&(Rt.innerHTML=Zn),ya=l(L),f(he.$$.fragment,L),ba=l(L),f(me.$$.fragment,L),L.forEach(n),Cs=l(e),F=h(e,"DIV",{class:!0});var q=J(F);f(Ae.$$.fragment,q),Ma=l(q),Bt=h(q,"P",{"data-svelte-h":!0}),b(Bt)!=="svelte-1spqaxd"&&(Bt.textContent=kn),ja=l(q),Wt=h(q,"P",{"data-svelte-h":!0}),b(Wt)!=="svelte-1zandc"&&(Wt.innerHTML=Gn),wa=l(q),f(fe.$$.fragment,q),q.forEach(n),Rs=l(e),D=h(e,"DIV",{class:!0});var P=J(D);f(Se.$$.fragment,P),$a=l(P),zt=h(P,"P",{"data-svelte-h":!0}),b(zt)!=="svelte-wslvoh"&&(zt.textContent=In),va=l(P),Ft=h(P,"P",{"data-svelte-h":!0}),b(Ft)!=="svelte-1jossqp"&&(Ft.textContent=Cn),Ta=l(P),f(ge.$$.fragment,P),P.forEach(n),Bs=l(e),B=h(e,"DIV",{class:!0});var N=J(B);f(He.$$.fragment,N),xa=l(N),Dt=h(N,"P",{"data-svelte-h":!0}),b(Dt)!=="svelte-16rzygd"&&(Dt.textContent=Rn),Ua=l(N),Et=h(N,"P",{"data-svelte-h":!0}),b(Et)!=="svelte-pnh06h"&&(Et.innerHTML=Bn),Ja=l(N),A=h(N,"DIV",{class:!0});var Q=J(A);f(Ye.$$.fragment,Q),Za=l(Q),Vt=h(Q,"P",{"data-svelte-h":!0}),b(Vt)!=="svelte-mrui81"&&(Vt.textContent=Wn),ka=l(Q),Xt=h(Q,"P",{"data-svelte-h":!0}),b(Xt)!=="svelte-mr7gff"&&(Xt.textContent=zn),Ga=l(Q),f(ue.$$.fragment,Q),Q.forEach(n),Ia=l(N),S=h(N,"DIV",{class:!0});var K=J(S);f(qe.$$.fragment,K),Ca=l(K),Lt=h(K,"P",{"data-svelte-h":!0}),b(Lt)!=="svelte-6ka7ei"&&(Lt.textContent=Fn),Ra=l(K),Nt=h(K,"P",{"data-svelte-h":!0}),b(Nt)!=="svelte-1s7wtva"&&(Nt.textContent=Dn),Ba=l(K),f(_e.$$.fragment,K),K.forEach(n),N.forEach(n),Ws=l(e),f(Pe.$$.fragment,e),zs=l(e),ae=h(e,"DIV",{class:!0});var Jt=J(ae);f(Qe.$$.fragment,Jt),Wa=l(Jt),At=h(Jt,"P",{"data-svelte-h":!0}),b(At)!=="svelte-bujp1z"&&(At.textContent=En),Jt.forEach(n),Fs=l(e),ne=h(e,"DIV",{class:!0});var Zt=J(ne);f(Ke.$$.fragment,Zt),za=l(Zt),St=h(Zt,"P",{"data-svelte-h":!0}),b(St)!=="svelte-76lsj1"&&(St.textContent=Vn),Zt.forEach(n),Ds=l(e),oe=h(e,"DIV",{class:!0});var kt=J(oe);f(Oe.$$.fragment,kt),Fa=l(kt),Ht=h(kt,"P",{"data-svelte-h":!0}),b(Ht)!=="svelte-1540kbq"&&(Ht.textContent=Xn),kt.forEach(n),Es=l(e),le=h(e,"DIV",{class:!0});var Gt=J(le);f(et.$$.fragment,Gt),Da=l(Gt),Yt=h(Gt,"P",{"data-svelte-h":!0}),b(Yt)!=="svelte-18paw2o"&&(Yt.textContent=Ln),Gt.forEach(n),Vs=l(e),f(tt.$$.fragment,e),Xs=l(e),st=h(e,"P",{"data-svelte-h":!0}),b(st)!=="svelte-1gnm445"&&(st.innerHTML=Nn),Ls=l(e),at=h(e,"P",{"data-svelte-h":!0}),b(at)!=="svelte-1mocwb"&&(at.innerHTML=An),Ns=l(e),f(nt.$$.fragment,e),As=l(e),v=h(e,"DIV",{class:!0});var x=J(v);f(ot.$$.fragment,x),Ea=l(x),qt=h(x,"P",{"data-svelte-h":!0}),b(qt)!=="svelte-ts5jcq"&&(qt.textContent=Sn),Va=l(x),Pt=h(x,"P",{"data-svelte-h":!0}),b(Pt)!=="svelte-12jpcei"&&(Pt.innerHTML=Hn),Xa=l(x),Qt=h(x,"P",{"data-svelte-h":!0}),b(Qt)!=="svelte-hxbjn2"&&(Qt.innerHTML=Yn),La=l(x),Kt=h(x,"P",{"data-svelte-h":!0}),b(Kt)!=="svelte-b08cux"&&(Kt.innerHTML=qn),Na=l(x),Ot=h(x,"P",{"data-svelte-h":!0}),b(Ot)!=="svelte-zotpm4"&&(Ot.innerHTML=Pn),Aa=l(x),f(ye.$$.fragment,x),Sa=l(x),f(be.$$.fragment,x),Ha=l(x),f(Me.$$.fragment,x),x.forEach(n),Ss=l(e),f(lt.$$.fragment,e),Hs=l(e),T=h(e,"DIV",{class:!0});var U=J(T);f(rt.$$.fragment,U),Ya=l(U),es=h(U,"P",{"data-svelte-h":!0}),b(es)!=="svelte-1hwpwyy"&&(es.textContent=Qn),qa=l(U),ts=h(U,"P",{"data-svelte-h":!0}),b(ts)!=="svelte-1sy8rkx"&&(ts.innerHTML=Kn),Pa=l(U),ss=h(U,"P",{"data-svelte-h":!0}),b(ss)!=="svelte-hxbjn2"&&(ss.innerHTML=On),Qa=l(U),as=h(U,"P",{"data-svelte-h":!0}),b(as)!=="svelte-b08cux"&&(as.innerHTML=eo),Ka=l(U),ns=h(U,"P",{"data-svelte-h":!0}),b(ns)!=="svelte-zotpm4"&&(ns.innerHTML=to),Oa=l(U),f(je.$$.fragment,U),en=l(U),f(we.$$.fragment,U),tn=l(U),f($e.$$.fragment,U),U.forEach(n),Ys=l(e),it=h(e,"P",{"data-svelte-h":!0}),b(it)!=="svelte-1jvx2r9"&&(it.innerHTML=so),qs=l(e),f(ct.$$.fragment,e),Ps=l(e),E=h(e,"DIV",{class:!0});var O=J(E);f(dt.$$.fragment,O),sn=l(O),os=h(O,"P",{"data-svelte-h":!0}),b(os)!=="svelte-1q1pe7b"&&(os.textContent=ao),an=l(O),ls=h(O,"P",{"data-svelte-h":!0}),b(ls)!=="svelte-17rio2z"&&(ls.innerHTML=no),nn=l(O),f(ve.$$.fragment,O),O.forEach(n),Qs=l(e),f(pt.$$.fragment,e),Ks=l(e),C=h(e,"DIV",{class:!0});var W=J(C);f(ht.$$.fragment,W),on=l(W),rs=h(W,"P",{"data-svelte-h":!0}),b(rs)!=="svelte-1q1pe7b"&&(rs.textContent=oo),ln=l(W),is=h(W,"P",{"data-svelte-h":!0}),b(is)!=="svelte-17rio2z"&&(is.innerHTML=lo),rn=l(W),f(Te.$$.fragment,W),cn=l(W),f(xe.$$.fragment,W),dn=l(W),f(Ue.$$.fragment,W),W.forEach(n),Os=l(e),f(mt.$$.fragment,e),ea=l(e),ft=h(e,"P",{"data-svelte-h":!0}),b(ft)!=="svelte-1hva642"&&(ft.innerHTML=ro),ta=l(e),V=h(e,"DIV",{class:!0});var ee=J(V);f(gt.$$.fragment,ee),pn=l(ee),cs=h(ee,"P",{"data-svelte-h":!0}),b(cs)!=="svelte-1q1pe7b"&&(cs.textContent=io),hn=l(ee),ds=h(ee,"P",{"data-svelte-h":!0}),b(ds)!=="svelte-17rio2z"&&(ds.innerHTML=co),mn=l(ee),f(Je.$$.fragment,ee),ee.forEach(n),sa=l(e),f(ut.$$.fragment,e),aa=l(e),_t=h(e,"P",{"data-svelte-h":!0}),b(_t)!=="svelte-1vzkkqp"&&(_t.innerHTML=po),na=l(e),f(yt.$$.fragment,e),oa=l(e),H=h(e,"DIV",{class:!0});var ie=J(H);f(bt.$$.fragment,ie),fn=l(ie),ps=h(ie,"P",{"data-svelte-h":!0}),b(ps)!=="svelte-qwh3fh"&&(ps.textContent=ho),gn=l(ie),f(Ze.$$.fragment,ie),ie.forEach(n),la=l(e),f(Mt.$$.fragment,e),ra=l(e),Y=h(e,"DIV",{class:!0});var ce=J(Y);f(jt.$$.fragment,ce),un=l(ce),hs=h(ce,"P",{"data-svelte-h":!0}),b(hs)!=="svelte-1mudbss"&&(hs.textContent=mo),_n=l(ce),f(ke.$$.fragment,ce),ce.forEach(n),ia=l(e),f(wt.$$.fragment,e),ca=l(e),f($t.$$.fragment,e),da=l(e),X=h(e,"DIV",{class:!0});var te=J(X);f(vt.$$.fragment,te),yn=l(te),ms=h(te,"P",{"data-svelte-h":!0}),b(ms)!=="svelte-lfv2l4"&&(ms.textContent=fo),bn=l(te),fs=h(te,"P",{"data-svelte-h":!0}),b(fs)!=="svelte-1o86t9o"&&(fs.textContent=go),Mn=l(te),gs=h(te,"P",{"data-svelte-h":!0}),b(gs)!=="svelte-akggeo"&&(gs.innerHTML=uo),te.forEach(n),pa=l(e),f(Tt.$$.fragment,e),ha=l(e),re=h(e,"DIV",{class:!0});var It=J(re);f(xt.$$.fragment,It),jn=l(It),us=h(It,"P",{"data-svelte-h":!0}),b(us)!=="svelte-1ey7lf2"&&(us.innerHTML=_o),It.forEach(n),ma=l(e),f(Ut.$$.fragment,e),fa=l(e),_s=h(e,"P",{}),J(_s).forEach(n),this.h()},h(){Z(t,"name","hf:doc:metadata"),Z(t,"content",So),Z(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(D,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(B,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(ae,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(ne,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(oe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(le,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(H,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(Y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(re,"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,a){d(document.head,t),i(e,M,a),i(e,r,a),i(e,c,a),g(j,e,a),i(e,s,a),i(e,w,a),i(e,ys,a),g(Ge,e,a),i(e,bs,a),i(e,Ie,a),i(e,Ms,a),g(pe,e,a),i(e,js,a),g(Ce,e,a),i(e,ws,a),i(e,Re,a),i(e,$s,a),g(Be,e,a),i(e,vs,a),i(e,We,a),i(e,Ts,a),g(ze,e,a),i(e,xs,a),i(e,Fe,a),i(e,Us,a),g(De,e,a),i(e,Js,a),i(e,Ee,a),i(e,Zs,a),g(Ve,e,a),i(e,ks,a),g(Xe,e,a),i(e,Gs,a),g(Le,e,a),i(e,Is,a),i(e,R,a),g(Ne,R,null),d(R,ua),d(R,Ct),d(R,_a),d(R,Rt),d(R,ya),g(he,R,null),d(R,ba),g(me,R,null),i(e,Cs,a),i(e,F,a),g(Ae,F,null),d(F,Ma),d(F,Bt),d(F,ja),d(F,Wt),d(F,wa),g(fe,F,null),i(e,Rs,a),i(e,D,a),g(Se,D,null),d(D,$a),d(D,zt),d(D,va),d(D,Ft),d(D,Ta),g(ge,D,null),i(e,Bs,a),i(e,B,a),g(He,B,null),d(B,xa),d(B,Dt),d(B,Ua),d(B,Et),d(B,Ja),d(B,A),g(Ye,A,null),d(A,Za),d(A,Vt),d(A,ka),d(A,Xt),d(A,Ga),g(ue,A,null),d(B,Ia),d(B,S),g(qe,S,null),d(S,Ca),d(S,Lt),d(S,Ra),d(S,Nt),d(S,Ba),g(_e,S,null),i(e,Ws,a),g(Pe,e,a),i(e,zs,a),i(e,ae,a),g(Qe,ae,null),d(ae,Wa),d(ae,At),i(e,Fs,a),i(e,ne,a),g(Ke,ne,null),d(ne,za),d(ne,St),i(e,Ds,a),i(e,oe,a),g(Oe,oe,null),d(oe,Fa),d(oe,Ht),i(e,Es,a),i(e,le,a),g(et,le,null),d(le,Da),d(le,Yt),i(e,Vs,a),g(tt,e,a),i(e,Xs,a),i(e,st,a),i(e,Ls,a),i(e,at,a),i(e,Ns,a),g(nt,e,a),i(e,As,a),i(e,v,a),g(ot,v,null),d(v,Ea),d(v,qt),d(v,Va),d(v,Pt),d(v,Xa),d(v,Qt),d(v,La),d(v,Kt),d(v,Na),d(v,Ot),d(v,Aa),g(ye,v,null),d(v,Sa),g(be,v,null),d(v,Ha),g(Me,v,null),i(e,Ss,a),g(lt,e,a),i(e,Hs,a),i(e,T,a),g(rt,T,null),d(T,Ya),d(T,es),d(T,qa),d(T,ts),d(T,Pa),d(T,ss),d(T,Qa),d(T,as),d(T,Ka),d(T,ns),d(T,Oa),g(je,T,null),d(T,en),g(we,T,null),d(T,tn),g($e,T,null),i(e,Ys,a),i(e,it,a),i(e,qs,a),g(ct,e,a),i(e,Ps,a),i(e,E,a),g(dt,E,null),d(E,sn),d(E,os),d(E,an),d(E,ls),d(E,nn),g(ve,E,null),i(e,Qs,a),g(pt,e,a),i(e,Ks,a),i(e,C,a),g(ht,C,null),d(C,on),d(C,rs),d(C,ln),d(C,is),d(C,rn),g(Te,C,null),d(C,cn),g(xe,C,null),d(C,dn),g(Ue,C,null),i(e,Os,a),g(mt,e,a),i(e,ea,a),i(e,ft,a),i(e,ta,a),i(e,V,a),g(gt,V,null),d(V,pn),d(V,cs),d(V,hn),d(V,ds),d(V,mn),g(Je,V,null),i(e,sa,a),g(ut,e,a),i(e,aa,a),i(e,_t,a),i(e,na,a),g(yt,e,a),i(e,oa,a),i(e,H,a),g(bt,H,null),d(H,fn),d(H,ps),d(H,gn),g(Ze,H,null),i(e,la,a),g(Mt,e,a),i(e,ra,a),i(e,Y,a),g(jt,Y,null),d(Y,un),d(Y,hs),d(Y,_n),g(ke,Y,null),i(e,ia,a),g(wt,e,a),i(e,ca,a),g($t,e,a),i(e,da,a),i(e,X,a),g(vt,X,null),d(X,yn),d(X,ms),d(X,bn),d(X,fs),d(X,Mn),d(X,gs),i(e,pa,a),g(Tt,e,a),i(e,ha,a),i(e,re,a),g(xt,re,null),d(re,jn),d(re,us),i(e,ma,a),g(Ut,e,a),i(e,fa,a),i(e,_s,a),ga=!0},p(e,[a]){const L={};a&2&&(L.$$scope={dirty:a,ctx:e}),pe.$set(L);const q={};a&2&&(q.$$scope={dirty:a,ctx:e}),he.$set(q);const P={};a&2&&(P.$$scope={dirty:a,ctx:e}),me.$set(P);const N={};a&2&&(N.$$scope={dirty:a,ctx:e}),fe.$set(N);const Q={};a&2&&(Q.$$scope={dirty:a,ctx:e}),ge.$set(Q);const K={};a&2&&(K.$$scope={dirty:a,ctx:e}),ue.$set(K);const Jt={};a&2&&(Jt.$$scope={dirty:a,ctx:e}),_e.$set(Jt);const Zt={};a&2&&(Zt.$$scope={dirty:a,ctx:e}),ye.$set(Zt);const kt={};a&2&&(kt.$$scope={dirty:a,ctx:e}),be.$set(kt);const Gt={};a&2&&(Gt.$$scope={dirty:a,ctx:e}),Me.$set(Gt);const x={};a&2&&(x.$$scope={dirty:a,ctx:e}),je.$set(x);const U={};a&2&&(U.$$scope={dirty:a,ctx:e}),we.$set(U);const O={};a&2&&(O.$$scope={dirty:a,ctx:e}),$e.$set(O);const W={};a&2&&(W.$$scope={dirty:a,ctx:e}),ve.$set(W);const ee={};a&2&&(ee.$$scope={dirty:a,ctx:e}),Te.$set(ee);const ie={};a&2&&(ie.$$scope={dirty:a,ctx:e}),xe.$set(ie);const ce={};a&2&&(ce.$$scope={dirty:a,ctx:e}),Ue.$set(ce);const te={};a&2&&(te.$$scope={dirty:a,ctx:e}),Je.$set(te);const It={};a&2&&(It.$$scope={dirty:a,ctx:e}),Ze.$set(It);const yo={};a&2&&(yo.$$scope={dirty:a,ctx:e}),ke.$set(yo)},i(e){ga||(u(j.$$.fragment,e),u(Ge.$$.fragment,e),u(pe.$$.fragment,e),u(Ce.$$.fragment,e),u(Be.$$.fragment,e),u(ze.$$.fragment,e),u(De.$$.fragment,e),u(Ve.$$.fragment,e),u(Xe.$$.fragment,e),u(Le.$$.fragment,e),u(Ne.$$.fragment,e),u(he.$$.fragment,e),u(me.$$.fragment,e),u(Ae.$$.fragment,e),u(fe.$$.fragment,e),u(Se.$$.fragment,e),u(ge.$$.fragment,e),u(He.$$.fragment,e),u(Ye.$$.fragment,e),u(ue.$$.fragment,e),u(qe.$$.fragment,e),u(_e.$$.fragment,e),u(Pe.$$.fragment,e),u(Qe.$$.fragment,e),u(Ke.$$.fragment,e),u(Oe.$$.fragment,e),u(et.$$.fragment,e),u(tt.$$.fragment,e),u(nt.$$.fragment,e),u(ot.$$.fragment,e),u(ye.$$.fragment,e),u(be.$$.fragment,e),u(Me.$$.fragment,e),u(lt.$$.fragment,e),u(rt.$$.fragment,e),u(je.$$.fragment,e),u(we.$$.fragment,e),u($e.$$.fragment,e),u(ct.$$.fragment,e),u(dt.$$.fragment,e),u(ve.$$.fragment,e),u(pt.$$.fragment,e),u(ht.$$.fragment,e),u(Te.$$.fragment,e),u(xe.$$.fragment,e),u(Ue.$$.fragment,e),u(mt.$$.fragment,e),u(gt.$$.fragment,e),u(Je.$$.fragment,e),u(ut.$$.fragment,e),u(yt.$$.fragment,e),u(bt.$$.fragment,e),u(Ze.$$.fragment,e),u(Mt.$$.fragment,e),u(jt.$$.fragment,e),u(ke.$$.fragment,e),u(wt.$$.fragment,e),u($t.$$.fragment,e),u(vt.$$.fragment,e),u(Tt.$$.fragment,e),u(xt.$$.fragment,e),u(Ut.$$.fragment,e),ga=!0)},o(e){_(j.$$.fragment,e),_(Ge.$$.fragment,e),_(pe.$$.fragment,e),_(Ce.$$.fragment,e),_(Be.$$.fragment,e),_(ze.$$.fragment,e),_(De.$$.fragment,e),_(Ve.$$.fragment,e),_(Xe.$$.fragment,e),_(Le.$$.fragment,e),_(Ne.$$.fragment,e),_(he.$$.fragment,e),_(me.$$.fragment,e),_(Ae.$$.fragment,e),_(fe.$$.fragment,e),_(Se.$$.fragment,e),_(ge.$$.fragment,e),_(He.$$.fragment,e),_(Ye.$$.fragment,e),_(ue.$$.fragment,e),_(qe.$$.fragment,e),_(_e.$$.fragment,e),_(Pe.$$.fragment,e),_(Qe.$$.fragment,e),_(Ke.$$.fragment,e),_(Oe.$$.fragment,e),_(et.$$.fragment,e),_(tt.$$.fragment,e),_(nt.$$.fragment,e),_(ot.$$.fragment,e),_(ye.$$.fragment,e),_(be.$$.fragment,e),_(Me.$$.fragment,e),_(lt.$$.fragment,e),_(rt.$$.fragment,e),_(je.$$.fragment,e),_(we.$$.fragment,e),_($e.$$.fragment,e),_(ct.$$.fragment,e),_(dt.$$.fragment,e),_(ve.$$.fragment,e),_(pt.$$.fragment,e),_(ht.$$.fragment,e),_(Te.$$.fragment,e),_(xe.$$.fragment,e),_(Ue.$$.fragment,e),_(mt.$$.fragment,e),_(gt.$$.fragment,e),_(Je.$$.fragment,e),_(ut.$$.fragment,e),_(yt.$$.fragment,e),_(bt.$$.fragment,e),_(Ze.$$.fragment,e),_(Mt.$$.fragment,e),_(jt.$$.fragment,e),_(ke.$$.fragment,e),_(wt.$$.fragment,e),_($t.$$.fragment,e),_(vt.$$.fragment,e),_(Tt.$$.fragment,e),_(xt.$$.fragment,e),_(Ut.$$.fragment,e),ga=!1},d(e){e&&(n(M),n(r),n(c),n(s),n(w),n(ys),n(bs),n(Ie),n(Ms),n(js),n(ws),n(Re),n($s),n(vs),n(We),n(Ts),n(xs),n(Fe),n(Us),n(Js),n(Ee),n(Zs),n(ks),n(Gs),n(Is),n(R),n(Cs),n(F),n(Rs),n(D),n(Bs),n(B),n(Ws),n(zs),n(ae),n(Fs),n(ne),n(Ds),n(oe),n(Es),n(le),n(Vs),n(Xs),n(st),n(Ls),n(at),n(Ns),n(As),n(v),n(Ss),n(Hs),n(T),n(Ys),n(it),n(qs),n(Ps),n(E),n(Qs),n(Ks),n(C),n(Os),n(ea),n(ft),n(ta),n(V),n(sa),n(aa),n(_t),n(na),n(oa),n(H),n(la),n(ra),n(Y),n(ia),n(ca),n(da),n(X),n(pa),n(ha),n(re),n(ma),n(fa),n(_s)),n(t),y(j,e),y(Ge,e),y(pe,e),y(Ce,e),y(Be,e),y(ze,e),y(De,e),y(Ve,e),y(Xe,e),y(Le,e),y(Ne),y(he),y(me),y(Ae),y(fe),y(Se),y(ge),y(He),y(Ye),y(ue),y(qe),y(_e),y(Pe,e),y(Qe),y(Ke),y(Oe),y(et),y(tt,e),y(nt,e),y(ot),y(ye),y(be),y(Me),y(lt,e),y(rt),y(je),y(we),y($e),y(ct,e),y(dt),y(ve),y(pt,e),y(ht),y(Te),y(xe),y(Ue),y(mt,e),y(gt),y(Je),y(ut,e),y(yt,e),y(bt),y(Ze),y(Mt,e),y(jt),y(ke),y(wt,e),y($t,e),y(vt),y(Tt,e),y(xt),y(Ut,e)}}}const So='{"title":"Serialization","local":"serialization","sections":[{"title":"DDUF file format","local":"dduf-file-format","sections":[{"title":"How to write a DDUF file?","local":"how-to-write-a-dduf-file","sections":[],"depth":3},{"title":"How to read a DDUF file?","local":"how-to-read-a-dduf-file","sections":[],"depth":3},{"title":"Helpers","local":"huggingface_hub.export_entries_as_dduf","sections":[],"depth":3},{"title":"Errors","local":"huggingface_hub.errors.DDUFError","sections":[],"depth":3}],"depth":2},{"title":"Saving tensors","local":"saving-tensors","sections":[{"title":"save_torch_model","local":"huggingface_hub.save_torch_model","sections":[],"depth":3},{"title":"save_torch_state_dict","local":"huggingface_hub.save_torch_state_dict","sections":[],"depth":3},{"title":"split_tf_state_dict_into_shards","local":"huggingface_hub.split_tf_state_dict_into_shards","sections":[],"depth":3},{"title":"split_torch_state_dict_into_shards","local":"huggingface_hub.split_torch_state_dict_into_shards","sections":[],"depth":3},{"title":"split_state_dict_into_shards_factory","local":"huggingface_hub.split_state_dict_into_shards_factory","sections":[],"depth":3}],"depth":2},{"title":"Loading tensors","local":"loading-tensors","sections":[{"title":"load_torch_model","local":"huggingface_hub.load_torch_model","sections":[],"depth":3},{"title":"load_state_dict_from_file","local":"huggingface_hub.load_state_dict_from_file","sections":[],"depth":3}],"depth":2},{"title":"Tensors helpers","local":"tensors-helpers","sections":[{"title":"get_torch_storage_id","local":"huggingface_hub.get_torch_storage_id","sections":[],"depth":3},{"title":"get_torch_storage_size","local":"huggingface_hub.get_torch_storage_size","sections":[],"depth":3}],"depth":2}],"depth":1}';function Ho($){return Mo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class tl extends jo{constructor(t){super(),wo(this,t,Ho,Ao,bo,{})}}export{tl as component};
