import{s as mo,o as go,n as K}from"../chunks/scheduler.0cf4ef2e.js";import{S as fo,i as uo,e as d,s as n,c as g,h as _o,a as p,d as a,b as o,f as J,g as f,j as m,k as v,l as r,m as l,n as u,t as _,o as y,p as b}from"../chunks/index.abc433bf.js";import{C as yo}from"../chunks/CopyLLMTxtMenu.efc6b005.js";import{D as k}from"../chunks/Docstring.e4170f41.js";import{C as W}from"../chunks/CodeBlock.00dcd05e.js";import{E as P}from"../chunks/ExampleCodeBlock.9d6d4e26.js";import{H as I,E as bo}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.86d448e2.js";function Mo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function jo(T){let i,w;return i=new W({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMEdlbmVyYXRvciUyQyUyMFR1cGxlJTBBaW1wb3J0JTIwc2FmZXRlbnNvcnMudG9yY2glMEFmcm9tJTIwaHVnZ2luZ2ZhY2VfaHViJTIwaW1wb3J0JTIwZXhwb3J0X2VudHJpZXNfYXNfZGR1ZiUwQXBpcGUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiklMEElMjMlMjAuLi4lMjBkbyUyMHNvbWUlMjB3b3JrJTIwd2l0aCUyMHRoZSUyMHBpcGVsaW5lJTBBJTBBZGVmJTIwYXNfZW50cmllcyhwaXBlJTNBJTIwRGlmZnVzaW9uUGlwZWxpbmUpJTIwLSUzRSUyMEdlbmVyYXRvciU1QnR1cGxlJTVCc3RyJTJDJTIwYnl0ZXMlNUQlMkMlMjBOb25lJTJDJTIwTm9uZSU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEJ1aWxkJTIwYSUyMGdlbmVyYXRvciUyMHRoYXQlMjB5aWVsZHMlMjB0aGUlMjBlbnRyaWVzJTIwdG8lMjBhZGQlMjB0byUyMHRoZSUyMEREVUYlMjBmaWxlLiUwQSUyMCUyMCUyMCUyMCUyMyUyMFRoZSUyMGZpcnN0JTIwZWxlbWVudCUyMG9mJTIwdGhlJTIwdHVwbGUlMjBpcyUyMHRoZSUyMGZpbGVuYW1lJTIwaW4lMjB0aGUlMjBERFVGJTIwYXJjaGl2ZSUyMChtdXN0JTIwdXNlJTIwVU5JWCUyMHNlcGFyYXRvciEpLiUyMFRoZSUyMHNlY29uZCUyMGVsZW1lbnQlMjBpcyUyMHRoZSUyMGNvbnRlbnQlMjBvZiUyMHRoZSUyMGZpbGUuJTBBJTIwJTIwJTIwJTIwJTIzJTIwRW50cmllcyUyMHdpbGwlMjBiZSUyMGV2YWx1YXRlZCUyMGxhemlseSUyMHdoZW4lMjB0aGUlMjBERFVGJTIwZmlsZSUyMGlzJTIwY3JlYXRlZCUyMChvbmx5JTIwMSUyMGVudHJ5JTIwaXMlMjBsb2FkZWQlMjBpbiUyMG1lbW9yeSUyMGF0JTIwYSUyMHRpbWUpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ2YWUlMkZjb25maWcuanNvbiUyMiUyQyUyMHBpcGUudmFlLnRvX2pzb25fc3RyaW5nKCkuZW5jb2RlKCklMEElMjAlMjAlMjAlMjB5aWVsZCUyMCUyMnZhZSUyRmRpZmZ1c2lvbl9weXRvcmNoX21vZGVsLnNhZmV0ZW5zb3JzJTIyJTJDJTIwc2FmZXRlbnNvcnMudG9yY2guc2F2ZShwaXBlLnZhZS5zdGF0ZV9kaWN0KCkpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ0ZXh0X2VuY29kZXIlMkZjb25maWcuanNvbiUyMiUyQyUyMHBpcGUudGV4dF9lbmNvZGVyLmNvbmZpZy50b19qc29uX3N0cmluZygpLmVuY29kZSgpJTBBJTIwJTIwJTIwJTIweWllbGQlMjAlMjJ0ZXh0X2VuY29kZXIlMkZtb2RlbC5zYWZldGVuc29ycyUyMiUyQyUyMHNhZmV0ZW5zb3JzLnRvcmNoLnNhdmUocGlwZS50ZXh0X2VuY29kZXIuc3RhdGVfZGljdCgpKSUwQSUyMCUyMCUyMCUyMCUyMyUyMC4uLiUyMGFkZCUyMG1vcmUlMjBlbnRyaWVzJTIwaGVyZSUwQSUwQWV4cG9ydF9lbnRyaWVzX2FzX2RkdWYoZGR1Zl9wYXRoJTNEJTIyc3RhYmxlLWRpZmZ1c2lvbi12MS00LmRkdWYlMjIlMkMlMjBlbnRyaWVzJTNEYXNfZW50cmllcyhwaXBlKSk=",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-built_in">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}}),{c(){g(i.$$.fragment)},l(h){f(i.$$.fragment,h)},m(h,c){u(i,h,c),w=!0},p:K,i(h){w||(_(i.$$.fragment,h),w=!0)},o(h){y(i.$$.fragment,h),w=!1},d(h){b(i,h)}}}function wo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function vo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function To(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function xo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function $o(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function Uo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function Jo(T){let i,w="Example:",h,c,M;return c=new W({props:{code:"aW1wb3J0JTIwanNvbiUwQWltcG9ydCUyMG9zJTBBZnJvbSUyMHNhZmV0ZW5zb3JzLnRvcmNoJTIwaW1wb3J0JTIwc2F2ZV9maWxlJTIwYXMlMjBzYWZlX3NhdmVfZmlsZSUwQWZyb20lMjBodWdnaW5nZmFjZV9odWIlMjBpbXBvcnQlMjBzcGxpdF90b3JjaF9zdGF0ZV9kaWN0X2ludG9fc2hhcmRzJTBBJTBBZGVmJTIwc2F2ZV9zdGF0ZV9kaWN0KHN0YXRlX2RpY3QlM0ElMjBkaWN0JTVCc3RyJTJDJTIwdG9yY2guVGVuc29yJTVEJTJDJTIwc2F2ZV9kaXJlY3RvcnklM0ElMjBzdHIpJTNBJTBBJTIwJTIwJTIwJTIwc3RhdGVfZGljdF9zcGxpdCUyMCUzRCUyMHNwbGl0X3RvcmNoX3N0YXRlX2RpY3RfaW50b19zaGFyZHMoc3RhdGVfZGljdCklMEElMjAlMjAlMjAlMjBmb3IlMjBmaWxlbmFtZSUyQyUyMHRlbnNvcnMlMjBpbiUyMHN0YXRlX2RpY3Rfc3BsaXQuZmlsZW5hbWVfdG9fdGVuc29ycy5pdGVtcygpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2hhcmQlMjAlM0QlMjAlN0J0ZW5zb3IlM0ElMjBzdGF0ZV9kaWN0JTVCdGVuc29yJTVEJTIwZm9yJTIwdGVuc29yJTIwaW4lMjB0ZW5zb3JzJTdEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2FmZV9zYXZlX2ZpbGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwc2hhcmQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcy5wYXRoLmpvaW4oc2F2ZV9kaXJlY3RvcnklMkMlMjBmaWxlbmFtZSklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtZXRhZGF0YSUzRCU3QiUyMmZvcm1hdCUyMiUzQSUyMCUyMnB0JTIyJTdEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMGlmJTIwc3RhdGVfZGljdF9zcGxpdC5pc19zaGFyZGVkJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5kZXglMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtZXRhZGF0YSUyMiUzQSUyMHN0YXRlX2RpY3Rfc3BsaXQubWV0YWRhdGElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ3ZWlnaHRfbWFwJTIyJTNBJTIwc3RhdGVfZGljdF9zcGxpdC50ZW5zb3JfdG9fZmlsZW5hbWUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3aXRoJTIwb3Blbihvcy5wYXRoLmpvaW4oc2F2ZV9kaXJlY3RvcnklMkMlMjAlMjJtb2RlbC5zYWZldGVuc29ycy5pbmRleC5qc29uJTIyKSUyQyUyMCUyMnclMjIpJTIwYXMlMjBmJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZi53cml0ZShqc29uLmR1bXBzKGluZGV4JTJDJTIwaW5kZW50JTNEMikp",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-built_in">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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function Zo(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function ko(T){let i,w="Example:",h,c,M;return c=new W({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(){i=d("p"),i.textContent=w,h=n(),g(c.$$.fragment)},l(t){i=p(t,"P",{"data-svelte-h":!0}),m(i)!=="svelte-11lpom8"&&(i.textContent=w),h=o(t),f(c.$$.fragment,t)},m(t,j){l(t,i,j),l(t,h,j),u(c,t,j),M=!0},p:K,i(t){M||(_(c.$$.fragment,t),M=!0)},o(t){y(c.$$.fragment,t),M=!1},d(t){t&&(a(i),a(h)),b(c,t)}}}function Go(T){let i,w,h,c,M,t,j,ds,ye,pn="<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.",ps,be,hs,Me,hn='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,ne,mn='<p>This is a very early version of the parser. The API and implementation can evolve in the near future.</p> <p>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>.</p>',gs,je,fs,we,gn='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>:',us,ve,_s,Te,fn='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:',ys,xe,bs,$e,un="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:",Ms,Ue,js,Je,_n="<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.",ws,Ze,vs,ke,Ts,Ge,xs,C,Ie,ia,xt,yn="Write a DDUF file from an iterable of entries.",ca,$t,bn=`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.`,da,oe,pa,le,$s,B,Ce,ha,Ut,Mn="Export a folder as a DDUF file.",ma,Jt,jn='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.',ga,re,Us,F,Re,fa,Zt,wn="Read a DDUF file and return a dictionary of entries.",ua,kt,vn="Only the metadata is read, the data is not loaded in memory.",_a,ie,Js,R,We,ya,Gt,Tn="Object representing a file entry in a DDUF file.",ba,It,xn='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.',Ma,X,Be,ja,Ct,$n="Open the file as a memory-mapped file.",wa,Rt,Un="Useful to load safetensors directly from the file.",va,ce,Ta,N,Fe,xa,Wt,Jn="Read the file as text.",$a,Bt,Zn="Useful for ‘.txt’ and ‘.json’ entries.",Ua,de,Zs,ze,ks,O,Ve,Ja,Ft,kn="Base exception for errors related to the DDUF format.",Gs,ee,Ee,Za,zt,Gn="Exception thrown when the DDUF file is corrupted.",Is,te,De,ka,Vt,In="Base exception for errors during DDUF export.",Cs,se,Xe,Ga,Et,Cn="Exception thrown when the entry name is invalid.",Rs,Ne,Ws,Le,Rn='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.',Bs,Ye,Wn='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.',Fs,Se,zs,x,Ae,Ia,Dt,Bn="Saves a given torch model to disk, handling sharding and shared tensors issues.",Ca,Xt,Fn='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.',Ra,Nt,zn='For more information about tensor sharing, check out <a href="https://huggingface.co/docs/safetensors/torch_shared_tensors" rel="nofollow">this guide</a>.',Wa,Lt,Vn=`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.`,Ba,Yt,En="Before saving the model, the <code>save_directory</code> is cleaned from any previous shard files.",Fa,qe,Dn=`<p>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>.</p>`,za,He,Xn="<p>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.</p>",Va,pe,Vs,Qe,Es,$,Pe,Ea,St,Nn="Save a model state dictionary to the disk, handling sharding and shared tensors issues.",Da,At,Ln='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.',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>.',Na,Ht,Sn=`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.`,La,Qt,An="Before saving the model, the <code>save_directory</code> is cleaned from any previous shard files.",Ya,Ke,qn=`<p>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>.</p>`,Sa,Oe,Hn="<p>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.</p>",Aa,he,Ds,et,Qn="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> tensors and are designed to be easily extended to any other ML frameworks.",Xs,tt,Ns,G,st,qa,Pt,Pn="Split a model state dictionary in shards so that each shard is smaller than a given size.",Ha,Kt,Kn=`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].`,Qa,at,On=`<p>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.</p>`,Pa,nt,eo=`<p>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>.</p>`,Ka,me,Ls,ot,Ys,lt,to='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.',Ss,z,rt,Oa,Ot,so="Split a model state dictionary in shards so that each shard is smaller than a given size.",en,es,ao=`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].`,tn,it,no=`<p>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>.</p>`,As,ct,qs,dt,oo='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.',Hs,pt,Qs,Y,ht,sn,ts,lo="Load a checkpoint into a model, handling both sharded and non-sharded checkpoints.",an,ge,Ps,mt,Ks,S,gt,nn,ss,ro="Loads a checkpoint file, handling both safetensors and pickle checkpoint formats.",on,fe,Os,ft,ea,ut,ta,V,_t,ln,as,io="Return unique identifier to a tensor storage.",rn,ns,co=`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.`,cn,os,po='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>.',sa,yt,aa,ae,bt,dn,ls,ho='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>',na,Mt,oa,cs,la;return M=new yo({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),j=new I({props:{title:"Serialization",local:"serialization",headingTag:"h1"}}),be=new I({props:{title:"DDUF file format",local:"dduf-file-format",headingTag:"h2"}}),je=new I({props:{title:"How to write a DDUF file?",local:"how-to-write-a-dduf-file",headingTag:"h3"}}),ve=new W({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}}),xe=new W({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}}),Ue=new W({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}}),Ze=new I({props:{title:"How to read a DDUF file?",local:"how-to-read-a-dduf-file",headingTag:"h3"}}),ke=new W({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}}),Ge=new I({props:{title:"Helpers",local:"huggingface_hub.export_entries_as_dduf",headingTag:"h3"}}),Ie=new k({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[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>
`}}),oe=new P({props:{anchor:"huggingface_hub.export_entries_as_dduf.example",$$slots:{default:[Mo]},$$scope:{ctx:T}}}),le=new P({props:{anchor:"huggingface_hub.export_entries_as_dduf.example-2",$$slots:{default:[jo]},$$scope:{ctx:T}}}),Ce=new k({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"}}),re=new P({props:{anchor:"huggingface_hub.export_folder_as_dduf.example",$$slots:{default:[wo]},$$scope:{ctx:T}}}),Re=new k({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>
`}}),ie=new P({props:{anchor:"huggingface_hub.read_dduf_file.example",$$slots:{default:[vo]},$$scope:{ctx:T}}}),We=new k({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#L35"}}),Be=new k({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"}}),ce=new P({props:{anchor:"huggingface_hub.DDUFEntry.as_mmap.example",$$slots:{default:[To]},$$scope:{ctx:T}}}),Fe=new k({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"}}),de=new P({props:{anchor:"huggingface_hub.DDUFEntry.read_text.example",$$slots:{default:[xo]},$$scope:{ctx:T}}}),ze=new I({props:{title:"Errors",local:"huggingface_hub.errors.DDUFError",headingTag:"h3"}}),Ve=new k({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#L337"}}),Ee=new k({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#L341"}}),De=new k({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#L345"}}),Xe=new k({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#L349"}}),Ne=new I({props:{title:"Saving tensors",local:"saving-tensors",headingTag:"h2"}}),Se=new I({props:{title:"save_torch_model",local:"huggingface_hub.save_torch_model",headingTag:"h3"}}),Ae=new k({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[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[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"}}),pe=new P({props:{anchor:"huggingface_hub.save_torch_model.example",$$slots:{default:[$o]},$$scope:{ctx:T}}}),Qe=new I({props:{title:"save_torch_state_dict",local:"huggingface_hub.save_torch_state_dict",headingTag:"h3"}}),Pe=new k({props:{name:"huggingface_hub.save_torch_state_dict",anchor:"huggingface_hub.save_torch_state_dict",parameters:[{name:"state_dict",val:": dict"},{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[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[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#L133"}}),he=new P({props:{anchor:"huggingface_hub.save_torch_state_dict.example",$$slots:{default:[Uo]},$$scope:{ctx:T}}}),tt=new I({props:{title:"split_torch_state_dict_into_shards",local:"huggingface_hub.split_torch_state_dict_into_shards",headingTag:"h3"}}),st=new k({props:{name:"huggingface_hub.split_torch_state_dict_into_shards",anchor:"huggingface_hub.split_torch_state_dict_into_shards",parameters:[{name:"state_dict",val:": dict"},{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#L290",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>
`}}),me=new P({props:{anchor:"huggingface_hub.split_torch_state_dict_into_shards.example",$$slots:{default:[Jo]},$$scope:{ctx:T}}}),ot=new I({props:{title:"split_state_dict_into_shards_factory",local:"huggingface_hub.split_state_dict_into_shards_factory",headingTag:"h3"}}),rt=new k({props:{name:"huggingface_hub.split_state_dict_into_shards_factory",anchor:"huggingface_hub.split_state_dict_into_shards_factory",parameters:[{name:"state_dict",val:": dict"},{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 0x7f1786e33910>"},{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>
`}}),ct=new I({props:{title:"Loading tensors",local:"loading-tensors",headingTag:"h2"}}),pt=new I({props:{title:"load_torch_model",local:"huggingface_hub.load_torch_model",headingTag:"h3"}}),ht=new k({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#L363",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>
`}}),ge=new P({props:{anchor:"huggingface_hub.load_torch_model.example",$$slots:{default:[Zo]},$$scope:{ctx:T}}}),mt=new I({props:{title:"load_state_dict_from_file",local:"huggingface_hub.load_state_dict_from_file",headingTag:"h3"}}),gt=new k({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#L540",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>
`}}),fe=new P({props:{anchor:"huggingface_hub.load_state_dict_from_file.example",$$slots:{default:[ko]},$$scope:{ctx:T}}}),ft=new I({props:{title:"Tensors helpers",local:"tensors-helpers",headingTag:"h2"}}),ut=new I({props:{title:"get_torch_storage_id",local:"huggingface_hub.get_torch_storage_id",headingTag:"h3"}}),_t=new k({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#L726"}}),yt=new I({props:{title:"get_torch_storage_size",local:"huggingface_hub.get_torch_storage_size",headingTag:"h3"}}),bt=new k({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#L743"}}),Mt=new bo({props:{source:"https://github.com/huggingface/huggingface_hub/blob/main/docs/source/en/package_reference/serialization.md"}}),{c(){i=d("meta"),w=n(),h=d("p"),c=n(),g(M.$$.fragment),t=n(),g(j.$$.fragment),ds=n(),ye=d("p"),ye.innerHTML=pn,ps=n(),g(be.$$.fragment),hs=n(),Me=d("p"),Me.innerHTML=hn,ms=n(),ne=d("blockquote"),ne.innerHTML=mn,gs=n(),g(je.$$.fragment),fs=n(),we=d("p"),we.innerHTML=gn,us=n(),g(ve.$$.fragment),_s=n(),Te=d("p"),Te.innerHTML=fn,ys=n(),g(xe.$$.fragment),bs=n(),$e=d("p"),$e.innerHTML=un,Ms=n(),g(Ue.$$.fragment),js=n(),Je=d("p"),Je.innerHTML=_n,ws=n(),g(Ze.$$.fragment),vs=n(),g(ke.$$.fragment),Ts=n(),g(Ge.$$.fragment),xs=n(),C=d("div"),g(Ie.$$.fragment),ia=n(),xt=d("p"),xt.textContent=yn,ca=n(),$t=d("p"),$t.innerHTML=bn,da=n(),g(oe.$$.fragment),pa=n(),g(le.$$.fragment),$s=n(),B=d("div"),g(Ce.$$.fragment),ha=n(),Ut=d("p"),Ut.textContent=Mn,ma=n(),Jt=d("p"),Jt.innerHTML=jn,ga=n(),g(re.$$.fragment),Us=n(),F=d("div"),g(Re.$$.fragment),fa=n(),Zt=d("p"),Zt.textContent=wn,ua=n(),kt=d("p"),kt.textContent=vn,_a=n(),g(ie.$$.fragment),Js=n(),R=d("div"),g(We.$$.fragment),ya=n(),Gt=d("p"),Gt.textContent=Tn,ba=n(),It=d("p"),It.innerHTML=xn,Ma=n(),X=d("div"),g(Be.$$.fragment),ja=n(),Ct=d("p"),Ct.textContent=$n,wa=n(),Rt=d("p"),Rt.textContent=Un,va=n(),g(ce.$$.fragment),Ta=n(),N=d("div"),g(Fe.$$.fragment),xa=n(),Wt=d("p"),Wt.textContent=Jn,$a=n(),Bt=d("p"),Bt.textContent=Zn,Ua=n(),g(de.$$.fragment),Zs=n(),g(ze.$$.fragment),ks=n(),O=d("div"),g(Ve.$$.fragment),Ja=n(),Ft=d("p"),Ft.textContent=kn,Gs=n(),ee=d("div"),g(Ee.$$.fragment),Za=n(),zt=d("p"),zt.textContent=Gn,Is=n(),te=d("div"),g(De.$$.fragment),ka=n(),Vt=d("p"),Vt.textContent=In,Cs=n(),se=d("div"),g(Xe.$$.fragment),Ga=n(),Et=d("p"),Et.textContent=Cn,Rs=n(),g(Ne.$$.fragment),Ws=n(),Le=d("p"),Le.innerHTML=Rn,Bs=n(),Ye=d("p"),Ye.innerHTML=Wn,Fs=n(),g(Se.$$.fragment),zs=n(),x=d("div"),g(Ae.$$.fragment),Ia=n(),Dt=d("p"),Dt.textContent=Bn,Ca=n(),Xt=d("p"),Xt.innerHTML=Fn,Ra=n(),Nt=d("p"),Nt.innerHTML=zn,Wa=n(),Lt=d("p"),Lt.innerHTML=Vn,Ba=n(),Yt=d("p"),Yt.innerHTML=En,Fa=n(),qe=d("blockquote"),qe.innerHTML=Dn,za=n(),He=d("blockquote"),He.innerHTML=Xn,Va=n(),g(pe.$$.fragment),Vs=n(),g(Qe.$$.fragment),Es=n(),$=d("div"),g(Pe.$$.fragment),Ea=n(),St=d("p"),St.textContent=Nn,Da=n(),At=d("p"),At.innerHTML=Ln,Xa=n(),qt=d("p"),qt.innerHTML=Yn,Na=n(),Ht=d("p"),Ht.innerHTML=Sn,La=n(),Qt=d("p"),Qt.innerHTML=An,Ya=n(),Ke=d("blockquote"),Ke.innerHTML=qn,Sa=n(),Oe=d("blockquote"),Oe.innerHTML=Hn,Aa=n(),g(he.$$.fragment),Ds=n(),et=d("p"),et.innerHTML=Qn,Xs=n(),g(tt.$$.fragment),Ns=n(),G=d("div"),g(st.$$.fragment),qa=n(),Pt=d("p"),Pt.textContent=Pn,Ha=n(),Kt=d("p"),Kt.innerHTML=Kn,Qa=n(),at=d("blockquote"),at.innerHTML=On,Pa=n(),nt=d("blockquote"),nt.innerHTML=eo,Ka=n(),g(me.$$.fragment),Ls=n(),g(ot.$$.fragment),Ys=n(),lt=d("p"),lt.innerHTML=to,Ss=n(),z=d("div"),g(rt.$$.fragment),Oa=n(),Ot=d("p"),Ot.textContent=so,en=n(),es=d("p"),es.innerHTML=ao,tn=n(),it=d("blockquote"),it.innerHTML=no,As=n(),g(ct.$$.fragment),qs=n(),dt=d("p"),dt.innerHTML=oo,Hs=n(),g(pt.$$.fragment),Qs=n(),Y=d("div"),g(ht.$$.fragment),sn=n(),ts=d("p"),ts.textContent=lo,an=n(),g(ge.$$.fragment),Ps=n(),g(mt.$$.fragment),Ks=n(),S=d("div"),g(gt.$$.fragment),nn=n(),ss=d("p"),ss.textContent=ro,on=n(),g(fe.$$.fragment),Os=n(),g(ft.$$.fragment),ea=n(),g(ut.$$.fragment),ta=n(),V=d("div"),g(_t.$$.fragment),ln=n(),as=d("p"),as.textContent=io,rn=n(),ns=d("p"),ns.textContent=co,cn=n(),os=d("p"),os.innerHTML=po,sa=n(),g(yt.$$.fragment),aa=n(),ae=d("div"),g(bt.$$.fragment),dn=n(),ls=d("p"),ls.innerHTML=ho,na=n(),g(Mt.$$.fragment),oa=n(),cs=d("p"),this.h()},l(e){const s=_o("svelte-u9bgzb",document.head);i=p(s,"META",{name:!0,content:!0}),s.forEach(a),w=o(e),h=p(e,"P",{}),J(h).forEach(a),c=o(e),f(M.$$.fragment,e),t=o(e),f(j.$$.fragment,e),ds=o(e),ye=p(e,"P",{"data-svelte-h":!0}),m(ye)!=="svelte-8n5thw"&&(ye.innerHTML=pn),ps=o(e),f(be.$$.fragment,e),hs=o(e),Me=p(e,"P",{"data-svelte-h":!0}),m(Me)!=="svelte-76eyi"&&(Me.innerHTML=hn),ms=o(e),ne=p(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(ne)!=="svelte-1vr7ad4"&&(ne.innerHTML=mn),gs=o(e),f(je.$$.fragment,e),fs=o(e),we=p(e,"P",{"data-svelte-h":!0}),m(we)!=="svelte-wjz0ef"&&(we.innerHTML=gn),us=o(e),f(ve.$$.fragment,e),_s=o(e),Te=p(e,"P",{"data-svelte-h":!0}),m(Te)!=="svelte-94wwhy"&&(Te.innerHTML=fn),ys=o(e),f(xe.$$.fragment,e),bs=o(e),$e=p(e,"P",{"data-svelte-h":!0}),m($e)!=="svelte-10ghbb4"&&($e.innerHTML=un),Ms=o(e),f(Ue.$$.fragment,e),js=o(e),Je=p(e,"P",{"data-svelte-h":!0}),m(Je)!=="svelte-1ia72u1"&&(Je.innerHTML=_n),ws=o(e),f(Ze.$$.fragment,e),vs=o(e),f(ke.$$.fragment,e),Ts=o(e),f(Ge.$$.fragment,e),xs=o(e),C=p(e,"DIV",{class:!0});var E=J(C);f(Ie.$$.fragment,E),ia=o(E),xt=p(E,"P",{"data-svelte-h":!0}),m(xt)!=="svelte-13au33d"&&(xt.textContent=yn),ca=o(E),$t=p(E,"P",{"data-svelte-h":!0}),m($t)!=="svelte-7i3cxt"&&($t.innerHTML=bn),da=o(E),f(oe.$$.fragment,E),pa=o(E),f(le.$$.fragment,E),E.forEach(a),$s=o(e),B=p(e,"DIV",{class:!0});var A=J(B);f(Ce.$$.fragment,A),ha=o(A),Ut=p(A,"P",{"data-svelte-h":!0}),m(Ut)!=="svelte-1spqaxd"&&(Ut.textContent=Mn),ma=o(A),Jt=p(A,"P",{"data-svelte-h":!0}),m(Jt)!=="svelte-1zandc"&&(Jt.innerHTML=jn),ga=o(A),f(re.$$.fragment,A),A.forEach(a),Us=o(e),F=p(e,"DIV",{class:!0});var q=J(F);f(Re.$$.fragment,q),fa=o(q),Zt=p(q,"P",{"data-svelte-h":!0}),m(Zt)!=="svelte-wslvoh"&&(Zt.textContent=wn),ua=o(q),kt=p(q,"P",{"data-svelte-h":!0}),m(kt)!=="svelte-1jossqp"&&(kt.textContent=vn),_a=o(q),f(ie.$$.fragment,q),q.forEach(a),Js=o(e),R=p(e,"DIV",{class:!0});var D=J(R);f(We.$$.fragment,D),ya=o(D),Gt=p(D,"P",{"data-svelte-h":!0}),m(Gt)!=="svelte-16rzygd"&&(Gt.textContent=Tn),ba=o(D),It=p(D,"P",{"data-svelte-h":!0}),m(It)!=="svelte-pnh06h"&&(It.innerHTML=xn),Ma=o(D),X=p(D,"DIV",{class:!0});var H=J(X);f(Be.$$.fragment,H),ja=o(H),Ct=p(H,"P",{"data-svelte-h":!0}),m(Ct)!=="svelte-mrui81"&&(Ct.textContent=$n),wa=o(H),Rt=p(H,"P",{"data-svelte-h":!0}),m(Rt)!=="svelte-mr7gff"&&(Rt.textContent=Un),va=o(H),f(ce.$$.fragment,H),H.forEach(a),Ta=o(D),N=p(D,"DIV",{class:!0});var Q=J(N);f(Fe.$$.fragment,Q),xa=o(Q),Wt=p(Q,"P",{"data-svelte-h":!0}),m(Wt)!=="svelte-6ka7ei"&&(Wt.textContent=Jn),$a=o(Q),Bt=p(Q,"P",{"data-svelte-h":!0}),m(Bt)!=="svelte-1s7wtva"&&(Bt.textContent=Zn),Ua=o(Q),f(de.$$.fragment,Q),Q.forEach(a),D.forEach(a),Zs=o(e),f(ze.$$.fragment,e),ks=o(e),O=p(e,"DIV",{class:!0});var jt=J(O);f(Ve.$$.fragment,jt),Ja=o(jt),Ft=p(jt,"P",{"data-svelte-h":!0}),m(Ft)!=="svelte-bujp1z"&&(Ft.textContent=kn),jt.forEach(a),Gs=o(e),ee=p(e,"DIV",{class:!0});var wt=J(ee);f(Ee.$$.fragment,wt),Za=o(wt),zt=p(wt,"P",{"data-svelte-h":!0}),m(zt)!=="svelte-76lsj1"&&(zt.textContent=Gn),wt.forEach(a),Is=o(e),te=p(e,"DIV",{class:!0});var vt=J(te);f(De.$$.fragment,vt),ka=o(vt),Vt=p(vt,"P",{"data-svelte-h":!0}),m(Vt)!=="svelte-1540kbq"&&(Vt.textContent=In),vt.forEach(a),Cs=o(e),se=p(e,"DIV",{class:!0});var Tt=J(se);f(Xe.$$.fragment,Tt),Ga=o(Tt),Et=p(Tt,"P",{"data-svelte-h":!0}),m(Et)!=="svelte-18paw2o"&&(Et.textContent=Cn),Tt.forEach(a),Rs=o(e),f(Ne.$$.fragment,e),Ws=o(e),Le=p(e,"P",{"data-svelte-h":!0}),m(Le)!=="svelte-1gnm445"&&(Le.innerHTML=Rn),Bs=o(e),Ye=p(e,"P",{"data-svelte-h":!0}),m(Ye)!=="svelte-1mocwb"&&(Ye.innerHTML=Wn),Fs=o(e),f(Se.$$.fragment,e),zs=o(e),x=p(e,"DIV",{class:!0});var U=J(x);f(Ae.$$.fragment,U),Ia=o(U),Dt=p(U,"P",{"data-svelte-h":!0}),m(Dt)!=="svelte-ts5jcq"&&(Dt.textContent=Bn),Ca=o(U),Xt=p(U,"P",{"data-svelte-h":!0}),m(Xt)!=="svelte-12jpcei"&&(Xt.innerHTML=Fn),Ra=o(U),Nt=p(U,"P",{"data-svelte-h":!0}),m(Nt)!=="svelte-hxbjn2"&&(Nt.innerHTML=zn),Wa=o(U),Lt=p(U,"P",{"data-svelte-h":!0}),m(Lt)!=="svelte-b08cux"&&(Lt.innerHTML=Vn),Ba=o(U),Yt=p(U,"P",{"data-svelte-h":!0}),m(Yt)!=="svelte-zotpm4"&&(Yt.innerHTML=En),Fa=o(U),qe=p(U,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(qe)!=="svelte-xsnrgo"&&(qe.innerHTML=Dn),za=o(U),He=p(U,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(He)!=="svelte-1an6eex"&&(He.innerHTML=Xn),Va=o(U),f(pe.$$.fragment,U),U.forEach(a),Vs=o(e),f(Qe.$$.fragment,e),Es=o(e),$=p(e,"DIV",{class:!0});var Z=J($);f(Pe.$$.fragment,Z),Ea=o(Z),St=p(Z,"P",{"data-svelte-h":!0}),m(St)!=="svelte-1hwpwyy"&&(St.textContent=Nn),Da=o(Z),At=p(Z,"P",{"data-svelte-h":!0}),m(At)!=="svelte-1sy8rkx"&&(At.innerHTML=Ln),Xa=o(Z),qt=p(Z,"P",{"data-svelte-h":!0}),m(qt)!=="svelte-hxbjn2"&&(qt.innerHTML=Yn),Na=o(Z),Ht=p(Z,"P",{"data-svelte-h":!0}),m(Ht)!=="svelte-b08cux"&&(Ht.innerHTML=Sn),La=o(Z),Qt=p(Z,"P",{"data-svelte-h":!0}),m(Qt)!=="svelte-zotpm4"&&(Qt.innerHTML=An),Ya=o(Z),Ke=p(Z,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(Ke)!=="svelte-xsnrgo"&&(Ke.innerHTML=qn),Sa=o(Z),Oe=p(Z,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(Oe)!=="svelte-1an6eex"&&(Oe.innerHTML=Hn),Aa=o(Z),f(he.$$.fragment,Z),Z.forEach(a),Ds=o(e),et=p(e,"P",{"data-svelte-h":!0}),m(et)!=="svelte-2v5z2y"&&(et.innerHTML=Qn),Xs=o(e),f(tt.$$.fragment,e),Ns=o(e),G=p(e,"DIV",{class:!0});var L=J(G);f(st.$$.fragment,L),qa=o(L),Pt=p(L,"P",{"data-svelte-h":!0}),m(Pt)!=="svelte-1q1pe7b"&&(Pt.textContent=Pn),Ha=o(L),Kt=p(L,"P",{"data-svelte-h":!0}),m(Kt)!=="svelte-17rio2z"&&(Kt.innerHTML=Kn),Qa=o(L),at=p(L,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(at)!=="svelte-1xpe5hv"&&(at.innerHTML=On),Pa=o(L),nt=p(L,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(nt)!=="svelte-xsnrgo"&&(nt.innerHTML=eo),Ka=o(L),f(me.$$.fragment,L),L.forEach(a),Ls=o(e),f(ot.$$.fragment,e),Ys=o(e),lt=p(e,"P",{"data-svelte-h":!0}),m(lt)!=="svelte-1hva642"&&(lt.innerHTML=to),Ss=o(e),z=p(e,"DIV",{class:!0});var ue=J(z);f(rt.$$.fragment,ue),Oa=o(ue),Ot=p(ue,"P",{"data-svelte-h":!0}),m(Ot)!=="svelte-1q1pe7b"&&(Ot.textContent=so),en=o(ue),es=p(ue,"P",{"data-svelte-h":!0}),m(es)!=="svelte-17rio2z"&&(es.innerHTML=ao),tn=o(ue),it=p(ue,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),m(it)!=="svelte-xsnrgo"&&(it.innerHTML=no),ue.forEach(a),As=o(e),f(ct.$$.fragment,e),qs=o(e),dt=p(e,"P",{"data-svelte-h":!0}),m(dt)!=="svelte-1vzkkqp"&&(dt.innerHTML=oo),Hs=o(e),f(pt.$$.fragment,e),Qs=o(e),Y=p(e,"DIV",{class:!0});var rs=J(Y);f(ht.$$.fragment,rs),sn=o(rs),ts=p(rs,"P",{"data-svelte-h":!0}),m(ts)!=="svelte-qwh3fh"&&(ts.textContent=lo),an=o(rs),f(ge.$$.fragment,rs),rs.forEach(a),Ps=o(e),f(mt.$$.fragment,e),Ks=o(e),S=p(e,"DIV",{class:!0});var is=J(S);f(gt.$$.fragment,is),nn=o(is),ss=p(is,"P",{"data-svelte-h":!0}),m(ss)!=="svelte-1mudbss"&&(ss.textContent=ro),on=o(is),f(fe.$$.fragment,is),is.forEach(a),Os=o(e),f(ft.$$.fragment,e),ea=o(e),f(ut.$$.fragment,e),ta=o(e),V=p(e,"DIV",{class:!0});var _e=J(V);f(_t.$$.fragment,_e),ln=o(_e),as=p(_e,"P",{"data-svelte-h":!0}),m(as)!=="svelte-lfv2l4"&&(as.textContent=io),rn=o(_e),ns=p(_e,"P",{"data-svelte-h":!0}),m(ns)!=="svelte-1o86t9o"&&(ns.textContent=co),cn=o(_e),os=p(_e,"P",{"data-svelte-h":!0}),m(os)!=="svelte-akggeo"&&(os.innerHTML=po),_e.forEach(a),sa=o(e),f(yt.$$.fragment,e),aa=o(e),ae=p(e,"DIV",{class:!0});var ra=J(ae);f(bt.$$.fragment,ra),dn=o(ra),ls=p(ra,"P",{"data-svelte-h":!0}),m(ls)!=="svelte-1ey7lf2"&&(ls.innerHTML=ho),ra.forEach(a),na=o(e),f(Mt.$$.fragment,e),oa=o(e),cs=p(e,"P",{}),J(cs).forEach(a),this.h()},h(){v(i,"name","hf:doc:metadata"),v(i,"content",Io),v(ne,"class","warning"),v(C,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(B,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(ee,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(te,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(se,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(qe,"class","warning"),v(He,"class","warning"),v(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(Ke,"class","warning"),v(Oe,"class","warning"),v($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(at,"class","tip"),v(nt,"class","warning"),v(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(it,"class","warning"),v(z,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(Y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),v(ae,"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,s){r(document.head,i),l(e,w,s),l(e,h,s),l(e,c,s),u(M,e,s),l(e,t,s),u(j,e,s),l(e,ds,s),l(e,ye,s),l(e,ps,s),u(be,e,s),l(e,hs,s),l(e,Me,s),l(e,ms,s),l(e,ne,s),l(e,gs,s),u(je,e,s),l(e,fs,s),l(e,we,s),l(e,us,s),u(ve,e,s),l(e,_s,s),l(e,Te,s),l(e,ys,s),u(xe,e,s),l(e,bs,s),l(e,$e,s),l(e,Ms,s),u(Ue,e,s),l(e,js,s),l(e,Je,s),l(e,ws,s),u(Ze,e,s),l(e,vs,s),u(ke,e,s),l(e,Ts,s),u(Ge,e,s),l(e,xs,s),l(e,C,s),u(Ie,C,null),r(C,ia),r(C,xt),r(C,ca),r(C,$t),r(C,da),u(oe,C,null),r(C,pa),u(le,C,null),l(e,$s,s),l(e,B,s),u(Ce,B,null),r(B,ha),r(B,Ut),r(B,ma),r(B,Jt),r(B,ga),u(re,B,null),l(e,Us,s),l(e,F,s),u(Re,F,null),r(F,fa),r(F,Zt),r(F,ua),r(F,kt),r(F,_a),u(ie,F,null),l(e,Js,s),l(e,R,s),u(We,R,null),r(R,ya),r(R,Gt),r(R,ba),r(R,It),r(R,Ma),r(R,X),u(Be,X,null),r(X,ja),r(X,Ct),r(X,wa),r(X,Rt),r(X,va),u(ce,X,null),r(R,Ta),r(R,N),u(Fe,N,null),r(N,xa),r(N,Wt),r(N,$a),r(N,Bt),r(N,Ua),u(de,N,null),l(e,Zs,s),u(ze,e,s),l(e,ks,s),l(e,O,s),u(Ve,O,null),r(O,Ja),r(O,Ft),l(e,Gs,s),l(e,ee,s),u(Ee,ee,null),r(ee,Za),r(ee,zt),l(e,Is,s),l(e,te,s),u(De,te,null),r(te,ka),r(te,Vt),l(e,Cs,s),l(e,se,s),u(Xe,se,null),r(se,Ga),r(se,Et),l(e,Rs,s),u(Ne,e,s),l(e,Ws,s),l(e,Le,s),l(e,Bs,s),l(e,Ye,s),l(e,Fs,s),u(Se,e,s),l(e,zs,s),l(e,x,s),u(Ae,x,null),r(x,Ia),r(x,Dt),r(x,Ca),r(x,Xt),r(x,Ra),r(x,Nt),r(x,Wa),r(x,Lt),r(x,Ba),r(x,Yt),r(x,Fa),r(x,qe),r(x,za),r(x,He),r(x,Va),u(pe,x,null),l(e,Vs,s),u(Qe,e,s),l(e,Es,s),l(e,$,s),u(Pe,$,null),r($,Ea),r($,St),r($,Da),r($,At),r($,Xa),r($,qt),r($,Na),r($,Ht),r($,La),r($,Qt),r($,Ya),r($,Ke),r($,Sa),r($,Oe),r($,Aa),u(he,$,null),l(e,Ds,s),l(e,et,s),l(e,Xs,s),u(tt,e,s),l(e,Ns,s),l(e,G,s),u(st,G,null),r(G,qa),r(G,Pt),r(G,Ha),r(G,Kt),r(G,Qa),r(G,at),r(G,Pa),r(G,nt),r(G,Ka),u(me,G,null),l(e,Ls,s),u(ot,e,s),l(e,Ys,s),l(e,lt,s),l(e,Ss,s),l(e,z,s),u(rt,z,null),r(z,Oa),r(z,Ot),r(z,en),r(z,es),r(z,tn),r(z,it),l(e,As,s),u(ct,e,s),l(e,qs,s),l(e,dt,s),l(e,Hs,s),u(pt,e,s),l(e,Qs,s),l(e,Y,s),u(ht,Y,null),r(Y,sn),r(Y,ts),r(Y,an),u(ge,Y,null),l(e,Ps,s),u(mt,e,s),l(e,Ks,s),l(e,S,s),u(gt,S,null),r(S,nn),r(S,ss),r(S,on),u(fe,S,null),l(e,Os,s),u(ft,e,s),l(e,ea,s),u(ut,e,s),l(e,ta,s),l(e,V,s),u(_t,V,null),r(V,ln),r(V,as),r(V,rn),r(V,ns),r(V,cn),r(V,os),l(e,sa,s),u(yt,e,s),l(e,aa,s),l(e,ae,s),u(bt,ae,null),r(ae,dn),r(ae,ls),l(e,na,s),u(Mt,e,s),l(e,oa,s),l(e,cs,s),la=!0},p(e,[s]){const E={};s&2&&(E.$$scope={dirty:s,ctx:e}),oe.$set(E);const A={};s&2&&(A.$$scope={dirty:s,ctx:e}),le.$set(A);const q={};s&2&&(q.$$scope={dirty:s,ctx:e}),re.$set(q);const D={};s&2&&(D.$$scope={dirty:s,ctx:e}),ie.$set(D);const H={};s&2&&(H.$$scope={dirty:s,ctx:e}),ce.$set(H);const Q={};s&2&&(Q.$$scope={dirty:s,ctx:e}),de.$set(Q);const jt={};s&2&&(jt.$$scope={dirty:s,ctx:e}),pe.$set(jt);const wt={};s&2&&(wt.$$scope={dirty:s,ctx:e}),he.$set(wt);const vt={};s&2&&(vt.$$scope={dirty:s,ctx:e}),me.$set(vt);const Tt={};s&2&&(Tt.$$scope={dirty:s,ctx:e}),ge.$set(Tt);const U={};s&2&&(U.$$scope={dirty:s,ctx:e}),fe.$set(U)},i(e){la||(_(M.$$.fragment,e),_(j.$$.fragment,e),_(be.$$.fragment,e),_(je.$$.fragment,e),_(ve.$$.fragment,e),_(xe.$$.fragment,e),_(Ue.$$.fragment,e),_(Ze.$$.fragment,e),_(ke.$$.fragment,e),_(Ge.$$.fragment,e),_(Ie.$$.fragment,e),_(oe.$$.fragment,e),_(le.$$.fragment,e),_(Ce.$$.fragment,e),_(re.$$.fragment,e),_(Re.$$.fragment,e),_(ie.$$.fragment,e),_(We.$$.fragment,e),_(Be.$$.fragment,e),_(ce.$$.fragment,e),_(Fe.$$.fragment,e),_(de.$$.fragment,e),_(ze.$$.fragment,e),_(Ve.$$.fragment,e),_(Ee.$$.fragment,e),_(De.$$.fragment,e),_(Xe.$$.fragment,e),_(Ne.$$.fragment,e),_(Se.$$.fragment,e),_(Ae.$$.fragment,e),_(pe.$$.fragment,e),_(Qe.$$.fragment,e),_(Pe.$$.fragment,e),_(he.$$.fragment,e),_(tt.$$.fragment,e),_(st.$$.fragment,e),_(me.$$.fragment,e),_(ot.$$.fragment,e),_(rt.$$.fragment,e),_(ct.$$.fragment,e),_(pt.$$.fragment,e),_(ht.$$.fragment,e),_(ge.$$.fragment,e),_(mt.$$.fragment,e),_(gt.$$.fragment,e),_(fe.$$.fragment,e),_(ft.$$.fragment,e),_(ut.$$.fragment,e),_(_t.$$.fragment,e),_(yt.$$.fragment,e),_(bt.$$.fragment,e),_(Mt.$$.fragment,e),la=!0)},o(e){y(M.$$.fragment,e),y(j.$$.fragment,e),y(be.$$.fragment,e),y(je.$$.fragment,e),y(ve.$$.fragment,e),y(xe.$$.fragment,e),y(Ue.$$.fragment,e),y(Ze.$$.fragment,e),y(ke.$$.fragment,e),y(Ge.$$.fragment,e),y(Ie.$$.fragment,e),y(oe.$$.fragment,e),y(le.$$.fragment,e),y(Ce.$$.fragment,e),y(re.$$.fragment,e),y(Re.$$.fragment,e),y(ie.$$.fragment,e),y(We.$$.fragment,e),y(Be.$$.fragment,e),y(ce.$$.fragment,e),y(Fe.$$.fragment,e),y(de.$$.fragment,e),y(ze.$$.fragment,e),y(Ve.$$.fragment,e),y(Ee.$$.fragment,e),y(De.$$.fragment,e),y(Xe.$$.fragment,e),y(Ne.$$.fragment,e),y(Se.$$.fragment,e),y(Ae.$$.fragment,e),y(pe.$$.fragment,e),y(Qe.$$.fragment,e),y(Pe.$$.fragment,e),y(he.$$.fragment,e),y(tt.$$.fragment,e),y(st.$$.fragment,e),y(me.$$.fragment,e),y(ot.$$.fragment,e),y(rt.$$.fragment,e),y(ct.$$.fragment,e),y(pt.$$.fragment,e),y(ht.$$.fragment,e),y(ge.$$.fragment,e),y(mt.$$.fragment,e),y(gt.$$.fragment,e),y(fe.$$.fragment,e),y(ft.$$.fragment,e),y(ut.$$.fragment,e),y(_t.$$.fragment,e),y(yt.$$.fragment,e),y(bt.$$.fragment,e),y(Mt.$$.fragment,e),la=!1},d(e){e&&(a(w),a(h),a(c),a(t),a(ds),a(ye),a(ps),a(hs),a(Me),a(ms),a(ne),a(gs),a(fs),a(we),a(us),a(_s),a(Te),a(ys),a(bs),a($e),a(Ms),a(js),a(Je),a(ws),a(vs),a(Ts),a(xs),a(C),a($s),a(B),a(Us),a(F),a(Js),a(R),a(Zs),a(ks),a(O),a(Gs),a(ee),a(Is),a(te),a(Cs),a(se),a(Rs),a(Ws),a(Le),a(Bs),a(Ye),a(Fs),a(zs),a(x),a(Vs),a(Es),a($),a(Ds),a(et),a(Xs),a(Ns),a(G),a(Ls),a(Ys),a(lt),a(Ss),a(z),a(As),a(qs),a(dt),a(Hs),a(Qs),a(Y),a(Ps),a(Ks),a(S),a(Os),a(ea),a(ta),a(V),a(sa),a(aa),a(ae),a(na),a(oa),a(cs)),a(i),b(M,e),b(j,e),b(be,e),b(je,e),b(ve,e),b(xe,e),b(Ue,e),b(Ze,e),b(ke,e),b(Ge,e),b(Ie),b(oe),b(le),b(Ce),b(re),b(Re),b(ie),b(We),b(Be),b(ce),b(Fe),b(de),b(ze,e),b(Ve),b(Ee),b(De),b(Xe),b(Ne,e),b(Se,e),b(Ae),b(pe),b(Qe,e),b(Pe),b(he),b(tt,e),b(st),b(me),b(ot,e),b(rt),b(ct,e),b(pt,e),b(ht),b(ge),b(mt,e),b(gt),b(fe),b(ft,e),b(ut,e),b(_t),b(yt,e),b(bt),b(Mt,e)}}}const Io='{"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_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 Co(T){return go(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Do extends fo{constructor(i){super(),uo(this,i,Co,Go,mo,{})}}export{Do as component};
