import{s as Bt,n as qt,o as Kt}from"../chunks/scheduler.d6170356.js";import{S as Ot,i as te,g as i,s as l,r as f,A as ee,h as d,f as a,c as n,j as Et,u as o,x as m,k as N,y as ae,a as s,v as r,d as u,t as h,w as g}from"../chunks/index.fcd4cc08.js";import{C as jt}from"../chunks/CodeBlock.db16bf50.js";import{H as S,E as se}from"../chunks/index.57043804.js";function le(Ut){let p,E,V,B,M,q,v,_t=`<a href="https://github.com/webdataset/webdataset" rel="nofollow">WebDataset</a> is a library for writing I/O pipelines for large datasets.
Its sequential I/O and sharding features make it especially useful for streaming large-scale datasets to a DataLoader.`,K,C,O,y,Jt=`A WebDataset file is a TAR archive containing a series of data files.
All successive data files with the same prefix are considered to be part of the same example (e.g., an image/audio file and its label or metadata):`,tt,c,Wt='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-format.png"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-format-dark.png"/>',et,$,Zt="Labels and metadata can be in a <code>.json</code> file, in a <code>.txt</code> (for a caption, a description), or in a <code>.cls</code> (for a class index).",at,x,Gt=`A large scale WebDataset is made of many files called shards, where each shard is a TAR archive.
Each shard is often ~1GB but the full dataset can be multiple terabytes!`,st,k,lt,T,Ht="WebDataset is designed for multimodal datasets, i.e. for image, audio and/or video datasets.",nt,j,Lt="Indeed, since media files tend to be quite big, WebDataset’s sequential I/O enables large reads and buffering, resulting in the best data loading speed.",it,U,Dt="Here is a non-exhaustive list of supported data formats:",dt,_,Rt="<li>image: jpeg, png, tiff</li> <li>audio: mp3, m4a, wav, flac</li> <li>video: mp4, mov, avi</li> <li>other: npy, npz</li>",mt,J,Xt='The full list evolves over time and depends on the implementation. For example, you can find which formats the <code>webdataset</code> package supports in the source code <a href="https://github.com/webdataset/webdataset/blob/main/webdataset/autodecode.py" rel="nofollow">here</a>.',pt,W,ft,Z,At=`Streaming TAR archives is fast because it reads contiguous chunks of data.
It can be orders of magnitude faster than reading separate data files one by one.`,ot,G,It="WebDataset streaming offers high-speed performance both when reading from disk and from cloud storage, which makes it an ideal format to feed to a DataLoader:",rt,b,zt='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-stream.png"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-stream-dark.png"/>',ut,H,Pt='For example here is how to stream the <a href="https://huggingface.co/datasets/timm/imagenet-12k-wds" rel="nofollow">timm/imagenet-12k-wds</a> dataset directly from Hugging Face:',ht,L,Qt='First you need to <a href="/docs/huggingface_hub/quick-start#login">Login with your Hugging Face account</a>, for example using:',gt,D,ct,R,Ft="And then you can stream the dataset with WebDataset:",bt,X,wt,A,Mt,I,Vt=`Generally, datasets in WebDataset formats are already shuffled and ready to feed to a DataLoader.
But you can still reshuffle the data with WebDataset’s approximate shuffling.`,vt,z,Yt="In addition to shuffling the list of shards, WebDataset uses a buffer to shuffle a dataset without any cost to speed:",Ct,w,Nt='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-shuffle.png"/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/datasets-webdataset-shuffle-dark.png"/>',yt,P,St="To shuffle a list of sharded files and randomly sample from the shuffle buffer:",$t,Q,xt,F,kt,Y,Tt;return M=new S({props:{title:"WebDataset",local:"webdataset",headingTag:"h1"}}),C=new S({props:{title:"The WebDataset format",local:"the-webdataset-format",headingTag:"h2"}}),k=new S({props:{title:"Multimodal support",local:"multimodal-support",headingTag:"h2"}}),W=new S({props:{title:"Streaming",local:"streaming",headingTag:"h2"}}),D=new jt({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login',wrap:!1}}),X=new jt({props:{code:"aW1wb3J0JTIwd2ViZGF0YXNldCUyMGFzJTIwd2RzJTBBZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGdldF90b2tlbiUwQWZyb20lMjB0b3JjaC51dGlscy5kYXRhJTIwaW1wb3J0JTIwRGF0YUxvYWRlciUwQSUwQWhmX3Rva2VuJTIwJTNEJTIwZ2V0X3Rva2VuKCklMEF1cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRmh1Z2dpbmdmYWNlLmNvJTJGZGF0YXNldHMlMkZ0aW1tJTJGaW1hZ2VuZXQtMTJrLXdkcyUyRnJlc29sdmUlMkZtYWluJTJGaW1hZ2VuZXQxMmstdHJhaW4tJTdCJTdCMDAwMC4uMTAyMyU3RCU3RC50YXIlMjIlMEF1cmwlMjAlM0QlMjBmJTIycGlwZSUzQWN1cmwlMjAtcyUyMC1MJTIwJTdCdXJsJTdEJTIwLUglMjAnQXV0aG9yaXphdGlvbiUzQUJlYXJlciUyMCU3QmhmX3Rva2VuJTdEJyUyMiUwQWRhdGFzZXQlMjAlM0QlMjB3ZHMuV2ViRGF0YXNldCh1cmwpLmRlY29kZSgpJTBBZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoZGF0YXNldCUyQyUyMGJhdGNoX3NpemUlM0Q2NCUyQyUyMG51bV93b3JrZXJzJTNENCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> webdataset <span class="hljs-keyword">as</span> wds
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> get_token
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

<span class="hljs-meta">&gt;&gt;&gt; </span>hf_token = get_token()
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://huggingface.co/datasets/timm/imagenet-12k-wds/resolve/main/imagenet12k-train-{{0000..1023}}.tar&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">f&quot;pipe:curl -s -L <span class="hljs-subst">{url}</span> -H &#x27;Authorization:Bearer <span class="hljs-subst">{hf_token}</span>&#x27;&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = wds.WebDataset(url).decode()
<span class="hljs-meta">&gt;&gt;&gt; </span>dataloader = DataLoader(dataset, batch_size=<span class="hljs-number">64</span>, num_workers=<span class="hljs-number">4</span>)`,wrap:!1}}),A=new S({props:{title:"Shuffle",local:"shuffle",headingTag:"h2"}}),Q=new jt({props:{code:"YnVmZmVyX3NpemUlMjAlM0QlMjAxMDAwJTBBZGF0YXNldCUyMCUzRCUyMCglMEElMjAlMjAlMjAlMjB3ZHMuV2ViRGF0YXNldCh1cmwlMkMlMjBzaGFyZHNodWZmbGUlM0RUcnVlKSUwQSUyMCUyMCUyMCUyMC5zaHVmZmxlKGJ1ZmZlcl9zaXplKSUwQSUyMCUyMCUyMCUyMC5kZWNvZGUoKSUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>buffer_size = <span class="hljs-number">1000</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = (
<span class="hljs-meta">... </span>    wds.WebDataset(url, shardshuffle=<span class="hljs-literal">True</span>)
<span class="hljs-meta">... </span>    .shuffle(buffer_size)
<span class="hljs-meta">... </span>    .decode()
<span class="hljs-meta">... </span>)`,wrap:!1}}),F=new se({props:{source:"https://github.com/huggingface/hub-docs/blob/main/docs/hub/datasets-webdataset.md"}}),{c(){p=i("meta"),E=l(),V=i("p"),B=l(),f(M.$$.fragment),q=l(),v=i("p"),v.innerHTML=_t,K=l(),f(C.$$.fragment),O=l(),y=i("p"),y.textContent=Jt,tt=l(),c=i("div"),c.innerHTML=Wt,et=l(),$=i("p"),$.innerHTML=Zt,at=l(),x=i("p"),x.textContent=Gt,st=l(),f(k.$$.fragment),lt=l(),T=i("p"),T.textContent=Ht,nt=l(),j=i("p"),j.textContent=Lt,it=l(),U=i("p"),U.textContent=Dt,dt=l(),_=i("ul"),_.innerHTML=Rt,mt=l(),J=i("p"),J.innerHTML=Xt,pt=l(),f(W.$$.fragment),ft=l(),Z=i("p"),Z.textContent=At,ot=l(),G=i("p"),G.textContent=It,rt=l(),b=i("div"),b.innerHTML=zt,ut=l(),H=i("p"),H.innerHTML=Pt,ht=l(),L=i("p"),L.innerHTML=Qt,gt=l(),f(D.$$.fragment),ct=l(),R=i("p"),R.textContent=Ft,bt=l(),f(X.$$.fragment),wt=l(),f(A.$$.fragment),Mt=l(),I=i("p"),I.textContent=Vt,vt=l(),z=i("p"),z.textContent=Yt,Ct=l(),w=i("div"),w.innerHTML=Nt,yt=l(),P=i("p"),P.textContent=St,$t=l(),f(Q.$$.fragment),xt=l(),f(F.$$.fragment),kt=l(),Y=i("p"),this.h()},l(t){const e=ee("svelte-u9bgzb",document.head);p=d(e,"META",{name:!0,content:!0}),e.forEach(a),E=n(t),V=d(t,"P",{}),Et(V).forEach(a),B=n(t),o(M.$$.fragment,t),q=n(t),v=d(t,"P",{"data-svelte-h":!0}),m(v)!=="svelte-1x0ilw7"&&(v.innerHTML=_t),K=n(t),o(C.$$.fragment,t),O=n(t),y=d(t,"P",{"data-svelte-h":!0}),m(y)!=="svelte-s28fzx"&&(y.textContent=Jt),tt=n(t),c=d(t,"DIV",{class:!0,"data-svelte-h":!0}),m(c)!=="svelte-1bdrcp9"&&(c.innerHTML=Wt),et=n(t),$=d(t,"P",{"data-svelte-h":!0}),m($)!=="svelte-7sb7k1"&&($.innerHTML=Zt),at=n(t),x=d(t,"P",{"data-svelte-h":!0}),m(x)!=="svelte-1pmozez"&&(x.textContent=Gt),st=n(t),o(k.$$.fragment,t),lt=n(t),T=d(t,"P",{"data-svelte-h":!0}),m(T)!=="svelte-11egvlw"&&(T.textContent=Ht),nt=n(t),j=d(t,"P",{"data-svelte-h":!0}),m(j)!=="svelte-td3uuk"&&(j.textContent=Lt),it=n(t),U=d(t,"P",{"data-svelte-h":!0}),m(U)!=="svelte-lwvb2g"&&(U.textContent=Dt),dt=n(t),_=d(t,"UL",{"data-svelte-h":!0}),m(_)!=="svelte-p3flt6"&&(_.innerHTML=Rt),mt=n(t),J=d(t,"P",{"data-svelte-h":!0}),m(J)!=="svelte-1w2ow21"&&(J.innerHTML=Xt),pt=n(t),o(W.$$.fragment,t),ft=n(t),Z=d(t,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-d0lfwq"&&(Z.textContent=At),ot=n(t),G=d(t,"P",{"data-svelte-h":!0}),m(G)!=="svelte-1ski7pk"&&(G.textContent=It),rt=n(t),b=d(t,"DIV",{class:!0,"data-svelte-h":!0}),m(b)!=="svelte-16x5sv3"&&(b.innerHTML=zt),ut=n(t),H=d(t,"P",{"data-svelte-h":!0}),m(H)!=="svelte-kd5fni"&&(H.innerHTML=Pt),ht=n(t),L=d(t,"P",{"data-svelte-h":!0}),m(L)!=="svelte-1jdzygp"&&(L.innerHTML=Qt),gt=n(t),o(D.$$.fragment,t),ct=n(t),R=d(t,"P",{"data-svelte-h":!0}),m(R)!=="svelte-3qvfc"&&(R.textContent=Ft),bt=n(t),o(X.$$.fragment,t),wt=n(t),o(A.$$.fragment,t),Mt=n(t),I=d(t,"P",{"data-svelte-h":!0}),m(I)!=="svelte-1qsq6cj"&&(I.textContent=Vt),vt=n(t),z=d(t,"P",{"data-svelte-h":!0}),m(z)!=="svelte-e5b3kw"&&(z.textContent=Yt),Ct=n(t),w=d(t,"DIV",{class:!0,"data-svelte-h":!0}),m(w)!=="svelte-15c8cpf"&&(w.innerHTML=Nt),yt=n(t),P=d(t,"P",{"data-svelte-h":!0}),m(P)!=="svelte-1qykgdn"&&(P.textContent=St),$t=n(t),o(Q.$$.fragment,t),xt=n(t),o(F.$$.fragment,t),kt=n(t),Y=d(t,"P",{}),Et(Y).forEach(a),this.h()},h(){N(p,"name","hf:doc:metadata"),N(p,"content",ne),N(c,"class","flex justify-center"),N(b,"class","flex justify-center"),N(w,"class","flex justify-center")},m(t,e){ae(document.head,p),s(t,E,e),s(t,V,e),s(t,B,e),r(M,t,e),s(t,q,e),s(t,v,e),s(t,K,e),r(C,t,e),s(t,O,e),s(t,y,e),s(t,tt,e),s(t,c,e),s(t,et,e),s(t,$,e),s(t,at,e),s(t,x,e),s(t,st,e),r(k,t,e),s(t,lt,e),s(t,T,e),s(t,nt,e),s(t,j,e),s(t,it,e),s(t,U,e),s(t,dt,e),s(t,_,e),s(t,mt,e),s(t,J,e),s(t,pt,e),r(W,t,e),s(t,ft,e),s(t,Z,e),s(t,ot,e),s(t,G,e),s(t,rt,e),s(t,b,e),s(t,ut,e),s(t,H,e),s(t,ht,e),s(t,L,e),s(t,gt,e),r(D,t,e),s(t,ct,e),s(t,R,e),s(t,bt,e),r(X,t,e),s(t,wt,e),r(A,t,e),s(t,Mt,e),s(t,I,e),s(t,vt,e),s(t,z,e),s(t,Ct,e),s(t,w,e),s(t,yt,e),s(t,P,e),s(t,$t,e),r(Q,t,e),s(t,xt,e),r(F,t,e),s(t,kt,e),s(t,Y,e),Tt=!0},p:qt,i(t){Tt||(u(M.$$.fragment,t),u(C.$$.fragment,t),u(k.$$.fragment,t),u(W.$$.fragment,t),u(D.$$.fragment,t),u(X.$$.fragment,t),u(A.$$.fragment,t),u(Q.$$.fragment,t),u(F.$$.fragment,t),Tt=!0)},o(t){h(M.$$.fragment,t),h(C.$$.fragment,t),h(k.$$.fragment,t),h(W.$$.fragment,t),h(D.$$.fragment,t),h(X.$$.fragment,t),h(A.$$.fragment,t),h(Q.$$.fragment,t),h(F.$$.fragment,t),Tt=!1},d(t){t&&(a(E),a(V),a(B),a(q),a(v),a(K),a(O),a(y),a(tt),a(c),a(et),a($),a(at),a(x),a(st),a(lt),a(T),a(nt),a(j),a(it),a(U),a(dt),a(_),a(mt),a(J),a(pt),a(ft),a(Z),a(ot),a(G),a(rt),a(b),a(ut),a(H),a(ht),a(L),a(gt),a(ct),a(R),a(bt),a(wt),a(Mt),a(I),a(vt),a(z),a(Ct),a(w),a(yt),a(P),a($t),a(xt),a(kt),a(Y)),a(p),g(M,t),g(C,t),g(k,t),g(W,t),g(D,t),g(X,t),g(A,t),g(Q,t),g(F,t)}}}const ne='{"title":"WebDataset","local":"webdataset","sections":[{"title":"The WebDataset format","local":"the-webdataset-format","sections":[],"depth":2},{"title":"Multimodal support","local":"multimodal-support","sections":[],"depth":2},{"title":"Streaming","local":"streaming","sections":[],"depth":2},{"title":"Shuffle","local":"shuffle","sections":[],"depth":2}],"depth":1}';function ie(Ut){return Kt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class oe extends Ot{constructor(p){super(),te(this,p,ie,le,Bt,{})}}export{oe as component};
