import{s as le,o as ne,n as ee}from"../chunks/scheduler.d627b047.js";import{S as se,i as ae,g as x,s as m,r as g,A as re,h as U,f as s,c,j as D,u as y,x as X,k as S,y as I,a as o,v as u,d as h,t as j,w as $}from"../chunks/index.73c51727.js";import{D as q}from"../chunks/Docstring.0ad99a5d.js";import{C as te}from"../chunks/CodeBlock.5f78c87f.js";import{E as O}from"../chunks/ExampleCodeBlock.e6081cec.js";import{H as L,E as oe}from"../chunks/index.8df1db42.js";function ie(E){let l,d="Example:",i,a,r;return a=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEFmcm9tJTIwdHJsLmV4dHJhcy5wcm9maWxpbmclMjBpbXBvcnQlMjBwcm9maWxpbmdfZGVjb3JhdG9yJTBBJTBBY2xhc3MlMjBNeVRyYWluZXIoVHJhaW5lciklM0ElMEElMjAlMjAlMjAlMjAlNDBwcm9maWxpbmdfZGVjb3JhdG9yJTBBJTIwJTIwJTIwJTIwZGVmJTIwc29tZV9tZXRob2Qoc2VsZiklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBBJTIwJTNEJTIwbnAucmFuZG9tLnJhbmQoMTAwMCUyQyUyMDEwMDApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwQiUyMCUzRCUyMG5wLnJhbmRvbS5yYW5kKDEwMDAlMkMlMjAxMDAwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMENvZGUlMjB0byUyMHByb2ZpbGUlM0ElMjBzaW11bGF0ZSUyMGElMjBjb21wdXRhdGlvbmFsbHklMjBleHBlbnNpdmUlMjBvcGVyYXRpb24lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjBBJTIwJTQwJTIwQg==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer
<span class="hljs-keyword">from</span> trl.extras.profiling <span class="hljs-keyword">import</span> profiling_decorator

<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyTrainer</span>(<span class="hljs-title class_ inherited__">Trainer</span>):
<span class="hljs-meta">    @profiling_decorator</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">some_method</span>(<span class="hljs-params">self</span>):
        A = np.random.rand(<span class="hljs-number">1000</span>, <span class="hljs-number">1000</span>)
        B = np.random.rand(<span class="hljs-number">1000</span>, <span class="hljs-number">1000</span>)
        <span class="hljs-comment"># Code to profile: simulate a computationally expensive operation</span>
        result = A @ B`,wrap:!1}}),{c(){l=x("p"),l.textContent=d,i=m(),g(a.$$.fragment)},l(t){l=U(t,"P",{"data-svelte-h":!0}),X(l)!=="svelte-11lpom8"&&(l.textContent=d),i=c(t),y(a.$$.fragment,t)},m(t,p){o(t,l,p),o(t,i,p),u(a,t,p),r=!0},p:ee,i(t){r||(h(a.$$.fragment,t),r=!0)},o(t){j(a.$$.fragment,t),r=!1},d(t){t&&(s(l),s(i)),$(a,t)}}}function pe(E){let l,d="Example:",i,a,r;return a=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEFmcm9tJTIwdHJsLmV4dHJhcy5wcm9maWxpbmclMjBpbXBvcnQlMjBwcm9maWxpbmdfY29udGV4dCUwQSUwQWNsYXNzJTIwTXlUcmFpbmVyKFRyYWluZXIpJTNBJTBBJTIwJTIwJTIwJTIwZGVmJTIwc29tZV9tZXRob2Qoc2VsZiklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBBJTIwJTNEJTIwbnAucmFuZG9tLnJhbmQoMTAwMCUyQyUyMDEwMDApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwQiUyMCUzRCUyMG5wLnJhbmRvbS5yYW5kKDEwMDAlMkMlMjAxMDAwKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHdpdGglMjBwcm9maWxpbmdfY29udGV4dChzZWxmJTJDJTIwJTIybWF0cml4X211bHRpcGxpY2F0aW9uJTIyKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMENvZGUlMjB0byUyMHByb2ZpbGUlM0ElMjBzaW11bGF0ZSUyMGElMjBjb21wdXRhdGlvbmFsbHklMjBleHBlbnNpdmUlMjBvcGVyYXRpb24lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjBBJTIwJTQwJTIwQiUyMCUyMCUyMyUyME1hdHJpeCUyMG11bHRpcGxpY2F0aW9u",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer
<span class="hljs-keyword">from</span> trl.extras.profiling <span class="hljs-keyword">import</span> profiling_context

<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyTrainer</span>(<span class="hljs-title class_ inherited__">Trainer</span>):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">some_method</span>(<span class="hljs-params">self</span>):
        A = np.random.rand(<span class="hljs-number">1000</span>, <span class="hljs-number">1000</span>)
        B = np.random.rand(<span class="hljs-number">1000</span>, <span class="hljs-number">1000</span>)
        <span class="hljs-keyword">with</span> profiling_context(self, <span class="hljs-string">&quot;matrix_multiplication&quot;</span>):
            <span class="hljs-comment"># Code to profile: simulate a computationally expensive operation</span>
            result = A @ B  <span class="hljs-comment"># Matrix multiplication</span>`,wrap:!1}}),{c(){l=x("p"),l.textContent=d,i=m(),g(a.$$.fragment)},l(t){l=U(t,"P",{"data-svelte-h":!0}),X(l)!=="svelte-11lpom8"&&(l.textContent=d),i=c(t),y(a.$$.fragment,t)},m(t,p){o(t,l,p),o(t,i,p),u(a,t,p),r=!0},p:ee,i(t){r||(h(a.$$.fragment,t),r=!0)},o(t){j(a.$$.fragment,t),r=!1},d(t){t&&(s(l),s(i)),$(a,t)}}}function me(E){let l,d,i,a,r,t,p,Z,f,_,F,v,P='Decorator to profile a function and log execution time using <a href="/docs/trl/main/en/others#trl.extras.profiling.profiling_context">extras.profiling.profiling_context()</a>.',Y,T,W,A,Q,M,C,N,k,K=`A context manager function for profiling a block of code. Results are logged to Weights & Biases or MLflow
depending on the trainer’s configuration.`,z,J,H,B,V,G,R;return r=new L({props:{title:"Other",local:"other",headingTag:"h1"}}),p=new L({props:{title:"profiling_decorator",local:"trl.extras.profiling.profiling_decorator",headingTag:"h2"}}),_=new q({props:{name:"trl.extras.profiling.profiling_decorator",anchor:"trl.extras.profiling.profiling_decorator",parameters:[{name:"func",val:": <built-in function callable>"}],parametersDescription:[{anchor:"trl.extras.profiling.profiling_decorator.func",description:`<strong>func</strong> (<code>callable</code>) &#x2014;
Function to be profiled.`,name:"func"}],source:"https://github.com/huggingface/trl/blob/main/trl/extras/profiling.py#L70"}}),T=new O({props:{anchor:"trl.extras.profiling.profiling_decorator.example",$$slots:{default:[ie]},$$scope:{ctx:E}}}),A=new L({props:{title:"profiling_context",local:"trl.extras.profiling.profiling_context",headingTag:"h2"}}),C=new q({props:{name:"trl.extras.profiling.profiling_context",anchor:"trl.extras.profiling.profiling_context",parameters:[{name:"trainer",val:": Trainer"},{name:"name",val:": str"}],parametersDescription:[{anchor:"trl.extras.profiling.profiling_context.trainer",description:`<strong>trainer</strong> (<code>~transformers.Trainer</code>) &#x2014;
Trainer object.`,name:"trainer"},{anchor:"trl.extras.profiling.profiling_context.name",description:`<strong>name</strong> (<code>str</code>) &#x2014;
Name of the block to be profiled. Used as a key in the logged dictionary.`,name:"name"}],source:"https://github.com/huggingface/trl/blob/main/trl/extras/profiling.py#L31"}}),J=new O({props:{anchor:"trl.extras.profiling.profiling_context.example",$$slots:{default:[pe]},$$scope:{ctx:E}}}),B=new oe({props:{source:"https://github.com/huggingface/trl/blob/main/docs/source/others.md"}}),{c(){l=x("meta"),d=m(),i=x("p"),a=m(),g(r.$$.fragment),t=m(),g(p.$$.fragment),Z=m(),f=x("div"),g(_.$$.fragment),F=m(),v=x("p"),v.innerHTML=P,Y=m(),g(T.$$.fragment),W=m(),g(A.$$.fragment),Q=m(),M=x("div"),g(C.$$.fragment),N=m(),k=x("p"),k.textContent=K,z=m(),g(J.$$.fragment),H=m(),g(B.$$.fragment),V=m(),G=x("p"),this.h()},l(e){const n=re("svelte-u9bgzb",document.head);l=U(n,"META",{name:!0,content:!0}),n.forEach(s),d=c(e),i=U(e,"P",{}),D(i).forEach(s),a=c(e),y(r.$$.fragment,e),t=c(e),y(p.$$.fragment,e),Z=c(e),f=U(e,"DIV",{class:!0});var w=D(f);y(_.$$.fragment,w),F=c(w),v=U(w,"P",{"data-svelte-h":!0}),X(v)!=="svelte-xlzzpy"&&(v.innerHTML=P),Y=c(w),y(T.$$.fragment,w),w.forEach(s),W=c(e),y(A.$$.fragment,e),Q=c(e),M=U(e,"DIV",{class:!0});var b=D(M);y(C.$$.fragment,b),N=c(b),k=U(b,"P",{"data-svelte-h":!0}),X(k)!=="svelte-mtd6ds"&&(k.textContent=K),z=c(b),y(J.$$.fragment,b),b.forEach(s),H=c(e),y(B.$$.fragment,e),V=c(e),G=U(e,"P",{}),D(G).forEach(s),this.h()},h(){S(l,"name","hf:doc:metadata"),S(l,"content",ce),S(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S(M,"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,n){I(document.head,l),o(e,d,n),o(e,i,n),o(e,a,n),u(r,e,n),o(e,t,n),u(p,e,n),o(e,Z,n),o(e,f,n),u(_,f,null),I(f,F),I(f,v),I(f,Y),u(T,f,null),o(e,W,n),u(A,e,n),o(e,Q,n),o(e,M,n),u(C,M,null),I(M,N),I(M,k),I(M,z),u(J,M,null),o(e,H,n),u(B,e,n),o(e,V,n),o(e,G,n),R=!0},p(e,[n]){const w={};n&2&&(w.$$scope={dirty:n,ctx:e}),T.$set(w);const b={};n&2&&(b.$$scope={dirty:n,ctx:e}),J.$set(b)},i(e){R||(h(r.$$.fragment,e),h(p.$$.fragment,e),h(_.$$.fragment,e),h(T.$$.fragment,e),h(A.$$.fragment,e),h(C.$$.fragment,e),h(J.$$.fragment,e),h(B.$$.fragment,e),R=!0)},o(e){j(r.$$.fragment,e),j(p.$$.fragment,e),j(_.$$.fragment,e),j(T.$$.fragment,e),j(A.$$.fragment,e),j(C.$$.fragment,e),j(J.$$.fragment,e),j(B.$$.fragment,e),R=!1},d(e){e&&(s(d),s(i),s(a),s(t),s(Z),s(f),s(W),s(Q),s(M),s(H),s(V),s(G)),s(l),$(r,e),$(p,e),$(_),$(T),$(A,e),$(C),$(J),$(B,e)}}}const ce='{"title":"Other","local":"other","sections":[{"title":"profiling_decorator","local":"trl.extras.profiling.profiling_decorator","sections":[],"depth":2},{"title":"profiling_context","local":"trl.extras.profiling.profiling_context","sections":[],"depth":2}],"depth":1}';function fe(E){return ne(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class je extends se{constructor(l){super(),ae(this,l,fe,me,le,{})}}export{je as component};
