import{s as ve,o as Te,n as _e}from"../chunks/scheduler.bdbef820.js";import{S as Me,i as je,g as o,s as i,r as u,A as ke,h as p,f as s,c as l,j as $e,u as g,x as h,k as ye,y as Ce,a,v as $,d as y,t as b,w}from"../chunks/index.c0aea24a.js";import{T as be}from"../chunks/Tip.31005f7d.js";import{C as we}from"../chunks/CodeBlock.6ccca92e.js";import{H as ne,E as xe}from"../chunks/EditOnGithub.725ee0c1.js";function Je(z){let n,c='Transforms are any of the processing methods from the <a href="./process">How-to Process</a> guides such as <a href="/docs/datasets/v3.0.0/en/package_reference/main_classes#datasets.Dataset.map">Dataset.map()</a> or <a href="/docs/datasets/v3.0.0/en/package_reference/main_classes#datasets.Dataset.shuffle">Dataset.shuffle()</a>.';return{c(){n=o("p"),n.innerHTML=c},l(r){n=p(r,"P",{"data-svelte-h":!0}),h(n)!=="svelte-1mcvn5q"&&(n.innerHTML=c)},m(r,f){a(r,n,f)},p:_e,d(r){r&&s(n)}}}function He(z){let n,c='When caching is disabled, use <a href="/docs/datasets/v3.0.0/en/package_reference/main_classes#datasets.Dataset.save_to_disk">Dataset.save_to_disk()</a> to save your transformed dataset or it will be deleted once the session ends.';return{c(){n=o("p"),n.innerHTML=c},l(r){n=p(r,"P",{"data-svelte-h":!0}),h(n)!=="svelte-15ytcnk"&&(n.innerHTML=c)},m(r,f){a(r,n,f)},p:_e,d(r){r&&s(n)}}}function Ue(z){let n,c,r,f,_,S,v,ie="The cache is one of the reasons why 🤗 Datasets is so efficient. It stores previously downloaded and processed datasets so when you need to use them again, they are reloaded directly from the cache. This avoids having to download a dataset all over again, or reapplying processing functions. Even after you close and start another Python session, 🤗 Datasets will reload your dataset directly from the cache!",D,T,E,M,le="How does the cache keeps track of what transforms are applied to a dataset? Well, 🤗 Datasets assigns a fingerprint to the cache file. A fingerprint keeps track of the current state of a dataset. The initial fingerprint is computed using a hash from the Arrow table, or a hash of the Arrow files if the dataset is on disk. Subsequent fingerprints are computed by combining the fingerprint of the previous state, and a hash of the latest transform applied.",W,m,X,j,re="Here are what the actual fingerprints look like:",Y,k,q,C,oe='In order for a transform to be hashable, it needs to be picklable by <a href="https://dill.readthedocs.io/en/latest/" rel="nofollow">dill</a> or <a href="https://docs.python.org/3/library/pickle" rel="nofollow">pickle</a>.',F,x,pe="When you use a non-hashable transform, 🤗 Datasets uses a random fingerprint instead and raises a warning. The non-hashable transform is considered different from the previous transforms. As a result, 🤗 Datasets will recompute all the transforms. Make sure your transforms are serializable with pickle or dill to avoid this!",Q,J,he="An example of when 🤗 Datasets recomputes everything is when caching is disabled. When this happens, the cache files are generated every time and they get written to a temporary directory. Once your Python session ends, the cache files in the temporary directory are deleted. A random hash is assigned to these cache files, instead of a fingerprint.",A,d,B,H,V,U,ce="The fingerprint of a dataset is updated by hashing the function passed to <code>map</code> as well as the <code>map</code> parameters (<code>batch_size</code>, <code>remove_columns</code>, etc.).",N,P,fe='You can check the hash of any Python object using the <a href="/docs/datasets/v3.0.0/en/package_reference/main_classes#datasets.fingerprint.Hasher">fingerprint.Hasher</a>:',O,I,K,G,me=`The hash is computed by dumping the object using a <code>dill</code> pickler and hashing the dumped bytes.
The pickler recursively dumps all the variables used in your function, so any change you do to an object that is used in your function, will cause the hash to change.`,ee,R,de=`If one of your functions doesn’t seem to have the same hash across sessions, it means at least one of its variables contains a Python object that is not deterministic.
When this happens, feel free to hash any object you find suspicious to try to find the object that caused the hash to change.
For example, if you use a list for which the order of its elements is not deterministic across sessions, then the hash won’t be the same across sessions either.`,te,Z,se,L,ae;return _=new ne({props:{title:"The cache",local:"the-cache",headingTag:"h1"}}),T=new ne({props:{title:"Fingerprint",local:"fingerprint",headingTag:"h2"}}),m=new be({props:{$$slots:{default:[Je]},$$scope:{ctx:z}}}),k=new we({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwRGF0YXNldCUwQWRhdGFzZXQxJTIwJTNEJTIwRGF0YXNldC5mcm9tX2RpY3QoJTdCJTIyYSUyMiUzQSUyMCU1QjAlMkMlMjAxJTJDJTIwMiU1RCU3RCklMEFkYXRhc2V0MiUyMCUzRCUyMGRhdGFzZXQxLm1hcChsYW1iZGElMjB4JTNBJTIwJTdCJTIyYSUyMiUzQSUyMHglNUIlMjJhJTIyJTVEJTIwJTJCJTIwMSU3RCklMEFwcmludChkYXRhc2V0MS5fZmluZ2VycHJpbnQlMkMlMjBkYXRhc2V0Mi5fZmluZ2VycHJpbnQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Dataset
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset1 = Dataset.from_dict({<span class="hljs-string">&quot;a&quot;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]})
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset2 = dataset1.<span class="hljs-built_in">map</span>(<span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;a&quot;</span>: x[<span class="hljs-string">&quot;a&quot;</span>] + <span class="hljs-number">1</span>})
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(dataset1._fingerprint, dataset2._fingerprint)
d19493523d95e2dc 5b86abacd4b42434`,wrap:!1}}),d=new be({props:{$$slots:{default:[He]},$$scope:{ctx:z}}}),H=new ne({props:{title:"Hashing",local:"hashing",headingTag:"h2"}}),I=new we({props:{code:"ZnJvbSUyMGRhdGFzZXRzLmZpbmdlcnByaW50JTIwaW1wb3J0JTIwSGFzaGVyJTBBbXlfZnVuYyUyMCUzRCUyMGxhbWJkYSUyMGV4YW1wbGUlM0ElMjAlN0IlMjJsZW5ndGglMjIlM0ElMjBsZW4oZXhhbXBsZSU1QiUyMnRleHQlMjIlNUQpJTdEJTBBcHJpbnQoSGFzaGVyLmhhc2gobXlfZnVuYykp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets.fingerprint <span class="hljs-keyword">import</span> Hasher
<span class="hljs-meta">&gt;&gt;&gt; </span>my_func = <span class="hljs-keyword">lambda</span> example: {<span class="hljs-string">&quot;length&quot;</span>: <span class="hljs-built_in">len</span>(example[<span class="hljs-string">&quot;text&quot;</span>])}
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(Hasher.<span class="hljs-built_in">hash</span>(my_func))
<span class="hljs-string">&#x27;3d35e2b3e94c81d6&#x27;</span>`,wrap:!1}}),Z=new xe({props:{source:"https://github.com/huggingface/datasets/blob/main/docs/source/about_cache.mdx"}}),{c(){n=o("meta"),c=i(),r=o("p"),f=i(),u(_.$$.fragment),S=i(),v=o("p"),v.textContent=ie,D=i(),u(T.$$.fragment),E=i(),M=o("p"),M.textContent=le,W=i(),u(m.$$.fragment),X=i(),j=o("p"),j.textContent=re,Y=i(),u(k.$$.fragment),q=i(),C=o("p"),C.innerHTML=oe,F=i(),x=o("p"),x.textContent=pe,Q=i(),J=o("p"),J.textContent=he,A=i(),u(d.$$.fragment),B=i(),u(H.$$.fragment),V=i(),U=o("p"),U.innerHTML=ce,N=i(),P=o("p"),P.innerHTML=fe,O=i(),u(I.$$.fragment),K=i(),G=o("p"),G.innerHTML=me,ee=i(),R=o("p"),R.textContent=de,te=i(),u(Z.$$.fragment),se=i(),L=o("p"),this.h()},l(e){const t=ke("svelte-u9bgzb",document.head);n=p(t,"META",{name:!0,content:!0}),t.forEach(s),c=l(e),r=p(e,"P",{}),$e(r).forEach(s),f=l(e),g(_.$$.fragment,e),S=l(e),v=p(e,"P",{"data-svelte-h":!0}),h(v)!=="svelte-14tcvpe"&&(v.textContent=ie),D=l(e),g(T.$$.fragment,e),E=l(e),M=p(e,"P",{"data-svelte-h":!0}),h(M)!=="svelte-1nie07o"&&(M.textContent=le),W=l(e),g(m.$$.fragment,e),X=l(e),j=p(e,"P",{"data-svelte-h":!0}),h(j)!=="svelte-1jtij1i"&&(j.textContent=re),Y=l(e),g(k.$$.fragment,e),q=l(e),C=p(e,"P",{"data-svelte-h":!0}),h(C)!=="svelte-i7zvcn"&&(C.innerHTML=oe),F=l(e),x=p(e,"P",{"data-svelte-h":!0}),h(x)!=="svelte-13cebff"&&(x.textContent=pe),Q=l(e),J=p(e,"P",{"data-svelte-h":!0}),h(J)!=="svelte-159jmpz"&&(J.textContent=he),A=l(e),g(d.$$.fragment,e),B=l(e),g(H.$$.fragment,e),V=l(e),U=p(e,"P",{"data-svelte-h":!0}),h(U)!=="svelte-epnhkf"&&(U.innerHTML=ce),N=l(e),P=p(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-bwub4u"&&(P.innerHTML=fe),O=l(e),g(I.$$.fragment,e),K=l(e),G=p(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-92c3vb"&&(G.innerHTML=me),ee=l(e),R=p(e,"P",{"data-svelte-h":!0}),h(R)!=="svelte-t61mhn"&&(R.textContent=de),te=l(e),g(Z.$$.fragment,e),se=l(e),L=p(e,"P",{}),$e(L).forEach(s),this.h()},h(){ye(n,"name","hf:doc:metadata"),ye(n,"content",Pe)},m(e,t){Ce(document.head,n),a(e,c,t),a(e,r,t),a(e,f,t),$(_,e,t),a(e,S,t),a(e,v,t),a(e,D,t),$(T,e,t),a(e,E,t),a(e,M,t),a(e,W,t),$(m,e,t),a(e,X,t),a(e,j,t),a(e,Y,t),$(k,e,t),a(e,q,t),a(e,C,t),a(e,F,t),a(e,x,t),a(e,Q,t),a(e,J,t),a(e,A,t),$(d,e,t),a(e,B,t),$(H,e,t),a(e,V,t),a(e,U,t),a(e,N,t),a(e,P,t),a(e,O,t),$(I,e,t),a(e,K,t),a(e,G,t),a(e,ee,t),a(e,R,t),a(e,te,t),$(Z,e,t),a(e,se,t),a(e,L,t),ae=!0},p(e,[t]){const ue={};t&2&&(ue.$$scope={dirty:t,ctx:e}),m.$set(ue);const ge={};t&2&&(ge.$$scope={dirty:t,ctx:e}),d.$set(ge)},i(e){ae||(y(_.$$.fragment,e),y(T.$$.fragment,e),y(m.$$.fragment,e),y(k.$$.fragment,e),y(d.$$.fragment,e),y(H.$$.fragment,e),y(I.$$.fragment,e),y(Z.$$.fragment,e),ae=!0)},o(e){b(_.$$.fragment,e),b(T.$$.fragment,e),b(m.$$.fragment,e),b(k.$$.fragment,e),b(d.$$.fragment,e),b(H.$$.fragment,e),b(I.$$.fragment,e),b(Z.$$.fragment,e),ae=!1},d(e){e&&(s(c),s(r),s(f),s(S),s(v),s(D),s(E),s(M),s(W),s(X),s(j),s(Y),s(q),s(C),s(F),s(x),s(Q),s(J),s(A),s(B),s(V),s(U),s(N),s(P),s(O),s(K),s(G),s(ee),s(R),s(te),s(se),s(L)),s(n),w(_,e),w(T,e),w(m,e),w(k,e),w(d,e),w(H,e),w(I,e),w(Z,e)}}}const Pe='{"title":"The cache","local":"the-cache","sections":[{"title":"Fingerprint","local":"fingerprint","sections":[],"depth":2},{"title":"Hashing","local":"hashing","sections":[],"depth":2}],"depth":1}';function Ie(z){return Te(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Se extends Me{constructor(n){super(),je(this,n,Ie,Ue,ve,{})}}export{Se as component};
