import{s as Ze,o as Je,n as xe}from"../chunks/scheduler.d627b047.js";import{S as Ee,i as Fe,g as $,s as i,r as g,A as Pe,h as k,f as n,c as s,j as Q,u as d,x as j,k as H,y as C,a as o,v as f,d as u,t as h,w as b}from"../chunks/index.73c51727.js";import{D as ne}from"../chunks/Docstring.0ad99a5d.js";import{C as Te}from"../chunks/CodeBlock.5f78c87f.js";import{E as ye}from"../chunks/ExampleCodeBlock.e6081cec.js";import{H as te,E as Ge}from"../chunks/index.8df1db42.js";function Ye(W){let r,_="Usage:",m,l,c;return l=new Te({props:{code:"dHJhaW5lciUyMCUzRCUyMERQT1RyYWluZXIoLi4uKSUwQWp1ZGdlJTIwJTNEJTIwUGFpclJNSnVkZ2UoKSUwQXdpbl9yYXRlX2NhbGxiYWNrJTIwJTNEJTIwV2luUmF0ZUNhbGxiYWNrKGp1ZGdlJTNEanVkZ2UlMkMlMjB0cmFpbmVyJTNEdHJhaW5lciklMEF0cmFpbmVyLmFkZF9jYWxsYmFjayh3aW5fcmF0ZV9jYWxsYmFjayk=",highlighted:`trainer = DPOTrainer(...)
judge = PairRMJudge()
win_rate_callback = WinRateCallback(judge=judge, trainer=trainer)
trainer.add_callback(win_rate_callback)`,wrap:!1}}),{c(){r=$("p"),r.textContent=_,m=i(),g(l.$$.fragment)},l(t){r=k(t,"P",{"data-svelte-h":!0}),j(r)!=="svelte-5wyjqd"&&(r.textContent=_),m=s(t),d(l.$$.fragment,t)},m(t,p){o(t,r,p),o(t,m,p),f(l,t,p),c=!0},p:xe,i(t){c||(u(l.$$.fragment,t),c=!0)},o(t){h(l.$$.fragment,t),c=!1},d(t){t&&(n(r),n(m)),b(l,t)}}}function Be(W){let r,_="Usage:",m,l,c;return l=new Te({props:{code:"dHJhaW5lciUyMCUzRCUyMERQT1RyYWluZXIoLi4uKSUwQWNvbXBsZXRpb25zX2NhbGxiYWNrJTIwJTNEJTIwTG9nQ29tcGxldGlvbnNDYWxsYmFjayh0cmFpbmVyJTNEdHJhaW5lciklMEF0cmFpbmVyLmFkZF9jYWxsYmFjayhjb21wbGV0aW9uc19jYWxsYmFjayk=",highlighted:`trainer = DPOTrainer(...)
completions_callback = LogCompletionsCallback(trainer=trainer)
trainer.add_callback(completions_callback)`,wrap:!1}}),{c(){r=$("p"),r.textContent=_,m=i(),g(l.$$.fragment)},l(t){r=k(t,"P",{"data-svelte-h":!0}),j(r)!=="svelte-5wyjqd"&&(r.textContent=_),m=s(t),d(l.$$.fragment,t)},m(t,p){o(t,r,p),o(t,m,p),f(l,t,p),c=!0},p:xe,i(t){c||(u(l.$$.fragment,t),c=!0)},o(t){h(l.$$.fragment,t),c=!1},d(t){t&&(n(r),n(m)),b(l,t)}}}function Ve(W){let r,_="Example:",m,l,c;return l=new Te({props:{code:"IXBpcCUyMGluc3RhbGwlMjB0cmwlNUJtZXJnZWtpdCU1RCUwQSUwQWZyb20lMjB0cmwubWVyZ2VraXRfdXRpbHMlMjBpbXBvcnQlMjBNZXJnZUNvbmZpZyUwQWZyb20lMjB0cmwlMjBpbXBvcnQlMjBNZXJnZU1vZGVsQ2FsbGJhY2slMEElMEFjb25maWclMjAlM0QlMjBNZXJnZUNvbmZpZygpJTBBbWVyZ2VfY2FsbGJhY2slMjAlM0QlMjBNZXJnZU1vZGVsQ2FsbGJhY2soY29uZmlnKSUwQXRyYWluZXIlMjAlM0QlMjBEUE9UcmFpbmVyKC4uLiUyQyUyMGNhbGxiYWNrcyUzRCU1Qm1lcmdlX2NhbGxiYWNrJTVEKQ==",highlighted:`!pip install trl[mergekit]

<span class="hljs-keyword">from</span> trl.mergekit_utils <span class="hljs-keyword">import</span> MergeConfig
<span class="hljs-keyword">from</span> trl <span class="hljs-keyword">import</span> MergeModelCallback

config = MergeConfig()
merge_callback = MergeModelCallback(config)
trainer = DPOTrainer(..., callbacks=[merge_callback])`,wrap:!1}}),{c(){r=$("p"),r.textContent=_,m=i(),g(l.$$.fragment)},l(t){r=k(t,"P",{"data-svelte-h":!0}),j(r)!=="svelte-11lpom8"&&(r.textContent=_),m=s(t),d(l.$$.fragment,t)},m(t,p){o(t,r,p),o(t,m,p),f(l,t,p),c=!0},p:xe,i(t){c||(u(l.$$.fragment,t),c=!0)},o(t){h(l.$$.fragment,t),c=!1},d(t){t&&(n(r),n(m)),b(l,t)}}}function Ie(W){let r,_,m,l,c,t,p,re,x,L,he,D,je="Callback to synchronize the model with a reference model.",le,Z,oe,T,J,be,S,We="A <code>TrainerCallback</code> that displays the progress of training or evaluation using Rich.",ie,E,se,v,F,$e,q,Re='A <a href="https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback" rel="nofollow">TrainerCallback</a> that computes the win rate of a model based on a reference.',ke,O,Ne=`It generates completions using prompts from the evaluation dataset and compares the trained model’s outputs against
a reference. The reference is either the initial version of the model (before training) or the reference model, if
available in the trainer. During each evaluation step, a judge determines how often the trained model’s completions
win against the reference using a judge. The win rate is then logged in the trainer’s logs under the key
<code>&quot;eval_win_rate&quot;</code>.`,Ce,R,ce,P,me,M,G,_e,A,Ue='A <a href="https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback" rel="nofollow">TrainerCallback</a> that logs completions to Weights &amp; Biases and/or Comet.',ve,N,pe,Y,ge,w,B,Me,z,Le='A <a href="https://huggingface.co/docs/transformers/main/en/main_classes/callback#transformers.TrainerCallback" rel="nofollow">TrainerCallback</a> that merges the policy model (the model being trained) with another model based on a merge configuration.',we,U,de,V,fe,ae,ue;return c=new te({props:{title:"Callbacks",local:"callbacks",headingTag:"h1"}}),p=new te({props:{title:"SyncRefModelCallback",local:"trl.SyncRefModelCallback",headingTag:"h2"}}),L=new ne({props:{name:"class trl.SyncRefModelCallback",anchor:"trl.SyncRefModelCallback",parameters:[{name:"ref_model",val:": typing.Union[transformers.modeling_utils.PreTrainedModel, torch.nn.modules.module.Module]"},{name:"accelerator",val:": typing.Optional[accelerate.accelerator.Accelerator]"}],source:"https://github.com/huggingface/trl/blob/main/trl/trainer/callbacks.py#L93"}}),Z=new te({props:{title:"RichProgressCallback",local:"trl.RichProgressCallback",headingTag:"h2"}}),J=new ne({props:{name:"class trl.RichProgressCallback",anchor:"trl.RichProgressCallback",parameters:[],source:"https://github.com/huggingface/trl/blob/main/trl/trainer/callbacks.py#L134"}}),E=new te({props:{title:"WinRateCallback",local:"trl.WinRateCallback",headingTag:"h2"}}),F=new ne({props:{name:"class trl.WinRateCallback",anchor:"trl.WinRateCallback",parameters:[{name:"judge",val:": BasePairwiseJudge"},{name:"trainer",val:": Trainer"},{name:"generation_config",val:": typing.Optional[transformers.generation.configuration_utils.GenerationConfig] = None"},{name:"num_prompts",val:": typing.Optional[int] = None"},{name:"shuffle_order",val:": bool = True"},{name:"use_soft_judge",val:": bool = False"}],parametersDescription:[{anchor:"trl.WinRateCallback.judge",description:`<strong>judge</strong> (<code>BasePairwiseJudge</code>) &#x2014;
The judge to use for comparing completions.`,name:"judge"},{anchor:"trl.WinRateCallback.trainer",description:`<strong>trainer</strong> (<code>Trainer</code>) &#x2014;
Trainer to which the callback will be attached. The trainer&#x2019;s evaluation dataset must include a <code>&quot;prompt&quot;</code>
column containing the prompts for generating completions. If the <code>Trainer</code> has a reference model (via the
<code>ref_model</code> attribute), it will use this reference model for generating the reference completions;
otherwise, it defaults to using the initial model.`,name:"trainer"},{anchor:"trl.WinRateCallback.generation_config",description:`<strong>generation_config</strong> (<code>GenerationConfig</code>, <em>optional</em>) &#x2014;
The generation config to use for generating completions.`,name:"generation_config"},{anchor:"trl.WinRateCallback.num_prompts",description:`<strong>num_prompts</strong> (<code>int</code> or <code>None</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
The number of prompts to generate completions for. If not provided, defaults to the number of examples
in the evaluation dataset.`,name:"num_prompts"},{anchor:"trl.WinRateCallback.shuffle_order",description:`<strong>shuffle_order</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether to shuffle the order of the completions before judging.`,name:"shuffle_order"},{anchor:"trl.WinRateCallback.use_soft_judge",description:`<strong>use_soft_judge</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to use a soft judge that returns a win probability between 0 and 1 for the first completion vs the
second.`,name:"use_soft_judge"}],source:"https://github.com/huggingface/trl/blob/main/trl/trainer/callbacks.py#L224"}}),R=new ye({props:{anchor:"trl.WinRateCallback.example",$$slots:{default:[Ye]},$$scope:{ctx:W}}}),P=new te({props:{title:"LogCompletionsCallback",local:"trl.LogCompletionsCallback",headingTag:"h2"}}),G=new ne({props:{name:"class trl.LogCompletionsCallback",anchor:"trl.LogCompletionsCallback",parameters:[{name:"trainer",val:": Trainer"},{name:"generation_config",val:": typing.Optional[transformers.generation.configuration_utils.GenerationConfig] = None"},{name:"num_prompts",val:": typing.Optional[int] = None"},{name:"freq",val:": typing.Optional[int] = None"}],parametersDescription:[{anchor:"trl.LogCompletionsCallback.trainer",description:`<strong>trainer</strong> (<code>Trainer</code>) &#x2014;
Trainer to which the callback will be attached. The trainer&#x2019;s evaluation dataset must include a <code>&quot;prompt&quot;</code>
column containing the prompts for generating completions.`,name:"trainer"},{anchor:"trl.LogCompletionsCallback.generation_config",description:`<strong>generation_config</strong> (<code>GenerationConfig</code>, <em>optional</em>) &#x2014;
The generation config to use for generating completions.`,name:"generation_config"},{anchor:"trl.LogCompletionsCallback.num_prompts",description:`<strong>num_prompts</strong> (<code>int</code> or <code>None</code>, <em>optional</em>) &#x2014;
The number of prompts to generate completions for. If not provided, defaults to the number of examples in the evaluation dataset.`,name:"num_prompts"},{anchor:"trl.LogCompletionsCallback.freq",description:`<strong>freq</strong> (<code>int</code> or <code>None</code>, <em>optional</em>) &#x2014;
The frequency at which to log completions. If not provided, defaults to the trainer&#x2019;s <code>eval_steps</code>.`,name:"freq"}],source:"https://github.com/huggingface/trl/blob/main/trl/trainer/callbacks.py#L420"}}),N=new ye({props:{anchor:"trl.LogCompletionsCallback.example",$$slots:{default:[Be]},$$scope:{ctx:W}}}),Y=new te({props:{title:"MergeModelCallback",local:"trl.MergeModelCallback",headingTag:"h2"}}),B=new ne({props:{name:"class trl.MergeModelCallback",anchor:"trl.MergeModelCallback",parameters:[{name:"merge_config",val:": typing.Optional[ForwardRef('MergeConfig')] = None"},{name:"merge_at_every_checkpoint",val:": bool = False"},{name:"push_to_hub",val:": bool = False"}],parametersDescription:[{anchor:"trl.MergeModelCallback.merge_config",description:`<strong>merge_config</strong> (<code>MergeConfig</code>, <em>optional</em>, defaults to <code>None</code>) &#x2014;
Configuration used for the merging process. If not provided, the default <code>MergeConfig</code> is used.`,name:"merge_config"},{anchor:"trl.MergeModelCallback.merge_at_every_checkpoint",description:`<strong>merge_at_every_checkpoint</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to merge the model at every checkpoint.`,name:"merge_at_every_checkpoint"},{anchor:"trl.MergeModelCallback.push_to_hub",description:`<strong>push_to_hub</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) &#x2014;
Whether to push the merged model to the Hub after merging.`,name:"push_to_hub"}],source:"https://github.com/huggingface/trl/blob/main/trl/trainer/callbacks.py#L511"}}),U=new ye({props:{anchor:"trl.MergeModelCallback.example",$$slots:{default:[Ve]},$$scope:{ctx:W}}}),V=new Ge({props:{source:"https://github.com/huggingface/trl/blob/main/docs/source/callbacks.md"}}),{c(){r=$("meta"),_=i(),m=$("p"),l=i(),g(c.$$.fragment),t=i(),g(p.$$.fragment),re=i(),x=$("div"),g(L.$$.fragment),he=i(),D=$("p"),D.textContent=je,le=i(),g(Z.$$.fragment),oe=i(),T=$("div"),g(J.$$.fragment),be=i(),S=$("p"),S.innerHTML=We,ie=i(),g(E.$$.fragment),se=i(),v=$("div"),g(F.$$.fragment),$e=i(),q=$("p"),q.innerHTML=Re,ke=i(),O=$("p"),O.innerHTML=Ne,Ce=i(),g(R.$$.fragment),ce=i(),g(P.$$.fragment),me=i(),M=$("div"),g(G.$$.fragment),_e=i(),A=$("p"),A.innerHTML=Ue,ve=i(),g(N.$$.fragment),pe=i(),g(Y.$$.fragment),ge=i(),w=$("div"),g(B.$$.fragment),Me=i(),z=$("p"),z.innerHTML=Le,we=i(),g(U.$$.fragment),de=i(),g(V.$$.fragment),fe=i(),ae=$("p"),this.h()},l(e){const a=Pe("svelte-u9bgzb",document.head);r=k(a,"META",{name:!0,content:!0}),a.forEach(n),_=s(e),m=k(e,"P",{}),Q(m).forEach(n),l=s(e),d(c.$$.fragment,e),t=s(e),d(p.$$.fragment,e),re=s(e),x=k(e,"DIV",{class:!0});var I=Q(x);d(L.$$.fragment,I),he=s(I),D=k(I,"P",{"data-svelte-h":!0}),j(D)!=="svelte-1003ujb"&&(D.textContent=je),I.forEach(n),le=s(e),d(Z.$$.fragment,e),oe=s(e),T=k(e,"DIV",{class:!0});var X=Q(T);d(J.$$.fragment,X),be=s(X),S=k(X,"P",{"data-svelte-h":!0}),j(S)!=="svelte-4ypj8u"&&(S.innerHTML=We),X.forEach(n),ie=s(e),d(E.$$.fragment,e),se=s(e),v=k(e,"DIV",{class:!0});var y=Q(v);d(F.$$.fragment,y),$e=s(y),q=k(y,"P",{"data-svelte-h":!0}),j(q)!=="svelte-16rvof"&&(q.innerHTML=Re),ke=s(y),O=k(y,"P",{"data-svelte-h":!0}),j(O)!=="svelte-bpyf2p"&&(O.innerHTML=Ne),Ce=s(y),d(R.$$.fragment,y),y.forEach(n),ce=s(e),d(P.$$.fragment,e),me=s(e),M=k(e,"DIV",{class:!0});var K=Q(M);d(G.$$.fragment,K),_e=s(K),A=k(K,"P",{"data-svelte-h":!0}),j(A)!=="svelte-1rlpx8d"&&(A.innerHTML=Ue),ve=s(K),d(N.$$.fragment,K),K.forEach(n),pe=s(e),d(Y.$$.fragment,e),ge=s(e),w=k(e,"DIV",{class:!0});var ee=Q(w);d(B.$$.fragment,ee),Me=s(ee),z=k(ee,"P",{"data-svelte-h":!0}),j(z)!=="svelte-z8aghu"&&(z.innerHTML=Le),we=s(ee),d(U.$$.fragment,ee),ee.forEach(n),de=s(e),d(V.$$.fragment,e),fe=s(e),ae=k(e,"P",{}),Q(ae).forEach(n),this.h()},h(){H(r,"name","hf:doc:metadata"),H(r,"content",Xe),H(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),H(w,"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,a){C(document.head,r),o(e,_,a),o(e,m,a),o(e,l,a),f(c,e,a),o(e,t,a),f(p,e,a),o(e,re,a),o(e,x,a),f(L,x,null),C(x,he),C(x,D),o(e,le,a),f(Z,e,a),o(e,oe,a),o(e,T,a),f(J,T,null),C(T,be),C(T,S),o(e,ie,a),f(E,e,a),o(e,se,a),o(e,v,a),f(F,v,null),C(v,$e),C(v,q),C(v,ke),C(v,O),C(v,Ce),f(R,v,null),o(e,ce,a),f(P,e,a),o(e,me,a),o(e,M,a),f(G,M,null),C(M,_e),C(M,A),C(M,ve),f(N,M,null),o(e,pe,a),f(Y,e,a),o(e,ge,a),o(e,w,a),f(B,w,null),C(w,Me),C(w,z),C(w,we),f(U,w,null),o(e,de,a),f(V,e,a),o(e,fe,a),o(e,ae,a),ue=!0},p(e,[a]){const I={};a&2&&(I.$$scope={dirty:a,ctx:e}),R.$set(I);const X={};a&2&&(X.$$scope={dirty:a,ctx:e}),N.$set(X);const y={};a&2&&(y.$$scope={dirty:a,ctx:e}),U.$set(y)},i(e){ue||(u(c.$$.fragment,e),u(p.$$.fragment,e),u(L.$$.fragment,e),u(Z.$$.fragment,e),u(J.$$.fragment,e),u(E.$$.fragment,e),u(F.$$.fragment,e),u(R.$$.fragment,e),u(P.$$.fragment,e),u(G.$$.fragment,e),u(N.$$.fragment,e),u(Y.$$.fragment,e),u(B.$$.fragment,e),u(U.$$.fragment,e),u(V.$$.fragment,e),ue=!0)},o(e){h(c.$$.fragment,e),h(p.$$.fragment,e),h(L.$$.fragment,e),h(Z.$$.fragment,e),h(J.$$.fragment,e),h(E.$$.fragment,e),h(F.$$.fragment,e),h(R.$$.fragment,e),h(P.$$.fragment,e),h(G.$$.fragment,e),h(N.$$.fragment,e),h(Y.$$.fragment,e),h(B.$$.fragment,e),h(U.$$.fragment,e),h(V.$$.fragment,e),ue=!1},d(e){e&&(n(_),n(m),n(l),n(t),n(re),n(x),n(le),n(oe),n(T),n(ie),n(se),n(v),n(ce),n(me),n(M),n(pe),n(ge),n(w),n(de),n(fe),n(ae)),n(r),b(c,e),b(p,e),b(L),b(Z,e),b(J),b(E,e),b(F),b(R),b(P,e),b(G),b(N),b(Y,e),b(B),b(U),b(V,e)}}}const Xe='{"title":"Callbacks","local":"callbacks","sections":[{"title":"SyncRefModelCallback","local":"trl.SyncRefModelCallback","sections":[],"depth":2},{"title":"RichProgressCallback","local":"trl.RichProgressCallback","sections":[],"depth":2},{"title":"WinRateCallback","local":"trl.WinRateCallback","sections":[],"depth":2},{"title":"LogCompletionsCallback","local":"trl.LogCompletionsCallback","sections":[],"depth":2},{"title":"MergeModelCallback","local":"trl.MergeModelCallback","sections":[],"depth":2}],"depth":1}';function Qe(W){return Je(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ze extends Ee{constructor(r){super(),Fe(this,r,Qe,Ie,Ze,{})}}export{ze as component};
