import{S as fc,i as Mc,s as bc,e as l,k as c,w as m,t as a,M as wc,c as o,d as s,m as h,a as r,x as u,h as n,b as d,G as t,g as p,y,q as g,o as f,B as M,v as vc}from"../chunks/vendor-hf-doc-builder.js";import{T as jc}from"../chunks/Tip-hf-doc-builder.js";import{I as k}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as _}from"../chunks/CodeBlock-hf-doc-builder.js";function Tc(ha){let w,ae;return{c(){w=l("p"),ae=a("The API for the streamer classes is still under development and may change in the future.")},l(j){w=o(j,"P",{});var J=r(w);ae=n(J,"The API for the streamer classes is still under development and may change in the future."),J.forEach(s)},m(j,J){p(j,w,J),t(w,ae)},d(j){j&&s(w)}}}function Uc(ha){let w,ae,j,J,Ht,Ge,zn,Qt,xn,da,ht,An,ma,ne,Hn,dt,Qn,Yn,ua,X,Yt,mt,Sn,Fn,St,ut,qn,Dn,Ft,yt,Ln,ya,gt,Pn,ga,le,Kn,qt,On,el,fa,ft,tl,Ma,V,Dt,sl,al,Lt,nl,ll,Pt,ol,ba,H,oe,Kt,Be,rl,Ot,il,wa,C,pl,Mt,cl,hl,es,dl,ml,va,re,ul,ts,yl,gl,ja,Ie,Ta,ie,fl,ss,Ml,bl,Ua,bt,wl,Ja,Q,pe,as,Xe,vl,ns,jl,ka,R,Tl,ls,Ul,Jl,os,kl,_l,_a,Ve,Za,wt,Zl,Ea,Z,vt,rs,El,Wl,Gl,jt,is,Bl,Il,Xl,ce,ps,Vl,Cl,cs,Rl,Nl,$l,Tt,hs,zl,xl,Wa,Y,he,ds,Ce,Al,ms,Hl,Ga,Ut,Ql,Ba,E,Re,Yl,Jt,Sl,Fl,ql,us,Dl,Ll,S,Pl,kt,Kl,Ol,ys,eo,to,so,F,ao,gs,no,lo,fs,oo,ro,Ia,Ne,Xa,W,io,Ms,po,co,_t,ho,mo,Zt,uo,yo,Va,$e,Ca,q,de,bs,ze,go,ws,fo,Ra,b,Mo,vs,bo,wo,js,vo,jo,Ts,To,Uo,Us,Jo,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&gt; </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;distilgpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.generation_config
GenerationConfig {
    <span class="hljs-string">&quot;bos_token_id&quot;</span>: <span class="hljs-number">50256</span>,
    <span class="hljs-string">&quot;eos_token_id&quot;</span>: <span class="hljs-number">50256</span>,
}`}}),Xe=new k({}),Ve=new _({props:{code:"bXlfbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBudW1fYmVhbXMlM0Q0JTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSk=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>my_model.generate(**inputs, num_beams=<span class="hljs-number">4</span>, do_sample=<span class="hljs-literal">True</span>)'}}),Ce=new k({}),Ne=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwR2VuZXJhdGlvbkNvbmZpZyUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKCUyMm15X2FjY291bnQlMkZteV9tb2RlbCUyMiklMEFnZW5lcmF0aW9uX2NvbmZpZyUyMCUzRCUyMEdlbmVyYXRpb25Db25maWcoJTBBJTIwJTIwJTIwJTIwbWF4X25ld190b2tlbnMlM0Q1MCUyQyUyMGRvX3NhbXBsZSUzRFRydWUlMkMlMjB0b3BfayUzRDUwJTJDJTIwZW9zX3Rva2VuX2lkJTNEbW9kZWwuY29uZmlnLmVvc190b2tlbl9pZCUwQSklMEFnZW5lcmF0aW9uX2NvbmZpZy5zYXZlX3ByZXRyYWluZWQoJTIybXlfYWNjb3VudCUyRm15X21vZGVsJTIyJTJDJTIwcHVzaF90b19odWIlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, GenerationConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;my_account/my_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generation_config = GenerationConfig(
<span class="hljs-meta">... </span>    max_new_tokens=<span class="hljs-number">50</span>, do_sample=<span class="hljs-literal">True</span>, top_k=<span class="hljs-number">50</span>, eos_token_id=model.config.eos_token_id
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>generation_config.save_pretrained(<span class="hljs-string">&quot;my_account/my_model&quot;</span>, push_to_hub=<span class="hljs-literal">True</span>)`}}),$e=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBHZW5lcmF0aW9uQ29uZmlnJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIydDUtc21hbGwlMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKCUyMnQ1LXNtYWxsJTIyKSUwQSUwQXRyYW5zbGF0aW9uX2dlbmVyYXRpb25fY29uZmlnJTIwJTNEJTIwR2VuZXJhdGlvbkNvbmZpZyglMEElMjAlMjAlMjAlMjBudW1fYmVhbXMlM0Q0JTJDJTBBJTIwJTIwJTIwJTIwZWFybHlfc3RvcHBpbmclM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZGVjb2Rlcl9zdGFydF90b2tlbl9pZCUzRDAlMkMlMEElMjAlMjAlMjAlMjBlb3NfdG9rZW5faWQlM0Rtb2RlbC5jb25maWcuZW9zX3Rva2VuX2lkJTJDJTBBJTIwJTIwJTIwJTIwcGFkX3Rva2VuJTNEbW9kZWwuY29uZmlnLnBhZF90b2tlbl9pZCUyQyUwQSklMEElMEElMjMlMjBUaXAlM0ElMjBhZGQlMjAlNjBwdXNoX3RvX2h1YiUzRFRydWUlNjAlMjB0byUyMHB1c2glMjB0byUyMHRoZSUyMEh1YiUwQXRyYW5zbGF0aW9uX2dlbmVyYXRpb25fY29uZmlnLnNhdmVfcHJldHJhaW5lZCglMjIlMkZ0bXAlMjIlMkMlMjAlMjJ0cmFuc2xhdGlvbl9nZW5lcmF0aW9uX2NvbmZpZy5qc29uJTIyKSUwQSUwQSUyMyUyMFlvdSUyMGNvdWxkJTIwdGhlbiUyMHVzZSUyMHRoZSUyMG5hbWVkJTIwZ2VuZXJhdGlvbiUyMGNvbmZpZyUyMGZpbGUlMjB0byUyMHBhcmFtZXRlcml6ZSUyMGdlbmVyYXRpb24lMEFnZW5lcmF0aW9uX2NvbmZpZyUyMCUzRCUyMEdlbmVyYXRpb25Db25maWcuZnJvbV9wcmV0cmFpbmVkKCUyMiUyRnRtcCUyMiUyQyUyMCUyMnRyYW5zbGF0aW9uX2dlbmVyYXRpb25fY29uZmlnLmpzb24lMjIpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMnRyYW5zbGF0ZSUyMEVuZ2xpc2glMjB0byUyMEZyZW5jaCUzQSUyMENvbmZpZ3VyYXRpb24lMjBmaWxlcyUyMGFyZSUyMGVhc3klMjB0byUyMHVzZSElMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMGdlbmVyYXRpb25fY29uZmlnJTNEZ2VuZXJhdGlvbl9jb25maWcpJTBBcHJpbnQodG9rZW5pemVyLmJhdGNoX2RlY29kZShvdXRwdXRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;t5-small&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;t5-small&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translation_generation_config = GenerationConfig(
<span class="hljs-meta">... </span>    num_beams=<span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    early_stopping=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    decoder_start_token_id=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>    eos_token_id=model.config.eos_token_id,
<span class="hljs-meta">... </span>    pad_token=model.config.pad_token_id,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Tip: add \`push_to_hub=True\` to push to the Hub</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>translation_generation_config.save_pretrained(<span class="hljs-string">&quot;/tmp&quot;</span>, <span class="hljs-string">&quot;translation_generation_config.json&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># You could then use the named generation config file to parameterize generation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>generation_config = GenerationConfig.from_pretrained(<span class="hljs-string">&quot;/tmp&quot;</span>, <span class="hljs-string">&quot;translation_generation_config.json&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(<span class="hljs-string">&quot;translate English to French: Configuration files are easy to use!&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, generation_config=generation_config)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>))
[<span class="hljs-string">&#x27;Les fichiers de configuration sont faciles \xE0 utiliser!&#x27;</span>]`}}),ze=new k({}),me=new jc({props:{warning:!0,$$slots:{default:[Tc]},$$scope:{ctx:ha}}}),xe=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMFRleHRTdHJlYW1lciUwQSUwQXRvayUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMmdwdDIlMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyZ3B0MiUyMiklMEFpbnB1dHMlMjAlM0QlMjB0b2soJTVCJTIyQW4lMjBpbmNyZWFzaW5nJTIwc2VxdWVuY2UlM0ElMjBvbmUlMkMlMjIlNUQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQXN0cmVhbWVyJTIwJTNEJTIwVGV4dFN0cmVhbWVyKHRvayklMEElMEElMjMlMjBEZXNwaXRlJTIwcmV0dXJuaW5nJTIwdGhlJTIwdXN1YWwlMjBvdXRwdXQlMkMlMjB0aGUlMjBzdHJlYW1lciUyMHdpbGwlMjBhbHNvJTIwcHJpbnQlMjB0aGUlMjBnZW5lcmF0ZWQlMjB0ZXh0JTIwdG8lMjBzdGRvdXQuJTBBXyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwc3RyZWFtZXIlM0RzdHJlYW1lciUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMjAp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, TextStreamer

<span class="hljs-meta">&gt;&gt;&gt; </span>tok = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;gpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;gpt2&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tok([<span class="hljs-string">&quot;An increasing sequence: one,&quot;</span>], return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>streamer = TextStreamer(tok)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Despite returning the usual output, the streamer will also print the generated text to stdout.</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>_ = model.generate(**inputs, streamer=streamer, max_new_tokens=<span class="hljs-number">20</span>)
An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,`}}),Ae=new k({}),Qe=new k({}),Ye=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkklMjBsb29rJTIwZm9yd2FyZCUyMHRvJTIyJTBBY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGdwdDIlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihwcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;I look forward to&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;distilgpt2&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;I look forward to seeing you all again!\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n&#x27;</span>]`}}),Se=new k({}),De=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJncHQyLWxhcmdlJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkh1Z2dpbmclMjBGYWNlJTIwQ29tcGFueSUyMGlzJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHByb21wdCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwcGVuYWx0eV9hbHBoYSUzRDAuNiUyQyUyMHRvcF9rJTNENCUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTAwKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;gpt2-large&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;Hugging Face Company is&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, penalty_alpha=<span class="hljs-number">0.6</span>, top_k=<span class="hljs-number">4</span>, max_new_tokens=<span class="hljs-number">100</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;Hugging Face Company is a family owned and operated business. We pride ourselves on being the best
in the business and our customer service is second to none.\\n\\nIf you have any questions about our
products or services, feel free to contact us at any time. We look forward to hearing from you!&#x27;</span>]`}}),Le=new k({}),Pe=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUyQyUyMHNldF9zZWVkJTBBc2V0X3NlZWQoMCklMjAlMjAlMjMlMjBGb3IlMjByZXByb2R1Y2liaWxpdHklMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZ3B0Mi1sYXJnZSUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJUb2RheSUyMHdhcyUyMGFuJTIwYW1hemluZyUyMGRheSUyMGJlY2F1c2UlMjIlMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIocHJvbXB0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBkb19zYW1wbGUlM0RUcnVlJTJDJTIwbnVtX2JlYW1zJTNEMSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTAwKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM, set_seed
<span class="hljs-meta">&gt;&gt;&gt; </span>set_seed(<span class="hljs-number">0</span>)  <span class="hljs-comment"># For reproducibility</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;gpt2-large&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;Today was an amazing day because&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, do_sample=<span class="hljs-literal">True</span>, num_beams=<span class="hljs-number">1</span>, max_new_tokens=<span class="hljs-number">100</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;Today was an amazing day because when you go to the World Cup and you don\\&#x27;t, or when you don\\&#x27;t get invited,
that\\&#x27;s a terrible feeling.&quot;&#x27;</span>]`}}),Ke=new k({}),Oe=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkl0JTIwaXMlMjBhc3RvbmlzaGluZyUyMGhvdyUyMG9uZSUyMGNhbiUyMiUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJncHQyLW1lZGl1bSUyMiUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHByb21wdCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEElMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBudW1fYmVhbXMlM0Q1JTJDJTIwbWF4X25ld190b2tlbnMlM0Q1MCklMEF0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dHB1dHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;It is astonishing how one can&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;gpt2-medium&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, num_beams=<span class="hljs-number">5</span>, max_new_tokens=<span class="hljs-number">50</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;It is astonishing how one can have such a profound impact on the lives of so many people in such a short period of
time.&quot;\\n\\nHe added: &quot;I am very proud of the work I have been able to do in the last few years.\\n\\n&quot;I have&#x27;</span>]`}}),et=new k({}),tt=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0lMkMlMjBzZXRfc2VlZCUwQXNldF9zZWVkKDApJTIwJTIwJTIzJTIwRm9yJTIwcmVwcm9kdWNpYmlsaXR5JTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIydHJhbnNsYXRlJTIwRW5nbGlzaCUyMHRvJTIwR2VybWFuJTNBJTIwVGhlJTIwaG91c2UlMjBpcyUyMHdvbmRlcmZ1bC4lMjIlMEFjaGVja3BvaW50JTIwJTNEJTIwJTIydDUtc21hbGwlMjIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihwcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZSgqKmlucHV0cyUyQyUyMG51bV9iZWFtcyUzRDUlMkMlMjBkb19zYW1wbGUlM0RUcnVlKSUwQXRva2VuaXplci5kZWNvZGUob3V0cHV0cyU1QjAlNUQlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSeq2SeqLM, set_seed
<span class="hljs-meta">&gt;&gt;&gt; </span>set_seed(<span class="hljs-number">0</span>)  <span class="hljs-comment"># For reproducibility</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;translate English to German: The house is wonderful.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;t5-small&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, num_beams=<span class="hljs-number">5</span>, do_sample=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-string">&#x27;Das Haus ist wunderbar.&#x27;</span>`}}),st=new k({}),nt=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0lMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyZ29vZ2xlJTJGcGVnYXN1cy14c3VtJTIyJTBBcHJvbXB0JTIwJTNEJTIwKCUwQSUyMCUyMCUyMCUyMCUyMlRoZSUyMFBlcm1hY3VsdHVyZSUyMERlc2lnbiUyMFByaW5jaXBsZXMlMjBhcmUlMjBhJTIwc2V0JTIwb2YlMjB1bml2ZXJzYWwlMjBkZXNpZ24lMjBwcmluY2lwbGVzJTIwJTIyJTBBJTIwJTIwJTIwJTIwJTIydGhhdCUyMGNhbiUyMGJlJTIwYXBwbGllZCUyMHRvJTIwYW55JTIwbG9jYXRpb24lMkMlMjBjbGltYXRlJTIwYW5kJTIwY3VsdHVyZSUyQyUyMGFuZCUyMHRoZXklMjBhbGxvdyUyMHVzJTIwdG8lMjBkZXNpZ24lMjAlMjIlMEElMjAlMjAlMjAlMjAlMjJ0aGUlMjBtb3N0JTIwZWZmaWNpZW50JTIwYW5kJTIwc3VzdGFpbmFibGUlMjBodW1hbiUyMGhhYml0YXRpb24lMjBhbmQlMjBmb29kJTIwcHJvZHVjdGlvbiUyMHN5c3RlbXMuJTIwJTIyJTBBJTIwJTIwJTIwJTIwJTIyUGVybWFjdWx0dXJlJTIwaXMlMjBhJTIwZGVzaWduJTIwc3lzdGVtJTIwdGhhdCUyMGVuY29tcGFzc2VzJTIwYSUyMHdpZGUlMjB2YXJpZXR5JTIwb2YlMj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91cHMlM0Q1JTJDJTIwbWF4X25ld190b2tlbnMlM0QzMCUyQyUyMGRpdmVyc2l0eV9wZW5hbHR5JTNEMS4wKSUwQXRva2VuaXplci5kZWNvZGUob3V0cHV0cyU1QjAlNUQlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSeq2SeqLM

<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;google/pegasus-xsum&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = (
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;The Permaculture Design Principles are a set of universal design principles &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;that can be applied to any location, climate and culture, and they allow us to design &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;the most efficient and sustainable human habitation and food production systems. &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Permaculture is a design system that encompasses a wide variety of disciplines, such &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;as ecology, landscape design, environmental science and energy conservation, and the &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;Permaculture design principles are drawn from these various disciplines. Each individual &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;design principle itself embodies a complete conceptual framework based on sound &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;scientific principles. When we bring all these separate  principles together, we can &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;create a design system that both looks at whole systems, the parts that these systems &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;consist of, and how those parts interact with each other to create a complex, dynamic, &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;living system. Each design principle serves as a tool that allows us to integrate all &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;the separate parts of a design, referred to as elements, into a functional, synergistic, &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;whole system, where the elements harmoniously interact and work together in the most &quot;</span>
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;efficient way possible.&quot;</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, num_beams=<span class="hljs-number">5</span>, num_beam_groups=<span class="hljs-number">5</span>, max_new_tokens=<span class="hljs-number">30</span>, diversity_penalty=<span class="hljs-number">1.0</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-string">&#x27;The Design Principles are a set of universal design principles that can be applied to any location, climate and
culture, and they allow us to design the&#x27;</span>`}}),lt=new k({}),rt=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkFsaWNlJTIwYW5kJTIwQm9iJTIyJTBBY2hlY2twb2ludCUyMCUzRCUyMCUyMkVsZXV0aGVyQUklMkZweXRoaWEtMS40Yi1kZWR1cGVkJTIyJTBBYXNzaXN0YW50X2NoZWNrcG9pbnQlMjAlM0QlMjAlMjJFbGV1dGhlckFJJTJGcHl0aGlhLTE2MG0tZGVkdXBlZCUyMiUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHByb21wdCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFhc3Npc3RhbnRfbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoYXNzaXN0YW50X2NoZWNrcG9pbnQpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqaW5wdXRzJTJDJTIwYXNzaXN0YW50X21vZGVsJTNEYXNzaXN0YW50X21vZGVsKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUob3V0cHV0cyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;Alice and Bob&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;EleutherAI/pythia-1.4b-deduped&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>assistant_checkpoint = <span class="hljs-string">&quot;EleutherAI/pythia-160m-deduped&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>assistant_model = AutoModelForCausalLM.from_pretrained(assistant_checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, assistant_model=assistant_model)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;Alice and Bob are sitting in a bar. Alice is drinking a beer and Bob is drinking a&#x27;</span>]`}}),it=new _({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUyQyUyMHNldF9zZWVkJTBBc2V0X3NlZWQoNDIpJTIwJTIwJTIzJTIwRm9yJTIwcmVwcm9kdWNpYmlsaXR5JTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQWxpY2UlMjBhbmQlMjBCb2IlMjIlMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyRWxldXRoZXJBSSUyRnB5dGhpYS0xLjRiLWRlZHVwZWQlMjIlMEFhc3Npc3RhbnRfY2hlY2twb2ludCUyMCUzRCUyMCUyMkVsZXV0aGVyQUklMkZweXRoaWEtMTYwbS1kZWR1cGVkJTIyJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCklMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIocHJvbXB0JTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQWFzc2lzdGFudF9tb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChhc3Npc3RhbnRfY2hlY2twb2ludCklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoKippbnB1dHMlMkMlMjBhc3Npc3RhbnRfbW9kZWwlM0Rhc3Npc3RhbnRfbW9kZWwlMkMlMjBkb19zYW1wbGUlM0RUcnVlJTJDJTIwdGVtcGVyYXR1cmUlM0QwLjUpJTBBdG9rZW5pemVyLmJhdGNoX2RlY29kZShvdXRwdXRzJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer, set_seed
<span class="hljs-meta">&gt;&gt;&gt; </span>set_seed(<span class="hljs-number">42</span>)  <span class="hljs-comment"># For reproducibility</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;Alice and Bob&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>checkpoint = <span class="hljs-string">&quot;EleutherAI/pythia-1.4b-deduped&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>assistant_checkpoint = <span class="hljs-string">&quot;EleutherAI/pythia-160m-deduped&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForCausalLM.from_pretrained(checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>assistant_model = AutoModelForCausalLM.from_pretrained(assistant_checkpoint)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(**inputs, assistant_model=assistant_model, do_sample=<span class="hljs-literal">True</span>, temperature=<span class="hljs-number">0.5</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)
[<span class="hljs-string">&#x27;Alice and Bob are going to the same party. It is a small party, in a small&#x27;</span>]`}}),{c(){w=l("meta"),ae=c(),j=l("h1"),J=l("a"),Ht=l("span"),m(Ge.$$.fragment),zn=c(),Qt=l("span"),xn=a("Text generation strategies"),da=c(),ht=l("p"),An=a(`Text generation is essential to many NLP tasks, such as open-ended text generation, summarization, translation, and
more. It also plays a role in a variety of mixed-modality applications that have text as an output like speech-to-text
and vision-to-text. Some of the models that can generate text include
GPT2, XLNet, OpenAI GPT, CTRL, TransformerXL, XLM, Bart, T5, GIT, Whisper.`),ma=c(),ne=l("p"),Hn=a("Check out a few examples that use "),dt=l("a"),Qn=a("generate()"),Yn=a(` method to produce
text outputs for different tasks:`),ua=c(),X=l("ul"),Yt=l("li"),mt=l("a"),Sn=a("Text summarization"),Fn=c(),St=l("li"),ut=l("a"),qn=a("Image captioning"),Dn=c(),Ft=l("li"),yt=l("a"),Ln=a("Audio transcription"),ya=c(),gt=l("p"),Pn=a(`Note that the inputs to the generate method depend on the model\u2019s modality. They are returned by the model\u2019s preprocessor
class, such as AutoTokenizer or AutoProcessor. If a model\u2019s preprocessor creates more than one kind of input, pass all
the inputs to generate(). You can learn more about the individual model\u2019s preprocessor in the corresponding model\u2019s documentation.`),ga=c(),le=l("p"),Kn=a(`The process of selecting output tokens to generate text is known as decoding, and you can customize the decoding strategy
that the `),qt=l("code"),On=a("generate()"),el=a(` method will use. Modifying a decoding strategy does not change the values of any trainable parameters.
However, it can have a noticeable impact on the quality of the generated output. It can help reduce repetition in the text
and make it more coherent.`),fa=c(),ft=l("p"),tl=a("This guide describes:"),Ma=c(),V=l("ul"),Dt=l("li"),sl=a("default generation configuration"),al=c(),Lt=l("li"),nl=a("common decoding strategies and their main parameters"),ll=c(),Pt=l("li"),ol=a("saving and sharing custom generation configurations with your fine-tuned model on \u{1F917} Hub"),ba=c(),H=l("h2"),oe=l("a"),Kt=l("span"),m(Be.$$.fragment),rl=c(),Ot=l("span"),il=a("Default text generation configuration"),wa=c(),C=l("p"),pl=a(`A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference
within a `),Mt=l("a"),cl=a("pipeline()"),hl=a(", the models call the "),es=l("code"),dl=a("PreTrainedModel.generate()"),ml=a(` method that applies a default generation
configuration under the hood. The default configuration is also used when no custom configuration has been saved with
the model.`),va=c(),re=l("p"),ul=a(`When you load a model explicitly, you can inspect the generation configuration that comes with it through
`),ts=l("code"),yl=a("model.generation_config"),gl=a(":"),ja=c(),m(Ie.$$.fragment),Ta=c(),ie=l("p"),fl=a("Printing out the "),ss=l("code"),Ml=a("model.generation_config"),bl=a(` reveals only the values that are different from the default generation
configuration, and does not list any of the default values.`),Ua=c(),bt=l("p"),wl=a(`The default generation configuration limits the size of the output combined with the input prompt to a maximum of 20
tokens to avoid running into resource limitations. The default decoding strategy is greedy search, which is the simplest decoding strategy that picks a token with the highest probability as the next token. For many tasks
and small output sizes this works well. However, when used to generate longer outputs, greedy search can start
producing highly repetitive results.`),Ja=c(),Q=l("h2"),pe=l("a"),as=l("span"),m(Xe.$$.fragment),vl=c(),ns=l("span"),jl=a("Customize text generation"),ka=c(),R=l("p"),Tl=a("You can override any "),ls=l("code"),Ul=a("generation_config"),Jl=a(" by passing the parameters and their values directly to the "),os=l("code"),kl=a("generate"),_l=a(" method:"),_a=c(),m(Ve.$$.fragment),Za=c(),wt=l("p"),Zl=a(`Even if the default decoding strategy mostly works for your task, you can still tweak a few things. Some of the
commonly adjusted parameters include:`),Ea=c(),Z=l("ul"),vt=l("li"),rs=l("code"),El=a("max_new_tokens"),Wl=a(`: the maximum number of tokens to generate. In other words, the size of the output sequence, not
including the tokens in the prompt.`),Gl=c(),jt=l("li"),is=l("code"),Bl=a("num_beams"),Il=a(`: by specifying a number of beams higher than 1, you are effectively switching from greedy search to
beam search. This strategy evaluates several hypotheses at each time step and eventually chooses the hypothesis that
has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with a lower probability initial tokens and would\u2019ve been ignored by the greedy search.`),Xl=c(),ce=l("li"),ps=l("code"),Vl=a("do_sample"),Cl=a(": if set to "),cs=l("code"),Rl=a("True"),Nl=a(`, this parameter enables decoding strategies such as multinomial sampling, beam-search
multinomial sampling, Top-K sampling and Top-p sampling. All these strategies select the next token from the probability
distribution over the entire vocabulary with various strategy-specific adjustments.`),$l=c(),Tt=l("li"),hs=l("code"),zl=a("num_return_sequences"),xl=a(`: the number of sequence candidates to return for each input. This option is only available for
the decoding strategies that support multiple sequence candidates, e.g. variations of beam search and sampling. Decoding
strategies like greedy search and contrastive search return a single output sequence.`),Wa=c(),Y=l("h2"),he=l("a"),ds=l("span"),m(Ce.$$.fragment),Al=c(),ms=l("span"),Hl=a("Save a custom decoding strategy with your model"),Ga=c(),Ut=l("p"),Ql=a("If you would like to share your fine-tuned model with a specific generation configuration, you can:"),Ba=c(),E=l("ul"),Re=l("li"),Yl=a("Create a "),Jt=l("a"),Sl=a("GenerationConfig"),Fl=a(" class instance"),ql=c(),us=l("li"),Dl=a("Specify the decoding strategy parameters"),Ll=c(),S=l("li"),Pl=a("Save your generation configuration with "),kt=l("a"),Kl=a("GenerationConfig.save_pretrained()"),Ol=a(", making sure to leave its "),ys=l("code"),eo=a("config_file_name"),to=a(" argument empty"),so=c(),F=l("li"),ao=a("Set "),gs=l("code"),no=a("push_to_hub"),lo=a(" to "),fs=l("code"),oo=a("True"),ro=a(" to upload your config to the model\u2019s repo"),Ia=c(),m(Ne.$$.fragment),Xa=c(),W=l("p"),io=a("You can also store several generation configurations in a single directory, making use of the "),Ms=l("code"),po=a("config_file_name"),co=a(`
argument in `),_t=l("a"),ho=a("GenerationConfig.save_pretrained()"),mo=a(". You can later instantiate them with "),Zt=l("a"),uo=a("GenerationConfig.from_pretrained()"),yo=a(`. This is useful if you want to
store several generation configurations for a single model (e.g. one for creative text generation with sampling, and
one for summarization with beam search). You must have the right Hub permissions to add configuration files to a model.`),Va=c(),m($e.$$.fragment),Ca=c(),q=l("h2"),de=l("a"),bs=l("span"),m(ze.$$.fragment),go=c(),ws=l("span"),fo=a("Streaming"),Ra=c(),b=l("p"),Mo=a("The "),vs=l("code"),bo=a("generate()"),wo=a(" supports streaming, through its "),js=l("code"),vo=a("streamer"),jo=a(" input. The "),Ts=l("code"),To=a("streamer"),Uo=a(` input is compatible with any instance
from a class that has the following methods: `),Us=l("code"),Jo=a("put()"),ko=a(" and "),Js=l("code"),_o=a("end()"),Zo=a(". Internally, "),ks=l("code"),Eo=a("put()"),Wo=a(` is used to push new tokens and
`),_s=l("code"),Go=a("end()"),Bo=a(" is used to flag the end of text generation."),Na=c(),m(me.$$.fragment),$a=c(),N=l("p"),Io=a(`In practice, you can craft your own streaming class for all sorts of purposes! We also have basic streaming classes
ready for you to use. For example, you can use the `),Et=l("a"),Xo=a("TextStreamer"),Vo=a(" class to stream the output of "),Zs=l("code"),Co=a("generate()"),Ro=a(` into
your screen, one word at a time:`),za=c(),m(xe.$$.fragment),xa=c(),D=l("h2"),ue=l("a"),Es=l("span"),m(Ae.$$.fragment),No=c(),Ws=l("span"),$o=a("Decoding strategies"),Aa=c(),G=l("p"),zo=a("Certain combinations of the "),Gs=l("code"),xo=a("generate()"),Ao=a(" parameters, and ultimately "),Bs=l("code"),Ho=a("generation_config"),Qo=a(`, can be used to enable specific
decoding strategies. If you are new to this concept, we recommend reading `),He=l("a"),Yo=a("this blog post that illustrates how common decoding strategies work"),So=a("."),Ha=c(),Wt=l("p"),Fo=a("Here, we\u2019ll show some of the parameters that control the decoding strategies and illustrate how you can use them."),Qa=c(),L=l("h3"),ye=l("a"),Is=l("span"),m(Qe.$$.fragment),qo=c(),Xs=l("span"),Do=a("Greedy Search"),Ya=c(),I=l("p"),Vs=l("code"),Lo=a("generate"),Po=a(" uses greedy search decoding by default so you don\u2019t have to pass any parameters to enable it. This means the parameters "),Cs=l("code"),Ko=a("num_beams"),Oo=a(" is set to 1 and "),Rs=l("code"),er=a("do_sample=False"),tr=a("."),Sa=c(),m(Ye.$$.fragment),Fa=c(),P=l("h3"),ge=l("a"),Ns=l("span"),m(Se.$$.fragment),sr=c(),$s=l("span"),ar=a("Contrastive search"),qa=c(),T=l("p"),nr=a("The contrastive search decoding strategy was proposed in the 2022 paper "),Fe=l("a"),lr=a("A Contrastive Framework for Neural Text Generation"),or=a(`.
It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search
works, check out `),qe=l("a"),rr=a("this blog post"),ir=a(`.
The two main parameters that enable and control the behavior of contrastive search are `),zs=l("code"),pr=a("penalty_alpha"),cr=a(" and "),xs=l("code"),hr=a("top_k"),dr=a(":"),Da=c(),m(De.$$.fragment),La=c(),K=l("h3"),fe=l("a"),As=l("span"),m(Le.$$.fragment),mr=c(),Hs=l("span"),ur=a("Multinomial sampling"),Pa=c(),Gt=l("p"),yr=a(`As opposed to greedy search that always chooses a token with the highest probability as the
next token, multinomial sampling (also called ancestral sampling) randomly selects the next token based on the probability distribution over the entire
vocabulary given by the model. Every token with a non-zero probability has a chance of being selected, thus reducing the
risk of repetition.`),Ka=c(),$=l("p"),gr=a("To enable multinomial sampling set "),Qs=l("code"),fr=a("do_sample=True"),Mr=a(" and "),Ys=l("code"),br=a("num_beams=1"),wr=a("."),Oa=c(),m(Pe.$$.fragment),en=c(),O=l("h3"),Me=l("a"),Ss=l("span"),m(Ke.$$.fragment),vr=c(),Fs=l("span"),jr=a("Beam-search decoding"),tn=c(),Bt=l("p"),Tr=a(`Unlike greedy search, beam-search decoding keeps several hypotheses at each time step and eventually chooses
the hypothesis that has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with lower probability initial tokens and would\u2019ve been ignored by the greedy search.`),sn=c(),be=l("p"),Ur=a("To enable this decoding strategy, specify the "),qs=l("code"),Jr=a("num_beams"),kr=a(" (aka number of hypotheses to keep track of) that is greater than 1."),an=c(),m(Oe.$$.fragment),nn=c(),ee=l("h3"),we=l("a"),Ds=l("span"),m(et.$$.fragment),_r=c(),Ls=l("span"),Zr=a("Beam-search multinomial sampling"),ln=c(),z=l("p"),Er=a(`As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify
the `),Ps=l("code"),Wr=a("num_beams"),Gr=a(" greater than 1, and set "),Ks=l("code"),Br=a("do_sample=True"),Ir=a(" to use this decoding strategy."),on=c(),m(tt.$$.fragment),rn=c(),te=l("h3"),ve=l("a"),Os=l("span"),m(st.$$.fragment),Xr=c(),ea=l("span"),Vr=a("Diverse beam search decoding"),pn=c(),U=l("p"),Cr=a(`The diverse beam search decoding strategy is an extension of the beam search strategy that allows for generating a more diverse
set of beam sequences to choose from. To learn how it works, refer to `),at=l("a"),Rr=a("Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models"),Nr=a(`.
This approach has three main parameters: `),ta=l("code"),$r=a("num_beams"),zr=a(", "),sa=l("code"),xr=a("num_beam_groups"),Ar=a(", and "),aa=l("code"),Hr=a("diversity_penalty"),Qr=a(`.
The diversity penalty ensures the outputs are distinct across groups, and beam search is used within each group.`),cn=c(),m(nt.$$.fragment),hn=c(),B=l("p"),Yr=a(`This guide illustrates the main parameters that enable various decoding strategies. More advanced parameters exist for the
`),na=l("code"),Sr=a("generate"),Fr=a(" method, which gives you even further control over the "),la=l("code"),qr=a("generate"),Dr=a(` method\u2019s behavior.
For the complete list of the available parameters, refer to the `),It=l("a"),Lr=a("API documentation"),Pr=a("."),dn=c(),se=l("h3"),je=l("a"),oa=l("span"),m(lt.$$.fragment),Kr=c(),ra=l("span"),Or=a("Assisted Decoding"),mn=c(),Te=l("p"),ei=a(`Assisted decoding is a modification of the decoding strategies above that uses an assistant model with the same
tokenizer (ideally a much smaller model) to greedily generate a few candidate tokens. The main model then validates
the candidate tokens in a single forward pass, which speeds up the decoding process. Currently, only greedy search
and sampling are supported with assisted decoding, and doesn\u2019t support batched inputs. To learn more about assisted
decoding, check `),ot=l("a"),ti=a("this blog post"),si=a("."),un=c(),Ue=l("p"),ai=a("To enable assisted decoding, set the "),ia=l("code"),ni=a("assistant_model"),li=a(" argument with a model."),yn=c(),m(rt.$$.fragment),gn=c(),Je=l("p"),oi=a("When using assisted decoding with sampling methods, you can use the "),pa=l("code"),ri=a("temperature"),ii=a(` argument to control the randomness
just like in multinomial sampling. However, in assisted decoding, reducing the temperature will help improving latency.`),fn=c(),m(it.$$.fragment),this.h()},l(e){const i=wc('[data-svelte="svelte-1phssyn"]',document.head);w=o(i,"META",{name:!0,content:!0}),i.forEach(s),ae=h(e),j=o(e,"H1",{class:!0});var pt=r(j);J=o(pt,"A",{id:!0,class:!0,href:!0});var di=r(J);Ht=o(di,"SPAN",{});var mi=r(Ht);u(Ge.$$.fragment,mi),mi.forEach(s),di.forEach(s),zn=h(pt),Qt=o(pt,"SPAN",{});var ui=r(Qt);xn=n(ui,"Text generation strategies"),ui.forEach(s),pt.forEach(s),da=h(e),ht=o(e,"P",{});var yi=r(ht);An=n(yi,`Text generation is essential to many NLP tasks, such as open-ended text generation, summarization, translation, and
more. It also plays a role in a variety of mixed-modality applications that have text as an output like speech-to-text
and vision-to-text. Some of the models that can generate text include
GPT2, XLNet, OpenAI GPT, CTRL, TransformerXL, XLM, Bart, T5, GIT, Whisper.`),yi.forEach(s),ma=h(e),ne=o(e,"P",{});var bn=r(ne);Hn=n(bn,"Check out a few examples that use "),dt=o(bn,"A",{href:!0});var gi=r(dt);Qn=n(gi,"generate()"),gi.forEach(s),Yn=n(bn,` method to produce
text outputs for different tasks:`),bn.forEach(s),ua=h(e),X=o(e,"UL",{});var Xt=r(X);Yt=o(Xt,"LI",{});var fi=r(Yt);mt=o(fi,"A",{href:!0});var Mi=r(mt);Sn=n(Mi,"Text summarization"),Mi.forEach(s),fi.forEach(s),Fn=h(Xt),St=o(Xt,"LI",{});var bi=r(St);ut=o(bi,"A",{href:!0});var wi=r(ut);qn=n(wi,"Image captioning"),wi.forEach(s),bi.forEach(s),Dn=h(Xt),Ft=o(Xt,"LI",{});var vi=r(Ft);yt=o(vi,"A",{href:!0});var ji=r(yt);Ln=n(ji,"Audio transcription"),ji.forEach(s),vi.forEach(s),Xt.forEach(s),ya=h(e),gt=o(e,"P",{});var Ti=r(gt);Pn=n(Ti,`Note that the inputs to the generate method depend on the model\u2019s modality. They are returned by the model\u2019s preprocessor
class, such as AutoTokenizer or AutoProcessor. If a model\u2019s preprocessor creates more than one kind of input, pass all
the inputs to generate(). You can learn more about the individual model\u2019s preprocessor in the corresponding model\u2019s documentation.`),Ti.forEach(s),ga=h(e),le=o(e,"P",{});var wn=r(le);Kn=n(wn,`The process of selecting output tokens to generate text is known as decoding, and you can customize the decoding strategy
that the `),qt=o(wn,"CODE",{});var Ui=r(qt);On=n(Ui,"generate()"),Ui.forEach(s),el=n(wn,` method will use. Modifying a decoding strategy does not change the values of any trainable parameters.
However, it can have a noticeable impact on the quality of the generated output. It can help reduce repetition in the text
and make it more coherent.`),wn.forEach(s),fa=h(e),ft=o(e,"P",{});var Ji=r(ft);tl=n(Ji,"This guide describes:"),Ji.forEach(s),Ma=h(e),V=o(e,"UL",{});var Vt=r(V);Dt=o(Vt,"LI",{});var ki=r(Dt);sl=n(ki,"default generation configuration"),ki.forEach(s),al=h(Vt),Lt=o(Vt,"LI",{});var _i=r(Lt);nl=n(_i,"common decoding strategies and their main parameters"),_i.forEach(s),ll=h(Vt),Pt=o(Vt,"LI",{});var Zi=r(Pt);ol=n(Zi,"saving and sharing custom generation configurations with your fine-tuned model on \u{1F917} Hub"),Zi.forEach(s),Vt.forEach(s),ba=h(e),H=o(e,"H2",{class:!0});var vn=r(H);oe=o(vn,"A",{id:!0,class:!0,href:!0});var Ei=r(oe);Kt=o(Ei,"SPAN",{});var Wi=r(Kt);u(Be.$$.fragment,Wi),Wi.forEach(s),Ei.forEach(s),rl=h(vn),Ot=o(vn,"SPAN",{});var Gi=r(Ot);il=n(Gi,"Default text generation configuration"),Gi.forEach(s),vn.forEach(s),wa=h(e),C=o(e,"P",{});var Ct=r(C);pl=n(Ct,`A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference
within a `),Mt=o(Ct,"A",{href:!0});var Bi=r(Mt);cl=n(Bi,"pipeline()"),Bi.forEach(s),hl=n(Ct,", the models call the "),es=o(Ct,"CODE",{});var Ii=r(es);dl=n(Ii,"PreTrainedModel.generate()"),Ii.forEach(s),ml=n(Ct,` method that applies a default generation
configuration under the hood. The default configuration is also used when no custom configuration has been saved with
the model.`),Ct.forEach(s),va=h(e),re=o(e,"P",{});var jn=r(re);ul=n(jn,`When you load a model explicitly, you can inspect the generation configuration that comes with it through
`),ts=o(jn,"CODE",{});var Xi=r(ts);yl=n(Xi,"model.generation_config"),Xi.forEach(s),gl=n(jn,":"),jn.forEach(s),ja=h(e),u(Ie.$$.fragment,e),Ta=h(e),ie=o(e,"P",{});var Tn=r(ie);fl=n(Tn,"Printing out the "),ss=o(Tn,"CODE",{});var Vi=r(ss);Ml=n(Vi,"model.generation_config"),Vi.forEach(s),bl=n(Tn,` reveals only the values that are different from the default generation
configuration, and does not list any of the default values.`),Tn.forEach(s),Ua=h(e),bt=o(e,"P",{});var Ci=r(bt);wl=n(Ci,`The default generation configuration limits the size of the output combined with the input prompt to a maximum of 20
tokens to avoid running into resource limitations. The default decoding strategy is greedy search, which is the simplest decoding strategy that picks a token with the highest probability as the next token. For many tasks
and small output sizes this works well. However, when used to generate longer outputs, greedy search can start
producing highly repetitive results.`),Ci.forEach(s),Ja=h(e),Q=o(e,"H2",{class:!0});var Un=r(Q);pe=o(Un,"A",{id:!0,class:!0,href:!0});var Ri=r(pe);as=o(Ri,"SPAN",{});var Ni=r(as);u(Xe.$$.fragment,Ni),Ni.forEach(s),Ri.forEach(s),vl=h(Un),ns=o(Un,"SPAN",{});var $i=r(ns);jl=n($i,"Customize text generation"),$i.forEach(s),Un.forEach(s),ka=h(e),R=o(e,"P",{});var Rt=r(R);Tl=n(Rt,"You can override any "),ls=o(Rt,"CODE",{});var zi=r(ls);Ul=n(zi,"generation_config"),zi.forEach(s),Jl=n(Rt," by passing the parameters and their values directly to the "),os=o(Rt,"CODE",{});var xi=r(os);kl=n(xi,"generate"),xi.forEach(s),_l=n(Rt," method:"),Rt.forEach(s),_a=h(e),u(Ve.$$.fragment,e),Za=h(e),wt=o(e,"P",{});var Ai=r(wt);Zl=n(Ai,`Even if the default decoding strategy mostly works for your task, you can still tweak a few things. Some of the
commonly adjusted parameters include:`),Ai.forEach(s),Ea=h(e),Z=o(e,"UL",{});var ke=r(Z);vt=o(ke,"LI",{});var pi=r(vt);rs=o(pi,"CODE",{});var Hi=r(rs);El=n(Hi,"max_new_tokens"),Hi.forEach(s),Wl=n(pi,`: the maximum number of tokens to generate. In other words, the size of the output sequence, not
including the tokens in the prompt.`),pi.forEach(s),Gl=h(ke),jt=o(ke,"LI",{});var ci=r(jt);is=o(ci,"CODE",{});var Qi=r(is);Bl=n(Qi,"num_beams"),Qi.forEach(s),Il=n(ci,`: by specifying a number of beams higher than 1, you are effectively switching from greedy search to
beam search. This strategy evaluates several hypotheses at each time step and eventually chooses the hypothesis that
has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with a lower probability initial tokens and would\u2019ve been ignored by the greedy search.`),ci.forEach(s),Xl=h(ke),ce=o(ke,"LI",{});var ca=r(ce);ps=o(ca,"CODE",{});var Yi=r(ps);Vl=n(Yi,"do_sample"),Yi.forEach(s),Cl=n(ca,": if set to "),cs=o(ca,"CODE",{});var Si=r(cs);Rl=n(Si,"True"),Si.forEach(s),Nl=n(ca,`, this parameter enables decoding strategies such as multinomial sampling, beam-search
multinomial sampling, Top-K sampling and Top-p sampling. All these strategies select the next token from the probability
distribution over the entire vocabulary with various strategy-specific adjustments.`),ca.forEach(s),$l=h(ke),Tt=o(ke,"LI",{});var hi=r(Tt);hs=o(hi,"CODE",{});var Fi=r(hs);zl=n(Fi,"num_return_sequences"),Fi.forEach(s),xl=n(hi,`: the number of sequence candidates to return for each input. This option is only available for
the decoding strategies that support multiple sequence candidates, e.g. variations of beam search and sampling. Decoding
strategies like greedy search and contrastive search return a single output sequence.`),hi.forEach(s),ke.forEach(s),Wa=h(e),Y=o(e,"H2",{class:!0});var Jn=r(Y);he=o(Jn,"A",{id:!0,class:!0,href:!0});var qi=r(he);ds=o(qi,"SPAN",{});var Di=r(ds);u(Ce.$$.fragment,Di),Di.forEach(s),qi.forEach(s),Al=h(Jn),ms=o(Jn,"SPAN",{});var Li=r(ms);Hl=n(Li,"Save a custom decoding strategy with your model"),Li.forEach(s),Jn.forEach(s),Ga=h(e),Ut=o(e,"P",{});var Pi=r(Ut);Ql=n(Pi,"If you would like to share your fine-tuned model with a specific generation configuration, you can:"),Pi.forEach(s),Ba=h(e),E=o(e,"UL",{});var _e=r(E);Re=o(_e,"LI",{});var kn=r(Re);Yl=n(kn,"Create a "),Jt=o(kn,"A",{href:!0});var Ki=r(Jt);Sl=n(Ki,"GenerationConfig"),Ki.forEach(s),Fl=n(kn," class instance"),kn.forEach(s),ql=h(_e),us=o(_e,"LI",{});var Oi=r(us);Dl=n(Oi,"Specify the decoding strategy parameters"),Oi.forEach(s),Ll=h(_e),S=o(_e,"LI",{});var Nt=r(S);Pl=n(Nt,"Save your generation configuration with "),kt=o(Nt,"A",{href:!0});var ep=r(kt);Kl=n(ep,"GenerationConfig.save_pretrained()"),ep.forEach(s),Ol=n(Nt,", making sure to leave its "),ys=o(Nt,"CODE",{});var tp=r(ys);eo=n(tp,"config_file_name"),tp.forEach(s),to=n(Nt," argument empty"),Nt.forEach(s),so=h(_e),F=o(_e,"LI",{});var $t=r(F);ao=n($t,"Set "),gs=o($t,"CODE",{});var sp=r(gs);no=n(sp,"push_to_hub"),sp.forEach(s),lo=n($t," to "),fs=o($t,"CODE",{});var ap=r(fs);oo=n(ap,"True"),ap.forEach(s),ro=n($t," to upload your config to the model\u2019s repo"),$t.forEach(s),_e.forEach(s),Ia=h(e),u(Ne.$$.fragment,e),Xa=h(e),W=o(e,"P",{});var Ze=r(W);io=n(Ze,"You can also store several generation configurations in a single directory, making use of the "),Ms=o(Ze,"CODE",{});var np=r(Ms);po=n(np,"config_file_name"),np.forEach(s),co=n(Ze,`
argument in `),_t=o(Ze,"A",{href:!0});var lp=r(_t);ho=n(lp,"GenerationConfig.save_pretrained()"),lp.forEach(s),mo=n(Ze,". You can later instantiate them with "),Zt=o(Ze,"A",{href:!0});var op=r(Zt);uo=n(op,"GenerationConfig.from_pretrained()"),op.forEach(s),yo=n(Ze,`. This is useful if you want to
store several generation configurations for a single model (e.g. one for creative text generation with sampling, and
one for summarization with beam search). You must have the right Hub permissions to add configuration files to a model.`),Ze.forEach(s),Va=h(e),u($e.$$.fragment,e),Ca=h(e),q=o(e,"H2",{class:!0});var _n=r(q);de=o(_n,"A",{id:!0,class:!0,href:!0});var rp=r(de);bs=o(rp,"SPAN",{});var ip=r(bs);u(ze.$$.fragment,ip),ip.forEach(s),rp.forEach(s),go=h(_n),ws=o(_n,"SPAN",{});var pp=r(ws);fo=n(pp,"Streaming"),pp.forEach(s),_n.forEach(s),Ra=h(e),b=o(e,"P",{});var v=r(b);Mo=n(v,"The "),vs=o(v,"CODE",{});var cp=r(vs);bo=n(cp,"generate()"),cp.forEach(s),wo=n(v," supports streaming, through its "),js=o(v,"CODE",{});var hp=r(js);vo=n(hp,"streamer"),hp.forEach(s),jo=n(v," input. The "),Ts=o(v,"CODE",{});var dp=r(Ts);To=n(dp,"streamer"),dp.forEach(s),Uo=n(v,` input is compatible with any instance
from a class that has the following methods: `),Us=o(v,"CODE",{});var mp=r(Us);Jo=n(mp,"put()"),mp.forEach(s),ko=n(v," and "),Js=o(v,"CODE",{});var up=r(Js);_o=n(up,"end()"),up.forEach(s),Zo=n(v,". Internally, "),ks=o(v,"CODE",{});var yp=r(ks);Eo=n(yp,"put()"),yp.forEach(s),Wo=n(v,` is used to push new tokens and
`),_s=o(v,"CODE",{});var gp=r(_s);Go=n(gp,"end()"),gp.forEach(s),Bo=n(v," is used to flag the end of text generation."),v.forEach(s),Na=h(e),u(me.$$.fragment,e),$a=h(e),N=o(e,"P",{});var zt=r(N);Io=n(zt,`In practice, you can craft your own streaming class for all sorts of purposes! We also have basic streaming classes
ready for you to use. For example, you can use the `),Et=o(zt,"A",{href:!0});var fp=r(Et);Xo=n(fp,"TextStreamer"),fp.forEach(s),Vo=n(zt," class to stream the output of "),Zs=o(zt,"CODE",{});var Mp=r(Zs);Co=n(Mp,"generate()"),Mp.forEach(s),Ro=n(zt,` into
your screen, one word at a time:`),zt.forEach(s),za=h(e),u(xe.$$.fragment,e),xa=h(e),D=o(e,"H2",{class:!0});var Zn=r(D);ue=o(Zn,"A",{id:!0,class:!0,href:!0});var bp=r(ue);Es=o(bp,"SPAN",{});var wp=r(Es);u(Ae.$$.fragment,wp),wp.forEach(s),bp.forEach(s),No=h(Zn),Ws=o(Zn,"SPAN",{});var vp=r(Ws);$o=n(vp,"Decoding strategies"),vp.forEach(s),Zn.forEach(s),Aa=h(e),G=o(e,"P",{});var Ee=r(G);zo=n(Ee,"Certain combinations of the "),Gs=o(Ee,"CODE",{});var jp=r(Gs);xo=n(jp,"generate()"),jp.forEach(s),Ao=n(Ee," parameters, and ultimately "),Bs=o(Ee,"CODE",{});var Tp=r(Bs);Ho=n(Tp,"generation_config"),Tp.forEach(s),Qo=n(Ee,`, can be used to enable specific
decoding strategies. If you are new to this concept, we recommend reading `),He=o(Ee,"A",{href:!0,rel:!0});var Up=r(He);Yo=n(Up,"this blog post that illustrates how common decoding strategies work"),Up.forEach(s),So=n(Ee,"."),Ee.forEach(s),Ha=h(e),Wt=o(e,"P",{});var Jp=r(Wt);Fo=n(Jp,"Here, we\u2019ll show some of the parameters that control the decoding strategies and illustrate how you can use them."),Jp.forEach(s),Qa=h(e),L=o(e,"H3",{class:!0});var En=r(L);ye=o(En,"A",{id:!0,class:!0,href:!0});var kp=r(ye);Is=o(kp,"SPAN",{});var _p=r(Is);u(Qe.$$.fragment,_p),_p.forEach(s),kp.forEach(s),qo=h(En),Xs=o(En,"SPAN",{});var Zp=r(Xs);Do=n(Zp,"Greedy Search"),Zp.forEach(s),En.forEach(s),Ya=h(e),I=o(e,"P",{});var ct=r(I);Vs=o(ct,"CODE",{});var Ep=r(Vs);Lo=n(Ep,"generate"),Ep.forEach(s),Po=n(ct," uses greedy search decoding by default so you don\u2019t have to pass any parameters to enable it. This means the parameters "),Cs=o(ct,"CODE",{});var Wp=r(Cs);Ko=n(Wp,"num_beams"),Wp.forEach(s),Oo=n(ct," is set to 1 and "),Rs=o(ct,"CODE",{});var Gp=r(Rs);er=n(Gp,"do_sample=False"),Gp.forEach(s),tr=n(ct,"."),ct.forEach(s),Sa=h(e),u(Ye.$$.fragment,e),Fa=h(e),P=o(e,"H3",{class:!0});var Wn=r(P);ge=o(Wn,"A",{id:!0,class:!0,href:!0});var Bp=r(ge);Ns=o(Bp,"SPAN",{});var Ip=r(Ns);u(Se.$$.fragment,Ip),Ip.forEach(s),Bp.forEach(s),sr=h(Wn),$s=o(Wn,"SPAN",{});var Xp=r($s);ar=n(Xp,"Contrastive search"),Xp.forEach(s),Wn.forEach(s),qa=h(e),T=o(e,"P",{});var x=r(T);nr=n(x,"The contrastive search decoding strategy was proposed in the 2022 paper "),Fe=o(x,"A",{href:!0,rel:!0});var Vp=r(Fe);lr=n(Vp,"A Contrastive Framework for Neural Text Generation"),Vp.forEach(s),or=n(x,`.
It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search
works, check out `),qe=o(x,"A",{href:!0,rel:!0});var Cp=r(qe);rr=n(Cp,"this blog post"),Cp.forEach(s),ir=n(x,`.
The two main parameters that enable and control the behavior of contrastive search are `),zs=o(x,"CODE",{});var Rp=r(zs);pr=n(Rp,"penalty_alpha"),Rp.forEach(s),cr=n(x," and "),xs=o(x,"CODE",{});var Np=r(xs);hr=n(Np,"top_k"),Np.forEach(s),dr=n(x,":"),x.forEach(s),Da=h(e),u(De.$$.fragment,e),La=h(e),K=o(e,"H3",{class:!0});var Gn=r(K);fe=o(Gn,"A",{id:!0,class:!0,href:!0});var $p=r(fe);As=o($p,"SPAN",{});var zp=r(As);u(Le.$$.fragment,zp),zp.forEach(s),$p.forEach(s),mr=h(Gn),Hs=o(Gn,"SPAN",{});var xp=r(Hs);ur=n(xp,"Multinomial sampling"),xp.forEach(s),Gn.forEach(s),Pa=h(e),Gt=o(e,"P",{});var Ap=r(Gt);yr=n(Ap,`As opposed to greedy search that always chooses a token with the highest probability as the
next token, multinomial sampling (also called ancestral sampling) randomly selects the next token based on the probability distribution over the entire
vocabulary given by the model. Every token with a non-zero probability has a chance of being selected, thus reducing the
risk of repetition.`),Ap.forEach(s),Ka=h(e),$=o(e,"P",{});var xt=r($);gr=n(xt,"To enable multinomial sampling set "),Qs=o(xt,"CODE",{});var Hp=r(Qs);fr=n(Hp,"do_sample=True"),Hp.forEach(s),Mr=n(xt," and "),Ys=o(xt,"CODE",{});var Qp=r(Ys);br=n(Qp,"num_beams=1"),Qp.forEach(s),wr=n(xt,"."),xt.forEach(s),Oa=h(e),u(Pe.$$.fragment,e),en=h(e),O=o(e,"H3",{class:!0});var Bn=r(O);Me=o(Bn,"A",{id:!0,class:!0,href:!0});var Yp=r(Me);Ss=o(Yp,"SPAN",{});var Sp=r(Ss);u(Ke.$$.fragment,Sp),Sp.forEach(s),Yp.forEach(s),vr=h(Bn),Fs=o(Bn,"SPAN",{});var Fp=r(Fs);jr=n(Fp,"Beam-search decoding"),Fp.forEach(s),Bn.forEach(s),tn=h(e),Bt=o(e,"P",{});var qp=r(Bt);Tr=n(qp,`Unlike greedy search, beam-search decoding keeps several hypotheses at each time step and eventually chooses
the hypothesis that has the overall highest probability for the entire sequence. This has the advantage of identifying high-probability
sequences that start with lower probability initial tokens and would\u2019ve been ignored by the greedy search.`),qp.forEach(s),sn=h(e),be=o(e,"P",{});var In=r(be);Ur=n(In,"To enable this decoding strategy, specify the "),qs=o(In,"CODE",{});var Dp=r(qs);Jr=n(Dp,"num_beams"),Dp.forEach(s),kr=n(In," (aka number of hypotheses to keep track of) that is greater than 1."),In.forEach(s),an=h(e),u(Oe.$$.fragment,e),nn=h(e),ee=o(e,"H3",{class:!0});var Xn=r(ee);we=o(Xn,"A",{id:!0,class:!0,href:!0});var Lp=r(we);Ds=o(Lp,"SPAN",{});var Pp=r(Ds);u(et.$$.fragment,Pp),Pp.forEach(s),Lp.forEach(s),_r=h(Xn),Ls=o(Xn,"SPAN",{});var Kp=r(Ls);Zr=n(Kp,"Beam-search multinomial sampling"),Kp.forEach(s),Xn.forEach(s),ln=h(e),z=o(e,"P",{});var At=r(z);Er=n(At,`As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify
the `),Ps=o(At,"CODE",{});var Op=r(Ps);Wr=n(Op,"num_beams"),Op.forEach(s),Gr=n(At," greater than 1, and set "),Ks=o(At,"CODE",{});var ec=r(Ks);Br=n(ec,"do_sample=True"),ec.forEach(s),Ir=n(At," to use this decoding strategy."),At.forEach(s),on=h(e),u(tt.$$.fragment,e),rn=h(e),te=o(e,"H3",{class:!0});var Vn=r(te);ve=o(Vn,"A",{id:!0,class:!0,href:!0});var tc=r(ve);Os=o(tc,"SPAN",{});var sc=r(Os);u(st.$$.fragment,sc),sc.forEach(s),tc.forEach(s),Xr=h(Vn),ea=o(Vn,"SPAN",{});var ac=r(ea);Vr=n(ac,"Diverse beam search decoding"),ac.forEach(s),Vn.forEach(s),pn=h(e),U=o(e,"P",{});var A=r(U);Cr=n(A,`The diverse beam search decoding strategy is an extension of the beam search strategy that allows for generating a more diverse
set of beam sequences to choose from. To learn how it works, refer to `),at=o(A,"A",{href:!0,rel:!0});var nc=r(at);Rr=n(nc,"Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models"),nc.forEach(s),Nr=n(A,`.
This approach has three main parameters: `),ta=o(A,"CODE",{});var lc=r(ta);$r=n(lc,"num_beams"),lc.forEach(s),zr=n(A,", "),sa=o(A,"CODE",{});var oc=r(sa);xr=n(oc,"num_beam_groups"),oc.forEach(s),Ar=n(A,", and "),aa=o(A,"CODE",{});var rc=r(aa);Hr=n(rc,"diversity_penalty"),rc.forEach(s),Qr=n(A,`.
The diversity penalty ensures the outputs are distinct across groups, and beam search is used within each group.`),A.forEach(s),cn=h(e),u(nt.$$.fragment,e),hn=h(e),B=o(e,"P",{});var We=r(B);Yr=n(We,`This guide illustrates the main parameters that enable various decoding strategies. More advanced parameters exist for the
`),na=o(We,"CODE",{});var ic=r(na);Sr=n(ic,"generate"),ic.forEach(s),Fr=n(We," method, which gives you even further control over the "),la=o(We,"CODE",{});var pc=r(la);qr=n(pc,"generate"),pc.forEach(s),Dr=n(We,` method\u2019s behavior.
For the complete list of the available parameters, refer to the `),It=o(We,"A",{href:!0});var cc=r(It);Lr=n(cc,"API documentation"),cc.forEach(s),Pr=n(We,"."),We.forEach(s),dn=h(e),se=o(e,"H3",{class:!0});var Cn=r(se);je=o(Cn,"A",{id:!0,class:!0,href:!0});var hc=r(je);oa=o(hc,"SPAN",{});var dc=r(oa);u(lt.$$.fragment,dc),dc.forEach(s),hc.forEach(s),Kr=h(Cn),ra=o(Cn,"SPAN",{});var mc=r(ra);Or=n(mc,"Assisted Decoding"),mc.forEach(s),Cn.forEach(s),mn=h(e),Te=o(e,"P",{});var Rn=r(Te);ei=n(Rn,`Assisted decoding is a modification of the decoding strategies above that uses an assistant model with the same
tokenizer (ideally a much smaller model) to greedily generate a few candidate tokens. The main model then validates
the candidate tokens in a single forward pass, which speeds up the decoding process. Currently, only greedy search
and sampling are supported with assisted decoding, and doesn\u2019t support batched inputs. To learn more about assisted
decoding, check `),ot=o(Rn,"A",{href:!0,rel:!0});var uc=r(ot);ti=n(uc,"this blog post"),uc.forEach(s),si=n(Rn,"."),Rn.forEach(s),un=h(e),Ue=o(e,"P",{});var Nn=r(Ue);ai=n(Nn,"To enable assisted decoding, set the "),ia=o(Nn,"CODE",{});var yc=r(ia);ni=n(yc,"assistant_model"),yc.forEach(s),li=n(Nn," argument with a model."),Nn.forEach(s),yn=h(e),u(rt.$$.fragment,e),gn=h(e),Je=o(e,"P",{});var $n=r(Je);oi=n($n,"When using assisted decoding with sampling methods, you can use the "),pa=o($n,"CODE",{});var gc=r(pa);ri=n(gc,"temperature"),gc.forEach(s),ii=n($n,` argument to control the randomness
just like in multinomial sampling. However, in assisted decoding, reducing the temperature will help improving latency.`),$n.forEach(s),fn=h(e),u(it.$$.fragment,e),this.h()},h(){d(w,"name","hf:doc:metadata"),d(w,"content",JSON.stringify(Jc)),d(J,"id","text-generation-strategies"),d(J,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(J,"href","#text-generation-strategies"),d(j,"class","relative group"),d(dt,"href","/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationMixin.generate"),d(mt,"href","./tasks/summarization#inference"),d(ut,"href","./model_doc/git#transformers.GitForCausalLM.forward.example"),d(yt,"href","./model_doc/whisper#transformers.WhisperForConditionalGeneration.forward.example"),d(oe,"id","default-text-generation-configuration"),d(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(oe,"href","#default-text-generation-configuration"),d(H,"class","relative group"),d(Mt,"href","/docs/transformers/main/en/main_classes/pipelines#transformers.pipeline"),d(pe,"id","customize-text-generation"),d(pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(pe,"href","#customize-text-generation"),d(Q,"class","relative group"),d(he,"id","save-a-custom-decoding-strategy-with-your-model"),d(he,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(he,"href","#save-a-custom-decoding-strategy-with-your-model"),d(Y,"class","relative group"),d(Jt,"href","/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationConfig"),d(kt,"href","/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationConfig.save_pretrained"),d(_t,"href","/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationConfig.save_pretrained"),d(Zt,"href","/docs/transformers/main/en/main_classes/text_generation#transformers.GenerationConfig.from_pretrained"),d(de,"id","streaming"),d(de,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(de,"href","#streaming"),d(q,"class","relative group"),d(Et,"href","/docs/transformers/main/en/internal/generation_utils#transformers.TextStreamer"),d(ue,"id","decoding-strategies"),d(ue,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ue,"href","#decoding-strategies"),d(D,"class","relative group"),d(He,"href","https://huggingface.co/blog/how-to-generate"),d(He,"rel","nofollow"),d(ye,"id","greedy-search"),d(ye,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ye,"href","#greedy-search"),d(L,"class","relative group"),d(ge,"id","contrastive-search"),d(ge,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ge,"href","#contrastive-search"),d(P,"class","relative group"),d(Fe,"href","https://arxiv.org/abs/2202.06417"),d(Fe,"rel","nofollow"),d(qe,"href","https://huggingface.co/blog/introducing-csearch"),d(qe,"rel","nofollow"),d(fe,"id","multinomial-sampling"),d(fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(fe,"href","#multinomial-sampling"),d(K,"class","relative group"),d(Me,"id","beamsearch-decoding"),d(Me,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Me,"href","#beamsearch-decoding"),d(O,"class","relative group"),d(we,"id","beamsearch-multinomial-sampling"),d(we,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(we,"href","#beamsearch-multinomial-sampling"),d(ee,"class","relative group"),d(ve,"id","diverse-beam-search-decoding"),d(ve,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(ve,"href","#diverse-beam-search-decoding"),d(te,"class","relative group"),d(at,"href","https://arxiv.org/pdf/1610.02424.pdf"),d(at,"rel","nofollow"),d(It,"href","./main_classes/text_generation.md"),d(je,"id","assisted-decoding"),d(je,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(je,"href","#assisted-decoding"),d(se,"class","relative group"),d(ot,"href","https://huggingface.co/blog/assisted-generation"),d(ot,"rel","nofollow")},m(e,i){t(document.head,w),p(e,ae,i),p(e,j,i),t(j,J),t(J,Ht),y(Ge,Ht,null),t(j,zn),t(j,Qt),t(Qt,xn),p(e,da,i),p(e,ht,i),t(ht,An),p(e,ma,i),p(e,ne,i),t(ne,Hn),t(ne,dt),t(dt,Qn),t(ne,Yn),p(e,ua,i),p(e,X,i),t(X,Yt),t(Yt,mt),t(mt,Sn),t(X,Fn),t(X,St),t(St,ut),t(ut,qn),t(X,Dn),t(X,Ft),t(Ft,yt),t(yt,Ln),p(e,ya,i),p(e,gt,i),t(gt,Pn),p(e,ga,i),p(e,le,i),t(le,Kn),t(le,qt),t(qt,On),t(le,el),p(e,fa,i),p(e,ft,i),t(ft,tl),p(e,Ma,i),p(e,V,i),t(V,Dt),t(Dt,sl),t(V,al),t(V,Lt),t(Lt,nl),t(V,ll),t(V,Pt),t(Pt,ol),p(e,ba,i),p(e,H,i),t(H,oe),t(oe,Kt),y(Be,Kt,null),t(H,rl),t(H,Ot),t(Ot,il),p(e,wa,i),p(e,C,i),t(C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),t($,gr),t($,Qs),t(Qs,fr),t($,Mr),t($,Ys),t(Ys,br),t($,wr),p(e,Oa,i),y(Pe,e,i),p(e,en,i),p(e,O,i),t(O,Me),t(Me,Ss),y(Ke,Ss,null),t(O,vr),t(O,Fs),t(Fs,jr),p(e,tn,i),p(e,Bt,i),t(Bt,Tr),p(e,sn,i),p(e,be,i),t(be,Ur),t(be,qs),t(qs,Jr),t(be,kr),p(e,an,i),y(Oe,e,i),p(e,nn,i),p(e,ee,i),t(ee,we),t(we,Ds),y(et,Ds,null),t(ee,_r),t(ee,Ls),t(Ls,Zr),p(e,ln,i),p(e,z,i),t(z,Er),t(z,Ps),t(Ps,Wr),t(z,Gr),t(z,Ks),t(Ks,Br),t(z,Ir),p(e,on,i),y(tt,e,i),p(e,rn,i),p(e,te,i),t(te,ve),t(ve,Os),y(st,Os,null),t(te,Xr),t(te,ea),t(ea,Vr),p(e,pn,i),p(e,U,i),t(U,Cr),t(U,at),t(at,Rr),t(U,Nr),t(U,ta),t(ta,$r),t(U,zr),t(U,sa),t(sa,xr),t(U,Ar),t(U,aa),t(aa,Hr),t(U,Qr),p(e,cn,i),y(nt,e,i),p(e,hn,i),p(e,B,i),t(B,Yr),t(B,na),t(na,Sr),t(B,Fr),t(B,la),t(la,qr),t(B,Dr),t(B,It),t(It,Lr),t(B,Pr),p(e,dn,i),p(e,se,i),t(se,je),t(je,oa),y(lt,oa,null),t(se,Kr),t(se,ra),t(ra,Or),p(e,mn,i),p(e,Te,i),t(Te,ei),t(Te,ot),t(ot,ti),t(Te,si),p(e,un,i),p(e,Ue,i),t(Ue,ai),t(Ue,ia),t(ia,ni),t(Ue,li),p(e,yn,i),y(rt,e,i),p(e,gn,i),p(e,Je,i),t(Je,oi),t(Je,pa),t(pa,ri),t(Je,ii),p(e,fn,i),y(it,e,i),Mn=!0},p(e,[i]){const pt={};i&2&&(pt.$$scope={dirty:i,ctx:e}),me.$set(pt)},i(e){Mn||(g(Ge.$$.fragment,e),g(Be.$$.fragment,e),g(Ie.$$.fragment,e),g(Xe.$$.fragment,e),g(Ve.$$.fragment,e),g(Ce.$$.fragment,e),g(Ne.$$.fragment,e),g($e.$$.fragment,e),g(ze.$$.fragment,e),g(me.$$.fragment,e),g(xe.$$.fragment,e),g(Ae.$$.fragment,e),g(Qe.$$.fragment,e),g(Ye.$$.fragment,e),g(Se.$$.fragment,e),g(De.$$.fragment,e),g(Le.$$.fragment,e),g(Pe.$$.fragment,e),g(Ke.$$.fragment,e),g(Oe.$$.fragment,e),g(et.$$.fragment,e),g(tt.$$.fragment,e),g(st.$$.fragment,e),g(nt.$$.fragment,e),g(lt.$$.fragment,e),g(rt.$$.fragment,e),g(it.$$.fragment,e),Mn=!0)},o(e){f(Ge.$$.fragment,e),f(Be.$$.fragment,e),f(Ie.$$.fragment,e),f(Xe.$$.fragment,e),f(Ve.$$.fragment,e),f(Ce.$$.fragment,e),f(Ne.$$.fragment,e),f($e.$$.fragment,e),f(ze.$$.fragment,e),f(me.$$.fragment,e),f(xe.$$.fragment,e),f(Ae.$$.fragment,e),f(Qe.$$.fragment,e),f(Ye.$$.fragment,e),f(Se.$$.fragment,e),f(De.$$.fragment,e),f(Le.$$.fragment,e),f(Pe.$$.fragment,e),f(Ke.$$.fragment,e),f(Oe.$$.fragment,e),f(et.$$.fragment,e),f(tt.$$.fragment,e),f(st.$$.fragment,e),f(nt.$$.fragment,e),f(lt.$$.fragment,e),f(rt.$$.fragment,e),f(it.$$.fragment,e),Mn=!1},d(e){s(w),e&&s(ae),e&&s(j),M(Ge),e&&s(da),e&&s(ht),e&&s(ma),e&&s(ne),e&&s(ua),e&&s(X),e&&s(ya),e&&s(gt),e&&s(ga),e&&s(le),e&&s(fa),e&&s(ft),e&&s(Ma),e&&s(V),e&&s(ba),e&&s(H),M(Be),e&&s(wa),e&&s(C),e&&s(va),e&&s(re),e&&s(ja),M(Ie,e),e&&s(Ta),e&&s(ie),e&&s(Ua),e&&s(bt),e&&s(Ja),e&&s(Q),M(Xe),e&&s(ka),e&&s(R),e&&s(_a),M(Ve,e),e&&s(Za),e&&s(wt),e&&s(Ea),e&&s(Z),e&&s(Wa),e&&s(Y),M(Ce),e&&s(Ga),e&&s(Ut),e&&s(Ba),e&&s(E),e&&s(Ia),M(Ne,e),e&&s(Xa),e&&s(W),e&&s(Va),M($e,e),e&&s(Ca),e&&s(q),M(ze),e&&s(Ra),e&&s(b),e&&s(Na),M(me,e),e&&s($a),e&&s(N),e&&s(za),M(xe,e),e&&s(xa),e&&s(D),M(Ae),e&&s(Aa),e&&s(G),e&&s(Ha),e&&s(Wt),e&&s(Qa),e&&s(L),M(Qe),e&&s(Ya),e&&s(I),e&&s(Sa),M(Ye,e),e&&s(Fa),e&&s(P),M(Se),e&&s(qa),e&&s(T),e&&s(Da),M(De,e),e&&s(La),e&&s(K),M(Le),e&&s(Pa),e&&s(Gt),e&&s(Ka),e&&s($),e&&s(Oa),M(Pe,e),e&&s(en),e&&s(O),M(Ke),e&&s(tn),e&&s(Bt),e&&s(sn),e&&s(be),e&&s(an),M(Oe,e),e&&s(nn),e&&s(ee),M(et),e&&s(ln),e&&s(z),e&&s(on),M(tt,e),e&&s(rn),e&&s(te),M(st),e&&s(pn),e&&s(U),e&&s(cn),M(nt,e),e&&s(hn),e&&s(B),e&&s(dn),e&&s(se),M(lt),e&&s(mn),e&&s(Te),e&&s(un),e&&s(Ue),e&&s(yn),M(rt,e),e&&s(gn),e&&s(Je),e&&s(fn),M(it,e)}}}const Jc={local:"text-generation-strategies",sections:[{local:"default-text-generation-configuration",title:"Default text generation configuration"},{local:"customize-text-generation",title:"Customize text generation"},{local:"save-a-custom-decoding-strategy-with-your-model",title:"Save a custom decoding strategy with your model"},{local:"streaming",title:"Streaming"},{local:"decoding-strategies",sections:[{local:"greedy-search",title:"Greedy Search"},{local:"contrastive-search",title:"Contrastive search"},{local:"multinomial-sampling",title:"Multinomial sampling"},{local:"beamsearch-decoding",title:"Beam-search decoding"},{local:"beamsearch-multinomial-sampling",title:"Beam-search multinomial sampling"},{local:"diverse-beam-search-decoding",title:"Diverse beam search decoding"},{local:"assisted-decoding",title:"Assisted Decoding"}],title:"Decoding strategies"}],title:"Text generation strategies"};function kc(ha){return vc(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Gc extends fc{constructor(w){super();Mc(this,w,kc,Uc,bc,{})}}export{Gc as default,Jc as metadata};
