import{s as ve,o as Te,n as we}from"../chunks/scheduler.bdbef820.js";import{S as Me,i as je,g as o,s as l,r as u,A as ke,h as p,f as s,c as i,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 as _}from"../chunks/index.c0aea24a.js";import{T as be}from"../chunks/Tip.31005f7d.js";import{C as _e}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/pr_7019/en/package_reference/main_classes#datasets.Dataset.map">Dataset.map()</a> or <a href="/docs/datasets/pr_7019/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-1bn0mnk"&&(n.innerHTML=c)},m(r,f){a(r,n,f)},p:we,d(r){r&&s(n)}}}function He(z){let n,c='When caching is disabled, use <a href="/docs/datasets/pr_7019/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-94gy9l"&&(n.innerHTML=c)},m(r,f){a(r,n,f)},p:we,d(r){r&&s(n)}}}function Ue(z){let n,c,r,f,w,S,v,le="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,ie="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,F,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>.',Q,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/pr_7019/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 w=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 _e({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 _e({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=l(),r=o("p"),f=l(),u(w.$$.fragment),S=l(),v=o("p"),v.textContent=le,D=l(),u(T.$$.fragment),E=l(),M=o("p"),M.textContent=ie,W=l(),u(m.$$.fragment),X=l(),j=o("p"),j.textContent=re,Y=l(),u(k.$$.fragment),F=l(),C=o("p"),C.innerHTML=oe,Q=l(),x=o("p"),x.textContent=pe,q=l(),J=o("p"),J.textContent=he,A=l(),u(d.$$.fragment),B=l(),u(H.$$.fragment),V=l(),U=o("p"),U.innerHTML=ce,N=l(),P=o("p"),P.innerHTML=fe,O=l(),u(I.$$.fragment),K=l(),G=o("p"),G.innerHTML=me,ee=l(),R=o("p"),R.textContent=de,te=l(),u(Z.$$.fragment),se=l(),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=i(e),r=p(e,"P",{}),$e(r).forEach(s),f=i(e),g(w.$$.fragment,e),S=i(e),v=p(e,"P",{"data-svelte-h":!0}),h(v)!=="svelte-14tcvpe"&&(v.textContent=le),D=i(e),g(T.$$.fragment,e),E=i(e),M=p(e,"P",{"data-svelte-h":!0}),h(M)!=="svelte-1nie07o"&&(M.textContent=ie),W=i(e),g(m.$$.fragment,e),X=i(e),j=p(e,"P",{"data-svelte-h":!0}),h(j)!=="svelte-1jtij1i"&&(j.textContent=re),Y=i(e),g(k.$$.fragment,e),F=i(e),C=p(e,"P",{"data-svelte-h":!0}),h(C)!=="svelte-i7zvcn"&&(C.innerHTML=oe),Q=i(e),x=p(e,"P",{"data-svelte-h":!0}),h(x)!=="svelte-13cebff"&&(x.textContent=pe),q=i(e),J=p(e,"P",{"data-svelte-h":!0}),h(J)!=="svelte-159jmpz"&&(J.textContent=he),A=i(e),g(d.$$.fragment,e),B=i(e),g(H.$$.fragment,e),V=i(e),U=p(e,"P",{"data-svelte-h":!0}),h(U)!=="svelte-epnhkf"&&(U.innerHTML=ce),N=i(e),P=p(e,"P",{"data-svelte-h":!0}),h(P)!=="svelte-1vi83lp"&&(P.innerHTML=fe),O=i(e),g(I.$$.fragment,e),K=i(e),G=p(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-92c3vb"&&(G.innerHTML=me),ee=i(e),R=p(e,"P",{"data-svelte-h":!0}),h(R)!=="svelte-t61mhn"&&(R.textContent=de),te=i(e),g(Z.$$.fragment,e),se=i(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),$(w,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,F,t),a(e,C,t),a(e,Q,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(w.$$.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(w.$$.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(F),s(C),s(Q),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),_(T,e),_(m,e),_(k,e),_(d,e),_(H,e),_(I,e),_(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};
