import{S as ph,i as hh,s as ch,e as n,k as h,w as d,t as a,M as uh,c as r,d as s,m as c,a as i,x as m,h as o,b as u,G as t,g as p,y as g,q as f,o as _,B as v,v as dh}from"../chunks/vendor-hf-doc-builder.js";import{T as mh}from"../chunks/Tip-hf-doc-builder.js";import{I as E}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as A}from"../chunks/CodeBlock-hf-doc-builder.js";function gh(pa){let y,se;return{c(){y=n("p"),se=a("The API for the streamer classes is still under development and may change in the future.")},l(b){y=r(b,"P",{});var $=i(y);se=o($,"The API for the streamer classes is still under development and may change in the future."),$.forEach(s)},m(b,$){p(b,y,$),t(y,se)},d(b){b&&s(y)}}}function fh(pa){let y,se,b,$,Ht,Ce,Do,Bt,Io,ha,pt,Oo,ca,ae,Go,ht,No,Ho,ua,L,Wt,ct,Bo,Wo,Yt,ut,Yo,Uo,Ut,dt,Xo,da,mt,Ro,ma,oe,Ko,Xt,Jo,Qo,ga,gt,Vo,fa,P,Rt,Zo,en,Kt,tn,sn,Jt,an,_a,H,ne,Qt,ze,on,Vt,nn,va,F,rn,ft,ln,pn,Zt,hn,cn,ka,re,un,es,dn,mn,ya,Me,wa,ie,gn,ts,fn,_n,ba,_t,vn,ja,B,le,ss,Se,kn,as,yn,$a,D,wn,os,bn,jn,ns,$n,En,Ea,Le,Aa,vt,An,Ta,T,kt,rs,Tn,qn,xn,yt,is,Cn,zn,Mn,pe,ls,Sn,Ln,ps,Pn,Fn,Dn,wt,hs,In,On,qa,W,he,cs,Pe,Gn,us,Nn,xa,bt,Hn,Ca,q,Fe,Bn,jt,Wn,Yn,Un,ds,Xn,Rn,Y,Kn,$t,Jn,Qn,ms,Vn,Zn,er,U,tr,gs,sr,ar,fs,or,nr,za,De,Ma,x,rr,_s,ir,lr,Et,pr,hr,At,cr,ur,Sa,Ie,La,X,ce,vs,Oe,dr,ks,mr,Pa,k,gr,ys,fr,_r,ws,vr,kr,bs,yr,wr,js,br,jr,$s,$r,Er,Es,Ar,Tr,As,qr,xr,Fa,ue,Da,I,Cr,Tt,zr,Mr,Ts,Sr,Lr,Ia,Ge,Oa,R,de,qs,Ne,Pr,xs,Fr,Ga,C,Dr,Cs,Ir,Or,zs,Gr,Nr,He,Hr,Br,Na,qt,Wr,Ha,K,me,Ms,Be,Yr,Ss,Ur,Ba,S,Ls,Xr,Rr,Ps,Kr,Jr,Fs,Qr,Vr,Wa,We,Ya,J,ge,Ds,Ye,Zr,Is,ei,Ua,j,ti,Ue,si,ai,Xe,oi,ni,Os,ri,ii,Gs,li,pi,Xa,Re,Ra,Q,fe,Ns,Ke,hi,Hs,ci,Ka,xt,ui,Ja,O,di,Bs,mi,gi,Ws,fi,_i,Qa,Je,Va,V,_e,Ys,Qe,vi,Us,ki,Za,Ct,yi,eo,ve,wi,Xs,bi,ji,to,Ve,so,Z,ke,Rs,Ze,$i,Ks,Ei,ao,G,Ai,Js,Ti,qi,Qs,xi,Ci,oo,et,no,ee,ye,Vs,tt,zi,Zs,Mi,ro,z,Si,st,Li,Pi,ea,Fi,Di,ta,Ii,Oi,io,at,lo,M,Gi,sa,Ni,Hi,aa,Bi,Wi,zt,Yi,Ui,po,te,we,oa,ot,Xi,na,Ri,ho,Mt,Ki,co,be,Ji,ra,Qi,Vi,uo,nt,mo,je,Zi,ia,el,tl,go,rt,fo;return Ce=new E({}),ze=new E({}),Me=new A({props:{code:`from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("distilgpt2")
model.generation_config`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM

<span class="hljs-meta">&gt;&gt;&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;_from_model_config&quot;</span>: true,
    <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>,
    <span class="hljs-string">&quot;transformers_version&quot;</span>: <span class="hljs-string">&quot;4.26.0.dev0&quot;</span>
}`}}),Se=new E({}),Le=new A({props:{code:"my_model.generate(**inputs, num_beams=4, do_sample=True)",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>)'}}),Pe=new E({}),De=new A({props:{code:`from transformers import AutoModelForCausalLM, GenerationConfig

model = AutoModelForCausalLM.from_pretrained("my_account/my_model")
generation_config = GenerationConfig(
    max_new_tokens=50, do_sample=True, top_k=50, eos_token_id=model.config.eos_token_id
)
generation_config.save_pretrained("my_account/my_model", push_to_hub=True)`,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>)`}}),Ie=new A({props:{code:`from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, GenerationConfig

tokenizer = AutoTokenizer.from_pretrained("t5-small")
model = AutoModelForSeq2SeqLM.from_pretrained("t5-small")

translation_generation_config = GenerationConfig(
    num_beams=4,
    early_stopping=True,
    decoder_start_token_id=0,
    eos_token_id=model.config.eos_token_id,
    pad_token=model.config.pad_token_id,
)

translation_generation_config.save_pretrained("t5-small", "translation_generation_config.json", push_to_hub=True)

# You could then use the named generation config file to parameterize generation
generation_config = GenerationConfig.from_pretrained("t5-small", "translation_generation_config.json")
inputs = tokenizer("translate English to French: Configuration files are easy to use!", return_tensors="pt")
outputs = model.generate(**inputs, generation_config=generation_config)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))`,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>translation_generation_config.save_pretrained(<span class="hljs-string">&quot;t5-small&quot;</span>, <span class="hljs-string">&quot;translation_generation_config.json&quot;</span>, push_to_hub=<span class="hljs-literal">True</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;t5-small&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>]`}}),Oe=new E({}),ue=new mh({props:{warning:!0,$$slots:{default:[gh]},$$scope:{ctx:pa}}}),Ge=new A({props:{code:`from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer

tok = AutoTokenizer.from_pretrained("gpt2")
model = AutoModelForCausalLM.from_pretrained("gpt2")
inputs = tok(["An increasing sequence: one,"], return_tensors="pt")
streamer = TextStreamer(tok)

# Despite returning the usual output, the streamer will also print the generated text to stdout.
_ = model.generate(**inputs, streamer=streamer, max_new_tokens=20)`,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,`}}),Ne=new E({}),Be=new E({}),We=new A({props:{code:`from transformers import AutoModelForCausalLM, AutoTokenizer

prompt = "I look forward to"
checkpoint = "distilgpt2"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForCausalLM.from_pretrained(checkpoint)
outputs = model.generate(**inputs)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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>]`}}),Ye=new E({}),Re=new A({props:{code:`from transformers import AutoTokenizer, AutoModelForCausalLM

checkpoint = "gpt2-large"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint)

prompt = "Hugging Face Company is"
inputs = tokenizer(prompt, return_tensors="pt")

outputs = model.generate(**inputs, penalty_alpha=0.6, top_k=4, max_new_tokens=100)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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>]`}}),Ke=new E({}),Je=new A({props:{code:`from transformers import AutoTokenizer, AutoModelForCausalLM

checkpoint = "gpt2-large"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint)

prompt = "Today was an amazing day because"
inputs = tokenizer(prompt, return_tensors="pt")

outputs = model.generate(**inputs, do_sample=True, num_beams=1, max_new_tokens=100)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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;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 we are now in the final stages of our trip to New York City which was very tough. \\
It is a difficult schedule and a challenging part of the year but still worth it. I have been taking things easier and \\
I feel stronger and more motivated to be out there on their tour. Hopefully, that experience is going to help them with \\
their upcoming events which are currently scheduled in Australia.\\n\\nWe love that they are here. They want to make a \\
name for themselves and become famous for what they&#x27;</span>]`}}),Qe=new E({}),Ve=new A({props:{code:`from transformers import AutoModelForCausalLM, AutoTokenizer

prompt = "It is astonishing how one can"
checkpoint = "gpt2-medium"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForCausalLM.from_pretrained(checkpoint)

outputs = model.generate(**inputs, num_beams=5, max_new_tokens=50)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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>]`}}),Ze=new E({}),et=new A({props:{code:`from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

prompt = "translate English to German: The house is wonderful."
checkpoint = "t5-small"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

outputs = model.generate(**inputs, num_beams=5, do_sample=True)
tokenizer.decode(outputs[0], skip_special_tokens=True)`,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>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>`}}),tt=new E({}),at=new A({props:{code:`from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

checkpoint = "google/pegasus-xsum"
prompt = "The Permaculture 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 most efficient and sustainable human habitation and food production systems. \\
Permaculture is a design system that encompasses a wide variety of disciplines, such \\
as ecology, landscape design, environmental science and energy conservation, and the \\
Permaculture design principles are drawn from these various disciplines. Each individual \\
design principle itself embodies a complete conceptual framework based on sound \\
scientific principles. When we bring all these separate  principles together, we can \\
create a design system that both looks at whole systems, the parts that these systems \\
consist of, and how those parts interact with each other to create a complex, dynamic, \\
living system. Each design principle serves as a tool that allows us to integrate all \\
the separate parts of a design, referred to as elements, into a functional, synergistic, \\
whole system, where the elements harmoniously interact and work together in the most \\
efficient way possible."

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)

outputs = model.generate(**inputs, num_beams=5, num_beam_groups=5, max_new_tokens=30)
tokenizer.decode(outputs[0], skip_special_tokens=True)`,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-string">&quot;The Permaculture Design Principles are a set of universal design principles \\
&gt;&gt;&gt; that can be applied to any location, climate and culture, and they allow us to design \\
&gt;&gt;&gt; the most efficient and sustainable human habitation and food production systems. \\
&gt;&gt;&gt; Permaculture is a design system that encompasses a wide variety of disciplines, such \\
&gt;&gt;&gt; as ecology, landscape design, environmental science and energy conservation, and the \\
&gt;&gt;&gt; Permaculture design principles are drawn from these various disciplines. Each individual \\
&gt;&gt;&gt; design principle itself embodies a complete conceptual framework based on sound \\
&gt;&gt;&gt; scientific principles. When we bring all these separate  principles together, we can \\
&gt;&gt;&gt; create a design system that both looks at whole systems, the parts that these systems \\
&gt;&gt;&gt; consist of, and how those parts interact with each other to create a complex, dynamic, \\
&gt;&gt;&gt; living system. Each design principle serves as a tool that allows us to integrate all \\
&gt;&gt;&gt; the separate parts of a design, referred to as elements, into a functional, synergistic, \\
&gt;&gt;&gt; whole system, where the elements harmoniously interact and work together in the most \\
&gt;&gt;&gt; efficient way possible.&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>, num_beam_groups=<span class="hljs-number">5</span>, max_new_tokens=<span class="hljs-number">30</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 most efficient and sustainable human habitation and food production systems.&#x27;</span>`}}),ot=new E({}),nt=new A({props:{code:`from transformers import AutoModelForCausalLM, AutoTokenizer

prompt = "Alice and Bob"
checkpoint = "EleutherAI/pythia-1.4b-deduped"
assistant_checkpoint = "EleutherAI/pythia-160m-deduped"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForCausalLM.from_pretrained(checkpoint)
assistant_model = AutoModelForCausalLM.from_pretrained(assistant_checkpoint)
outputs = model.generate(**inputs, assistant_model=assistant_model)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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>]`}}),rt=new A({props:{code:`from transformers import AutoModelForCausalLM, AutoTokenizer

prompt = "Alice and Bob"
checkpoint = "EleutherAI/pythia-1.4b-deduped"
assistant_checkpoint = "EleutherAI/pythia-160m-deduped"

tokenizer = AutoTokenizer.from_pretrained(checkpoint)
inputs = tokenizer(prompt, return_tensors="pt")

model = AutoModelForCausalLM.from_pretrained(checkpoint)
assistant_model = AutoModelForCausalLM.from_pretrained(assistant_checkpoint)
outputs = model.generate(**inputs, assistant_model=assistant_model, do_sample=True, temperature=0.5)
tokenizer.batch_decode(outputs, skip_special_tokens=True)`,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, 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">&quot;Alice and Bob are sitting on the sofa. Alice says, &#x27;I&#x27;m going to my room&quot;</span>]`}}),{c(){y=n("meta"),se=h(),b=n("h1"),$=n("a"),Ht=n("span"),d(Ce.$$.fragment),Do=h(),Bt=n("span"),Io=a("Text generation strategies"),ha=h(),pt=n("p"),Oo=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.`),ca=h(),ae=n("p"),Go=a("Check out a few examples that use "),ht=n("a"),No=a("generate()"),Ho=a(` method to produce
text outputs for different tasks:`),ua=h(),L=n("ul"),Wt=n("li"),ct=n("a"),Bo=a("Text summarization"),Wo=h(),Yt=n("li"),ut=n("a"),Yo=a("Image captioning"),Uo=h(),Ut=n("li"),dt=n("a"),Xo=a("Audio transcription"),da=h(),mt=n("p"),Ro=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.`),ma=h(),oe=n("p"),Ko=a(`The process of selecting output tokens to generate text is known as decoding, and you can customize the decoding strategy
that the `),Xt=n("code"),Jo=a("generate()"),Qo=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.`),ga=h(),gt=n("p"),Vo=a("This guide describes:"),fa=h(),P=n("ul"),Rt=n("li"),Zo=a("default generation configuration"),en=h(),Kt=n("li"),tn=a("common decoding strategies and their main parameters"),sn=h(),Jt=n("li"),an=a("saving and sharing custom generation configurations with your fine-tuned model on \u{1F917} Hub"),_a=h(),H=n("h2"),ne=n("a"),Qt=n("span"),d(ze.$$.fragment),on=h(),Vt=n("span"),nn=a("Default text generation configuration"),va=h(),F=n("p"),rn=a(`A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference
within a `),ft=n("a"),ln=a("pipeline()"),pn=a(", the models call the "),Zt=n("code"),hn=a("PreTrainedModel.generate()"),cn=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.`),ka=h(),re=n("p"),un=a(`When you load a model explicitly, you can inspect the generation configuration that comes with it through
`),es=n("code"),dn=a("model.generation_config"),mn=a(":"),ya=h(),d(Me.$$.fragment),wa=h(),ie=n("p"),gn=a("Printing out the "),ts=n("code"),fn=a("model.generation_config"),_n=a(` reveals only the values that are different from the default generation
configuration, and does not list any of the default values.`),ba=h(),_t=n("p"),vn=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=h(),B=n("h2"),le=n("a"),ss=n("span"),d(Se.$$.fragment),kn=h(),as=n("span"),yn=a("Customize text generation"),$a=h(),D=n("p"),wn=a("You can override any "),os=n("code"),bn=a("generation_config"),jn=a(" by passing the parameters and their values directly to the "),ns=n("code"),$n=a("generate"),En=a(" method:"),Ea=h(),d(Le.$$.fragment),Aa=h(),vt=n("p"),An=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:`),Ta=h(),T=n("ul"),kt=n("li"),rs=n("code"),Tn=a("max_new_tokens"),qn=a(`: the maximum number of tokens to generate. In other words, the size of the output sequence, not
including the tokens in the prompt.`),xn=h(),yt=n("li"),is=n("code"),Cn=a("num_beams"),zn=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.`),Mn=h(),pe=n("li"),ls=n("code"),Sn=a("do_sample"),Ln=a(": if set to "),ps=n("code"),Pn=a("True"),Fn=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.`),Dn=h(),wt=n("li"),hs=n("code"),In=a("num_return_sequences"),On=a(`: the number of sequence candidates to return for each input. This options 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.`),qa=h(),W=n("h2"),he=n("a"),cs=n("span"),d(Pe.$$.fragment),Gn=h(),us=n("span"),Nn=a("Save a custom decoding strategy with your model"),xa=h(),bt=n("p"),Hn=a("If you would like to share your fine-tuned model with a specific generation configuration, you can:"),Ca=h(),q=n("ul"),Fe=n("li"),Bn=a("Create a "),jt=n("a"),Wn=a("GenerationConfig"),Yn=a(" class instance"),Un=h(),ds=n("li"),Xn=a("Specify the decoding strategy parameters"),Rn=h(),Y=n("li"),Kn=a("Save your generation configuration with "),$t=n("a"),Jn=a("GenerationConfig.save_pretrained()"),Qn=a(", making sure to leave its "),ms=n("code"),Vn=a("config_file_name"),Zn=a(" argument empty"),er=h(),U=n("li"),tr=a("Set "),gs=n("code"),sr=a("push_to_hub"),ar=a(" to "),fs=n("code"),or=a("True"),nr=a(" to upload your config to the model\u2019s repo"),za=h(),d(De.$$.fragment),Ma=h(),x=n("p"),rr=a("You can also store several generation configurations in a single directory, making use of the "),_s=n("code"),ir=a("config_file_name"),lr=a(`
argument in `),Et=n("a"),pr=a("GenerationConfig.save_pretrained()"),hr=a(". You can later instantiate them with "),At=n("a"),cr=a("GenerationConfig.from_pretrained()"),ur=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.`),Sa=h(),d(Ie.$$.fragment),La=h(),X=n("h2"),ce=n("a"),vs=n("span"),d(Oe.$$.fragment),dr=h(),ks=n("span"),mr=a("Streaming"),Pa=h(),k=n("p"),gr=a("The "),ys=n("code"),fr=a("generate()"),_r=a(" supports streaming, through its "),ws=n("code"),vr=a("streamer"),kr=a(" input. The "),bs=n("code"),yr=a("streamer"),wr=a(` input is compatible any instance
from a class that has the following methods: `),js=n("code"),br=a("put()"),jr=a(" and "),$s=n("code"),$r=a("end()"),Er=a(". Internally, "),Es=n("code"),Ar=a("put()"),Tr=a(` is used to push new tokens and
`),As=n("code"),qr=a("end()"),xr=a(" is used to flag the end of text generation."),Fa=h(),d(ue.$$.fragment),Da=h(),I=n("p"),Cr=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 `),Tt=n("a"),zr=a("TextStreamer"),Mr=a(" class to stream the output of "),Ts=n("code"),Sr=a("generate()"),Lr=a(` into
your screen, one word at a time:`),Ia=h(),d(Ge.$$.fragment),Oa=h(),R=n("h2"),de=n("a"),qs=n("span"),d(Ne.$$.fragment),Pr=h(),xs=n("span"),Fr=a("Decoding strategies"),Ga=h(),C=n("p"),Dr=a("Certain combinations of the "),Cs=n("code"),Ir=a("generate()"),Or=a(" parameters, and ultimately "),zs=n("code"),Gr=a("generation_config"),Nr=a(`, can be used to enable specific
decoding strategies. If you are new to this concept, we recommend reading `),He=n("a"),Hr=a("this blog post that illustrates how common decoding strategies work"),Br=a("."),Na=h(),qt=n("p"),Wr=a("Here, we\u2019ll show some of the parameters that control the decoding strategies and illustrate how you can use them."),Ha=h(),K=n("h3"),me=n("a"),Ms=n("span"),d(Be.$$.fragment),Yr=h(),Ss=n("span"),Ur=a("Greedy Search"),Ba=h(),S=n("p"),Ls=n("code"),Xr=a("generate"),Rr=a(" uses greedy search decoding by default so you don\u2019t have to pass any parameters to enable it. This means the parameters "),Ps=n("code"),Kr=a("num_beams"),Jr=a(" is set to 1 and "),Fs=n("code"),Qr=a("do_sample=False"),Vr=a("."),Wa=h(),d(We.$$.fragment),Ya=h(),J=n("h3"),ge=n("a"),Ds=n("span"),d(Ye.$$.fragment),Zr=h(),Is=n("span"),ei=a("Contrastive search"),Ua=h(),j=n("p"),ti=a("The contrastive search decoding strategy was proposed in the 2022 paper "),Ue=n("a"),si=a("A Contrastive Framework for Neural Text Generation"),ai=a(`.
It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search
works, check out `),Xe=n("a"),oi=a("this blog post"),ni=a(`.
The two main parameters that enable and control the behavior of contrastive search are `),Os=n("code"),ri=a("penalty_alpha"),ii=a(" and "),Gs=n("code"),li=a("top_k"),pi=a(":"),Xa=h(),d(Re.$$.fragment),Ra=h(),Q=n("h3"),fe=n("a"),Ns=n("span"),d(Ke.$$.fragment),hi=h(),Hs=n("span"),ci=a("Multinomial sampling"),Ka=h(),xt=n("p"),ui=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.`),Ja=h(),O=n("p"),di=a("To enable multinomial sampling set "),Bs=n("code"),mi=a("do_sample=True"),gi=a(" and "),Ws=n("code"),fi=a("num_beams=1"),_i=a("."),Qa=h(),d(Je.$$.fragment),Va=h(),V=n("h3"),_e=n("a"),Ys=n("span"),d(Qe.$$.fragment),vi=h(),Us=n("span"),ki=a("Beam-search decoding"),Za=h(),Ct=n("p"),yi=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.`),eo=h(),ve=n("p"),wi=a("To enable this decoding strategy, specify the "),Xs=n("code"),bi=a("num_beams"),ji=a(" (aka number of hypotheses to keep track of) that is greater than 1."),to=h(),d(Ve.$$.fragment),so=h(),Z=n("h3"),ke=n("a"),Rs=n("span"),d(Ze.$$.fragment),$i=h(),Ks=n("span"),Ei=a("Beam-search multinomial sampling"),ao=h(),G=n("p"),Ai=a(`As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify
the `),Js=n("code"),Ti=a("num_beams"),qi=a(" greater than 1, and set "),Qs=n("code"),xi=a("do_sample=True"),Ci=a(" to use this decoding strategy."),oo=h(),d(et.$$.fragment),no=h(),ee=n("h3"),ye=n("a"),Vs=n("span"),d(tt.$$.fragment),zi=h(),Zs=n("span"),Mi=a("Diverse beam search decoding"),ro=h(),z=n("p"),Si=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 `),st=n("a"),Li=a("Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models"),Pi=a(`.
This approach has two main parameters: `),ea=n("code"),Fi=a("num_beams"),Di=a(" and "),ta=n("code"),Ii=a("num_beam_groups"),Oi=a(`.
The groups are selected to ensure they are distinct enough compared to the others, and regular beam search is used within each group.`),io=h(),d(at.$$.fragment),lo=h(),M=n("p"),Gi=a(`This guide illustrates the main parameters that enable various decoding strategies. More advanced parameters exist for the
`),sa=n("code"),Ni=a("generate"),Hi=a(" method, which gives you even further control over the "),aa=n("code"),Bi=a("generate"),Wi=a(` method\u2019s behavior.
For the complete list of the available parameters, refer to the `),zt=n("a"),Yi=a("API documentation"),Ui=a("."),po=h(),te=n("h3"),we=n("a"),oa=n("span"),d(ot.$$.fragment),Xi=h(),na=n("span"),Ri=a("Assisted Decoding"),ho=h(),Mt=n("p"),Ki=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.`),co=h(),be=n("p"),Ji=a("To enable assisted decoding, set the "),ra=n("code"),Qi=a("assistant_model"),Vi=a(" argument with a model."),uo=h(),d(nt.$$.fragment),mo=h(),je=n("p"),Zi=a("When using assisted decoding with sampling methods, you can use the "),ia=n("code"),el=a("temperarure"),tl=a(` argument to control the randomness
just like in multinomial sampling. However, in assisted decoding, reducing the temperature will help improving latency.`),go=h(),d(rt.$$.fragment),this.h()},l(e){const l=uh('[data-svelte="svelte-1phssyn"]',document.head);y=r(l,"META",{name:!0,content:!0}),l.forEach(s),se=c(e),b=r(e,"H1",{class:!0});var it=i(b);$=r(it,"A",{id:!0,class:!0,href:!0});var nl=i($);Ht=r(nl,"SPAN",{});var rl=i(Ht);m(Ce.$$.fragment,rl),rl.forEach(s),nl.forEach(s),Do=c(it),Bt=r(it,"SPAN",{});var il=i(Bt);Io=o(il,"Text generation strategies"),il.forEach(s),it.forEach(s),ha=c(e),pt=r(e,"P",{});var ll=i(pt);Oo=o(ll,`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.`),ll.forEach(s),ca=c(e),ae=r(e,"P",{});var _o=i(ae);Go=o(_o,"Check out a few examples that use "),ht=r(_o,"A",{href:!0});var pl=i(ht);No=o(pl,"generate()"),pl.forEach(s),Ho=o(_o,` method to produce
text outputs for different tasks:`),_o.forEach(s),ua=c(e),L=r(e,"UL",{});var St=i(L);Wt=r(St,"LI",{});var hl=i(Wt);ct=r(hl,"A",{href:!0});var cl=i(ct);Bo=o(cl,"Text summarization"),cl.forEach(s),hl.forEach(s),Wo=c(St),Yt=r(St,"LI",{});var ul=i(Yt);ut=r(ul,"A",{href:!0});var dl=i(ut);Yo=o(dl,"Image captioning"),dl.forEach(s),ul.forEach(s),Uo=c(St),Ut=r(St,"LI",{});var ml=i(Ut);dt=r(ml,"A",{href:!0});var gl=i(dt);Xo=o(gl,"Audio transcription"),gl.forEach(s),ml.forEach(s),St.forEach(s),da=c(e),mt=r(e,"P",{});var fl=i(mt);Ro=o(fl,`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.`),fl.forEach(s),ma=c(e),oe=r(e,"P",{});var vo=i(oe);Ko=o(vo,`The process of selecting output tokens to generate text is known as decoding, and you can customize the decoding strategy
that the `),Xt=r(vo,"CODE",{});var _l=i(Xt);Jo=o(_l,"generate()"),_l.forEach(s),Qo=o(vo,` 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.`),vo.forEach(s),ga=c(e),gt=r(e,"P",{});var vl=i(gt);Vo=o(vl,"This guide describes:"),vl.forEach(s),fa=c(e),P=r(e,"UL",{});var Lt=i(P);Rt=r(Lt,"LI",{});var kl=i(Rt);Zo=o(kl,"default generation configuration"),kl.forEach(s),en=c(Lt),Kt=r(Lt,"LI",{});var yl=i(Kt);tn=o(yl,"common decoding strategies and their main parameters"),yl.forEach(s),sn=c(Lt),Jt=r(Lt,"LI",{});var wl=i(Jt);an=o(wl,"saving and sharing custom generation configurations with your fine-tuned model on \u{1F917} Hub"),wl.forEach(s),Lt.forEach(s),_a=c(e),H=r(e,"H2",{class:!0});var ko=i(H);ne=r(ko,"A",{id:!0,class:!0,href:!0});var bl=i(ne);Qt=r(bl,"SPAN",{});var jl=i(Qt);m(ze.$$.fragment,jl),jl.forEach(s),bl.forEach(s),on=c(ko),Vt=r(ko,"SPAN",{});var $l=i(Vt);nn=o($l,"Default text generation configuration"),$l.forEach(s),ko.forEach(s),va=c(e),F=r(e,"P",{});var Pt=i(F);rn=o(Pt,`A decoding strategy for a model is defined in its generation configuration. When using pre-trained models for inference
within a `),ft=r(Pt,"A",{href:!0});var El=i(ft);ln=o(El,"pipeline()"),El.forEach(s),pn=o(Pt,", the models call the "),Zt=r(Pt,"CODE",{});var Al=i(Zt);hn=o(Al,"PreTrainedModel.generate()"),Al.forEach(s),cn=o(Pt,` 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.`),Pt.forEach(s),ka=c(e),re=r(e,"P",{});var yo=i(re);un=o(yo,`When you load a model explicitly, you can inspect the generation configuration that comes with it through
`),es=r(yo,"CODE",{});var Tl=i(es);dn=o(Tl,"model.generation_config"),Tl.forEach(s),mn=o(yo,":"),yo.forEach(s),ya=c(e),m(Me.$$.fragment,e),wa=c(e),ie=r(e,"P",{});var wo=i(ie);gn=o(wo,"Printing out the "),ts=r(wo,"CODE",{});var ql=i(ts);fn=o(ql,"model.generation_config"),ql.forEach(s),_n=o(wo,` reveals only the values that are different from the default generation
configuration, and does not list any of the default values.`),wo.forEach(s),ba=c(e),_t=r(e,"P",{});var xl=i(_t);vn=o(xl,`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.`),xl.forEach(s),ja=c(e),B=r(e,"H2",{class:!0});var bo=i(B);le=r(bo,"A",{id:!0,class:!0,href:!0});var Cl=i(le);ss=r(Cl,"SPAN",{});var zl=i(ss);m(Se.$$.fragment,zl),zl.forEach(s),Cl.forEach(s),kn=c(bo),as=r(bo,"SPAN",{});var Ml=i(as);yn=o(Ml,"Customize text generation"),Ml.forEach(s),bo.forEach(s),$a=c(e),D=r(e,"P",{});var Ft=i(D);wn=o(Ft,"You can override any "),os=r(Ft,"CODE",{});var Sl=i(os);bn=o(Sl,"generation_config"),Sl.forEach(s),jn=o(Ft," by passing the parameters and their values directly to the "),ns=r(Ft,"CODE",{});var Ll=i(ns);$n=o(Ll,"generate"),Ll.forEach(s),En=o(Ft," method:"),Ft.forEach(s),Ea=c(e),m(Le.$$.fragment,e),Aa=c(e),vt=r(e,"P",{});var Pl=i(vt);An=o(Pl,`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:`),Pl.forEach(s),Ta=c(e),T=r(e,"UL",{});var $e=i(T);kt=r($e,"LI",{});var sl=i(kt);rs=r(sl,"CODE",{});var Fl=i(rs);Tn=o(Fl,"max_new_tokens"),Fl.forEach(s),qn=o(sl,`: the maximum number of tokens to generate. In other words, the size of the output sequence, not
including the tokens in the prompt.`),sl.forEach(s),xn=c($e),yt=r($e,"LI",{});var al=i(yt);is=r(al,"CODE",{});var Dl=i(is);Cn=o(Dl,"num_beams"),Dl.forEach(s),zn=o(al,`: 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.`),al.forEach(s),Mn=c($e),pe=r($e,"LI",{});var la=i(pe);ls=r(la,"CODE",{});var Il=i(ls);Sn=o(Il,"do_sample"),Il.forEach(s),Ln=o(la,": if set to "),ps=r(la,"CODE",{});var Ol=i(ps);Pn=o(Ol,"True"),Ol.forEach(s),Fn=o(la,`, 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.`),la.forEach(s),Dn=c($e),wt=r($e,"LI",{});var ol=i(wt);hs=r(ol,"CODE",{});var Gl=i(hs);In=o(Gl,"num_return_sequences"),Gl.forEach(s),On=o(ol,`: the number of sequence candidates to return for each input. This options 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.`),ol.forEach(s),$e.forEach(s),qa=c(e),W=r(e,"H2",{class:!0});var jo=i(W);he=r(jo,"A",{id:!0,class:!0,href:!0});var Nl=i(he);cs=r(Nl,"SPAN",{});var Hl=i(cs);m(Pe.$$.fragment,Hl),Hl.forEach(s),Nl.forEach(s),Gn=c(jo),us=r(jo,"SPAN",{});var Bl=i(us);Nn=o(Bl,"Save a custom decoding strategy with your model"),Bl.forEach(s),jo.forEach(s),xa=c(e),bt=r(e,"P",{});var Wl=i(bt);Hn=o(Wl,"If you would like to share your fine-tuned model with a specific generation configuration, you can:"),Wl.forEach(s),Ca=c(e),q=r(e,"UL",{});var Ee=i(q);Fe=r(Ee,"LI",{});var $o=i(Fe);Bn=o($o,"Create a "),jt=r($o,"A",{href:!0});var Yl=i(jt);Wn=o(Yl,"GenerationConfig"),Yl.forEach(s),Yn=o($o," class instance"),$o.forEach(s),Un=c(Ee),ds=r(Ee,"LI",{});var Ul=i(ds);Xn=o(Ul,"Specify the decoding strategy parameters"),Ul.forEach(s),Rn=c(Ee),Y=r(Ee,"LI",{});var Dt=i(Y);Kn=o(Dt,"Save your generation configuration with "),$t=r(Dt,"A",{href:!0});var Xl=i($t);Jn=o(Xl,"GenerationConfig.save_pretrained()"),Xl.forEach(s),Qn=o(Dt,", making sure to leave its "),ms=r(Dt,"CODE",{});var Rl=i(ms);Vn=o(Rl,"config_file_name"),Rl.forEach(s),Zn=o(Dt," argument empty"),Dt.forEach(s),er=c(Ee),U=r(Ee,"LI",{});var It=i(U);tr=o(It,"Set "),gs=r(It,"CODE",{});var Kl=i(gs);sr=o(Kl,"push_to_hub"),Kl.forEach(s),ar=o(It," to "),fs=r(It,"CODE",{});var Jl=i(fs);or=o(Jl,"True"),Jl.forEach(s),nr=o(It," to upload your config to the model\u2019s repo"),It.forEach(s),Ee.forEach(s),za=c(e),m(De.$$.fragment,e),Ma=c(e),x=r(e,"P",{});var Ae=i(x);rr=o(Ae,"You can also store several generation configurations in a single directory, making use of the "),_s=r(Ae,"CODE",{});var Ql=i(_s);ir=o(Ql,"config_file_name"),Ql.forEach(s),lr=o(Ae,`
argument in `),Et=r(Ae,"A",{href:!0});var Vl=i(Et);pr=o(Vl,"GenerationConfig.save_pretrained()"),Vl.forEach(s),hr=o(Ae,". You can later instantiate them with "),At=r(Ae,"A",{href:!0});var Zl=i(At);cr=o(Zl,"GenerationConfig.from_pretrained()"),Zl.forEach(s),ur=o(Ae,`. 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.`),Ae.forEach(s),Sa=c(e),m(Ie.$$.fragment,e),La=c(e),X=r(e,"H2",{class:!0});var Eo=i(X);ce=r(Eo,"A",{id:!0,class:!0,href:!0});var ep=i(ce);vs=r(ep,"SPAN",{});var tp=i(vs);m(Oe.$$.fragment,tp),tp.forEach(s),ep.forEach(s),dr=c(Eo),ks=r(Eo,"SPAN",{});var sp=i(ks);mr=o(sp,"Streaming"),sp.forEach(s),Eo.forEach(s),Pa=c(e),k=r(e,"P",{});var w=i(k);gr=o(w,"The "),ys=r(w,"CODE",{});var ap=i(ys);fr=o(ap,"generate()"),ap.forEach(s),_r=o(w," supports streaming, through its "),ws=r(w,"CODE",{});var op=i(ws);vr=o(op,"streamer"),op.forEach(s),kr=o(w," input. The "),bs=r(w,"CODE",{});var np=i(bs);yr=o(np,"streamer"),np.forEach(s),wr=o(w,` input is compatible any instance
from a class that has the following methods: `),js=r(w,"CODE",{});var rp=i(js);br=o(rp,"put()"),rp.forEach(s),jr=o(w," and "),$s=r(w,"CODE",{});var ip=i($s);$r=o(ip,"end()"),ip.forEach(s),Er=o(w,". Internally, "),Es=r(w,"CODE",{});var lp=i(Es);Ar=o(lp,"put()"),lp.forEach(s),Tr=o(w,` is used to push new tokens and
`),As=r(w,"CODE",{});var pp=i(As);qr=o(pp,"end()"),pp.forEach(s),xr=o(w," is used to flag the end of text generation."),w.forEach(s),Fa=c(e),m(ue.$$.fragment,e),Da=c(e),I=r(e,"P",{});var Ot=i(I);Cr=o(Ot,`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 `),Tt=r(Ot,"A",{href:!0});var hp=i(Tt);zr=o(hp,"TextStreamer"),hp.forEach(s),Mr=o(Ot," class to stream the output of "),Ts=r(Ot,"CODE",{});var cp=i(Ts);Sr=o(cp,"generate()"),cp.forEach(s),Lr=o(Ot,` into
your screen, one word at a time:`),Ot.forEach(s),Ia=c(e),m(Ge.$$.fragment,e),Oa=c(e),R=r(e,"H2",{class:!0});var Ao=i(R);de=r(Ao,"A",{id:!0,class:!0,href:!0});var up=i(de);qs=r(up,"SPAN",{});var dp=i(qs);m(Ne.$$.fragment,dp),dp.forEach(s),up.forEach(s),Pr=c(Ao),xs=r(Ao,"SPAN",{});var mp=i(xs);Fr=o(mp,"Decoding strategies"),mp.forEach(s),Ao.forEach(s),Ga=c(e),C=r(e,"P",{});var Te=i(C);Dr=o(Te,"Certain combinations of the "),Cs=r(Te,"CODE",{});var gp=i(Cs);Ir=o(gp,"generate()"),gp.forEach(s),Or=o(Te," parameters, and ultimately "),zs=r(Te,"CODE",{});var fp=i(zs);Gr=o(fp,"generation_config"),fp.forEach(s),Nr=o(Te,`, can be used to enable specific
decoding strategies. If you are new to this concept, we recommend reading `),He=r(Te,"A",{href:!0,rel:!0});var _p=i(He);Hr=o(_p,"this blog post that illustrates how common decoding strategies work"),_p.forEach(s),Br=o(Te,"."),Te.forEach(s),Na=c(e),qt=r(e,"P",{});var vp=i(qt);Wr=o(vp,"Here, we\u2019ll show some of the parameters that control the decoding strategies and illustrate how you can use them."),vp.forEach(s),Ha=c(e),K=r(e,"H3",{class:!0});var To=i(K);me=r(To,"A",{id:!0,class:!0,href:!0});var kp=i(me);Ms=r(kp,"SPAN",{});var yp=i(Ms);m(Be.$$.fragment,yp),yp.forEach(s),kp.forEach(s),Yr=c(To),Ss=r(To,"SPAN",{});var wp=i(Ss);Ur=o(wp,"Greedy Search"),wp.forEach(s),To.forEach(s),Ba=c(e),S=r(e,"P",{});var lt=i(S);Ls=r(lt,"CODE",{});var bp=i(Ls);Xr=o(bp,"generate"),bp.forEach(s),Rr=o(lt," uses greedy search decoding by default so you don\u2019t have to pass any parameters to enable it. This means the parameters "),Ps=r(lt,"CODE",{});var jp=i(Ps);Kr=o(jp,"num_beams"),jp.forEach(s),Jr=o(lt," is set to 1 and "),Fs=r(lt,"CODE",{});var $p=i(Fs);Qr=o($p,"do_sample=False"),$p.forEach(s),Vr=o(lt,"."),lt.forEach(s),Wa=c(e),m(We.$$.fragment,e),Ya=c(e),J=r(e,"H3",{class:!0});var qo=i(J);ge=r(qo,"A",{id:!0,class:!0,href:!0});var Ep=i(ge);Ds=r(Ep,"SPAN",{});var Ap=i(Ds);m(Ye.$$.fragment,Ap),Ap.forEach(s),Ep.forEach(s),Zr=c(qo),Is=r(qo,"SPAN",{});var Tp=i(Is);ei=o(Tp,"Contrastive search"),Tp.forEach(s),qo.forEach(s),Ua=c(e),j=r(e,"P",{});var N=i(j);ti=o(N,"The contrastive search decoding strategy was proposed in the 2022 paper "),Ue=r(N,"A",{href:!0,rel:!0});var qp=i(Ue);si=o(qp,"A Contrastive Framework for Neural Text Generation"),qp.forEach(s),ai=o(N,`.
It demonstrates superior results for generating non-repetitive yet coherent long outputs. To learn how contrastive search
works, check out `),Xe=r(N,"A",{href:!0,rel:!0});var xp=i(Xe);oi=o(xp,"this blog post"),xp.forEach(s),ni=o(N,`.
The two main parameters that enable and control the behavior of contrastive search are `),Os=r(N,"CODE",{});var Cp=i(Os);ri=o(Cp,"penalty_alpha"),Cp.forEach(s),ii=o(N," and "),Gs=r(N,"CODE",{});var zp=i(Gs);li=o(zp,"top_k"),zp.forEach(s),pi=o(N,":"),N.forEach(s),Xa=c(e),m(Re.$$.fragment,e),Ra=c(e),Q=r(e,"H3",{class:!0});var xo=i(Q);fe=r(xo,"A",{id:!0,class:!0,href:!0});var Mp=i(fe);Ns=r(Mp,"SPAN",{});var Sp=i(Ns);m(Ke.$$.fragment,Sp),Sp.forEach(s),Mp.forEach(s),hi=c(xo),Hs=r(xo,"SPAN",{});var Lp=i(Hs);ci=o(Lp,"Multinomial sampling"),Lp.forEach(s),xo.forEach(s),Ka=c(e),xt=r(e,"P",{});var Pp=i(xt);ui=o(Pp,`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.`),Pp.forEach(s),Ja=c(e),O=r(e,"P",{});var Gt=i(O);di=o(Gt,"To enable multinomial sampling set "),Bs=r(Gt,"CODE",{});var Fp=i(Bs);mi=o(Fp,"do_sample=True"),Fp.forEach(s),gi=o(Gt," and "),Ws=r(Gt,"CODE",{});var Dp=i(Ws);fi=o(Dp,"num_beams=1"),Dp.forEach(s),_i=o(Gt,"."),Gt.forEach(s),Qa=c(e),m(Je.$$.fragment,e),Va=c(e),V=r(e,"H3",{class:!0});var Co=i(V);_e=r(Co,"A",{id:!0,class:!0,href:!0});var Ip=i(_e);Ys=r(Ip,"SPAN",{});var Op=i(Ys);m(Qe.$$.fragment,Op),Op.forEach(s),Ip.forEach(s),vi=c(Co),Us=r(Co,"SPAN",{});var Gp=i(Us);ki=o(Gp,"Beam-search decoding"),Gp.forEach(s),Co.forEach(s),Za=c(e),Ct=r(e,"P",{});var Np=i(Ct);yi=o(Np,`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.`),Np.forEach(s),eo=c(e),ve=r(e,"P",{});var zo=i(ve);wi=o(zo,"To enable this decoding strategy, specify the "),Xs=r(zo,"CODE",{});var Hp=i(Xs);bi=o(Hp,"num_beams"),Hp.forEach(s),ji=o(zo," (aka number of hypotheses to keep track of) that is greater than 1."),zo.forEach(s),to=c(e),m(Ve.$$.fragment,e),so=c(e),Z=r(e,"H3",{class:!0});var Mo=i(Z);ke=r(Mo,"A",{id:!0,class:!0,href:!0});var Bp=i(ke);Rs=r(Bp,"SPAN",{});var Wp=i(Rs);m(Ze.$$.fragment,Wp),Wp.forEach(s),Bp.forEach(s),$i=c(Mo),Ks=r(Mo,"SPAN",{});var Yp=i(Ks);Ei=o(Yp,"Beam-search multinomial sampling"),Yp.forEach(s),Mo.forEach(s),ao=c(e),G=r(e,"P",{});var Nt=i(G);Ai=o(Nt,`As the name implies, this decoding strategy combines beam search with multinomial sampling. You need to specify
the `),Js=r(Nt,"CODE",{});var Up=i(Js);Ti=o(Up,"num_beams"),Up.forEach(s),qi=o(Nt," greater than 1, and set "),Qs=r(Nt,"CODE",{});var Xp=i(Qs);xi=o(Xp,"do_sample=True"),Xp.forEach(s),Ci=o(Nt," to use this decoding strategy."),Nt.forEach(s),oo=c(e),m(et.$$.fragment,e),no=c(e),ee=r(e,"H3",{class:!0});var So=i(ee);ye=r(So,"A",{id:!0,class:!0,href:!0});var Rp=i(ye);Vs=r(Rp,"SPAN",{});var Kp=i(Vs);m(tt.$$.fragment,Kp),Kp.forEach(s),Rp.forEach(s),zi=c(So),Zs=r(So,"SPAN",{});var Jp=i(Zs);Mi=o(Jp,"Diverse beam search decoding"),Jp.forEach(s),So.forEach(s),ro=c(e),z=r(e,"P",{});var qe=i(z);Si=o(qe,`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 `),st=r(qe,"A",{href:!0,rel:!0});var Qp=i(st);Li=o(Qp,"Diverse Beam Search: Decoding Diverse Solutions from Neural Sequence Models"),Qp.forEach(s),Pi=o(qe,`.
This approach has two main parameters: `),ea=r(qe,"CODE",{});var Vp=i(ea);Fi=o(Vp,"num_beams"),Vp.forEach(s),Di=o(qe," and "),ta=r(qe,"CODE",{});var Zp=i(ta);Ii=o(Zp,"num_beam_groups"),Zp.forEach(s),Oi=o(qe,`.
The groups are selected to ensure they are distinct enough compared to the others, and regular beam search is used within each group.`),qe.forEach(s),io=c(e),m(at.$$.fragment,e),lo=c(e),M=r(e,"P",{});var xe=i(M);Gi=o(xe,`This guide illustrates the main parameters that enable various decoding strategies. More advanced parameters exist for the
`),sa=r(xe,"CODE",{});var eh=i(sa);Ni=o(eh,"generate"),eh.forEach(s),Hi=o(xe," method, which gives you even further control over the "),aa=r(xe,"CODE",{});var th=i(aa);Bi=o(th,"generate"),th.forEach(s),Wi=o(xe,` method\u2019s behavior.
For the complete list of the available parameters, refer to the `),zt=r(xe,"A",{href:!0});var sh=i(zt);Yi=o(sh,"API documentation"),sh.forEach(s),Ui=o(xe,"."),xe.forEach(s),po=c(e),te=r(e,"H3",{class:!0});var Lo=i(te);we=r(Lo,"A",{id:!0,class:!0,href:!0});var ah=i(we);oa=r(ah,"SPAN",{});var oh=i(oa);m(ot.$$.fragment,oh),oh.forEach(s),ah.forEach(s),Xi=c(Lo),na=r(Lo,"SPAN",{});var nh=i(na);Ri=o(nh,"Assisted Decoding"),nh.forEach(s),Lo.forEach(s),ho=c(e),Mt=r(e,"P",{});var rh=i(Mt);Ki=o(rh,`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.`),rh.forEach(s),co=c(e),be=r(e,"P",{});var Po=i(be);Ji=o(Po,"To enable assisted decoding, set the "),ra=r(Po,"CODE",{});var ih=i(ra);Qi=o(ih,"assistant_model"),ih.forEach(s),Vi=o(Po," argument with a model."),Po.forEach(s),uo=c(e),m(nt.$$.fragment,e),mo=c(e),je=r(e,"P",{});var Fo=i(je);Zi=o(Fo,"When using assisted decoding with sampling methods, you can use the "),ia=r(Fo,"CODE",{});var lh=i(ia);el=o(lh,"temperarure"),lh.forEach(s),tl=o(Fo,` argument to control the randomness
just like in multinomial sampling. However, in assisted decoding, reducing the temperature will help improving latency.`),Fo.forEach(s),go=c(e),m(rt.$$.fragment,e),this.h()},h(){u(y,"name","hf:doc:metadata"),u(y,"content",JSON.stringify(_h)),u($,"id","text-generation-strategies"),u($,"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"),u($,"href","#text-generation-strategies"),u(b,"class","relative group"),u(ht,"href","/docs/transformers/v4.29.0/en/main_classes/text_generation#transformers.GenerationMixin.generate"),u(ct,"href","./tasks/summarization#inference"),u(ut,"href","./model_doc/git#transformers.GitForCausalLM.forward.example"),u(dt,"href","./model_doc/whisper#transformers.WhisperForConditionalGeneration.forward.example"),u(ne,"id","default-text-generation-configuration"),u(ne,"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"),u(ne,"href","#default-text-generation-configuration"),u(H,"class","relative group"),u(ft,"href","/docs/transformers/v4.29.0/en/main_classes/pipelines#transformers.pipeline"),u(le,"id","customize-text-generation"),u(le,"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"),u(le,"href","#customize-text-generation"),u(B,"class","relative group"),u(he,"id","save-a-custom-decoding-strategy-with-your-model"),u(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"),u(he,"href","#save-a-custom-decoding-strategy-with-your-model"),u(W,"class","relative group"),u(jt,"href","/docs/transformers/v4.29.0/en/main_classes/text_generation#transformers.GenerationConfig"),u($t,"href","/docs/transformers/v4.29.0/en/main_classes/text_generation#transformers.GenerationConfig.save_pretrained"),u(Et,"href","/docs/transformers/v4.29.0/en/main_classes/text_generation#transformers.GenerationConfig.save_pretrained"),u(At,"href","/docs/transformers/v4.29.0/en/main_classes/text_generation#transformers.GenerationConfig.from_pretrained"),u(ce,"id","streaming"),u(ce,"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"),u(ce,"href","#streaming"),u(X,"class","relative group"),u(Tt,"href","/docs/transformers/v4.29.0/en/internal/generation_utils#transformers.TextStreamer"),u(de,"id","decoding-strategies"),u(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"),u(de,"href","#decoding-strategies"),u(R,"class","relative group"),u(He,"href","https://huggingface.co/blog/how-to-generate"),u(He,"rel","nofollow"),u(me,"id","greedy-search"),u(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"),u(me,"href","#greedy-search"),u(K,"class","relative group"),u(ge,"id","contrastive-search"),u(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"),u(ge,"href","#contrastive-search"),u(J,"class","relative group"),u(Ue,"href","https://arxiv.org/abs/2202.06417"),u(Ue,"rel","nofollow"),u(Xe,"href","https://huggingface.co/blog/introducing-csearch"),u(Xe,"rel","nofollow"),u(fe,"id","multinomial-sampling"),u(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"),u(fe,"href","#multinomial-sampling"),u(Q,"class","relative group"),u(_e,"id","beamsearch-decoding"),u(_e,"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"),u(_e,"href","#beamsearch-decoding"),u(V,"class","relative group"),u(ke,"id","beamsearch-multinomial-sampling"),u(ke,"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"),u(ke,"href","#beamsearch-multinomial-sampling"),u(Z,"class","relative group"),u(ye,"id","diverse-beam-search-decoding"),u(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"),u(ye,"href","#diverse-beam-search-decoding"),u(ee,"class","relative group"),u(st,"href","https://arxiv.org/pdf/1610.02424.pdf"),u(st,"rel","nofollow"),u(zt,"href","./main_classes/text_generation.mdx"),u(we,"id","assisted-decoding"),u(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"),u(we,"href","#assisted-decoding"),u(te,"class","relative group")},m(e,l){t(document.head,y),p(e,se,l),p(e,b,l),t(b,$),t($,Ht),g(Ce,Ht,null),t(b,Do),t(b,Bt),t(Bt,Io),p(e,ha,l),p(e,pt,l),t(pt,Oo),p(e,ca,l),p(e,ae,l),t(ae,Go),t(ae,ht),t(ht,No),t(ae,Ho),p(e,ua,l),p(e,L,l),t(L,Wt),t(Wt,ct),t(ct,Bo),t(L,Wo),t(L,Yt),t(Yt,ut),t(ut,Yo),t(L,Uo),t(L,Ut),t(Ut,dt),t(dt,Xo),p(e,da,l),p(e,mt,l),t(mt,Ro),p(e,ma,l),p(e,oe,l),t(oe,Ko),t(oe,Xt),t(Xt,Jo),t(oe,Qo),p(e,ga,l),p(e,gt,l),t(gt,Vo),p(e,fa,l),p(e,P,l),t(P,Rt),t(Rt,Zo),t(P,en),t(P,Kt),t(Kt,tn),t(P,sn),t(P,Jt),t(Jt,an),p(e,_a,l),p(e,H,l),t(H,ne),t(ne,Qt),g(ze,Qt,null),t(H,on),t(H,Vt),t(Vt,nn),p(e,va,l),p(e,F,l),t(F,rn),t(F,ft),t(ft,ln),t(F,pn),t(F,Zt),t(Zt,hn),t(F,cn),p(e,ka,l),p(e,re,l),t(re,un),t(re,es),t(es,dn),t(re,mn),p(e,ya,l),g(Me,e,l),p(e,wa,l),p(e,ie,l),t(ie,gn),t(ie,ts),t(ts,fn),t(ie,_n),p(e,ba,l),p(e,_t,l),t(_t,vn),p(e,ja,l),p(e,B,l),t(B,le),t(le,ss),g(Se,ss,null),t(B,kn),t(B,as),t(as,yn),p(e,$a,l),p(e,D,l),t(D,wn),t(D,os),t(os,bn),t(D,jn),t(D,ns),t(ns,$n),t(D,En),p(e,Ea,l),g(Le,e,l),p(e,Aa,l),p(e,vt,l),t(vt,An),p(e,Ta,l),p(e,T,l),t(T,kt),t(kt,rs),t(rs,Tn),t(kt,qn),t(T,xn),t(T,yt),t(yt,is),t(is,Cn),t(yt,zn),t(T,Mn),t(T,pe),t(pe,ls),t(ls,Sn),t(pe,Ln),t(pe,ps),t(ps,Pn),t(pe,Fn),t(T,Dn),t(T,wt),t(wt,hs),t(hs,In),t(wt,On),p(e,qa,l),p(e,W,l),t(W,he),t(he,cs),g(Pe,cs,null),t(W,Gn),t(W,us),t(us,Nn),p(e,xa,l),p(e,bt,l),t(bt,Hn),p(e,Ca,l),p(e,q,l),t(q,Fe),t(Fe,Bn),t(Fe,jt),t(jt,Wn),t(Fe,Yn),t(q,Un),t(q,ds),t(ds,Xn),t(q,Rn),t(q,Y),t(Y,Kn),t(Y,$t),t($t,Jn),t(Y,Qn),t(Y,ms),t(ms,Vn),t(Y,Zn),t(q,er),t(q,U),t(U,tr),t(U,gs),t(gs,sr),t(U,ar),t(U,fs),t(fs,or),t(U,nr),p(e,za,l),g(De,e,l),p(e,Ma,l),p(e,x,l),t(x,rr),t(x,_s),t(_s,ir),t(x,lr),t(x,Et),t(Et,pr),t(x,hr),t(x,At),t(At,cr),t(x,ur),p(e,Sa,l),g(Ie,e,l),p(e,La,l),p(e,X,l),t(X,ce),t(ce,vs),g(Oe,vs,null),t(X,dr),t(X,ks),t(ks,mr),p(e,Pa,l),p(e,k,l),t(k,gr),t(k,ys),t(ys,fr),t(k,_r),t(k,ws),t(ws,vr),t(k,kr),t(k,bs),t(bs,yr),t(k,wr),t(k,js),t(js,br),t(k,jr),t(k,$s),t($s,$r),t(k,Er),t(k,Es),t(Es,Ar),t(k,Tr),t(k,As),t(As,qr),t(k,xr),p(e,Fa,l),g(ue,e,l),p(e,Da,l),p(e,I,l),t(I,Cr),t(I,Tt),t(Tt,zr),t(I,Mr),t(I,Ts),t(Ts,Sr),t(I,Lr),p(e,Ia,l),g(Ge,e,l),p(e,Oa,l),p(e,R,l),t(R,de),t(de,qs),g(Ne,qs,null),t(R,Pr),t(R,xs),t(xs,Fr),p(e,Ga,l),p(e,C,l),t(C,Dr),t(C,Cs),t(Cs,Ir),t(C,Or),t(C,zs),t(zs,Gr),t(C,Nr),t(C,He),t(He,Hr),t(C,Br),p(e,Na,l),p(e,qt,l),t(qt,Wr),p(e,Ha,l),p(e,K,l),t(K,me),t(me,Ms),g(Be,Ms,null),t(K,Yr),t(K,Ss),t(Ss,Ur),p(e,Ba,l),p(e,S,l),t(S,Ls),t(Ls,Xr),t(S,Rr),t(S,Ps),t(Ps,Kr),t(S,Jr),t(S,Fs),t(Fs,Qr),t(S,Vr),p(e,Wa,l),g(We,e,l),p(e,Ya,l),p(e,J,l),t(J,ge),t(ge,Ds),g(Ye,Ds,null),t(J,Zr),t(J,Is),t(Is,ei),p(e,Ua,l),p(e,j,l),t(j,ti),t(j,Ue),t(Ue,si),t(j,ai),t(j,Xe),t(Xe,oi),t(j,ni),t(j,Os),t(Os,ri),t(j,ii),t(j,Gs),t(Gs,li),t(j,pi),p(e,Xa,l),g(Re,e,l),p(e,Ra,l),p(e,Q,l),t(Q,fe),t(fe,Ns),g(Ke,Ns,null),t(Q,hi),t(Q,Hs),t(Hs,ci),p(e,Ka,l),p(e,xt,l),t(xt,ui),p(e,Ja,l),p(e,O,l),t(O,di),t(O,Bs),t(Bs,mi),t(O,gi),t(O,Ws),t(Ws,fi),t(O,_i),p(e,Qa,l),g(Je,e,l),p(e,Va,l),p(e,V,l),t(V,_e),t(_e,Ys),g(Qe,Ys,null),t(V,vi),t(V,Us),t(Us,ki),p(e,Za,l),p(e,Ct,l),t(Ct,yi),p(e,eo,l),p(e,ve,l),t(ve,wi),t(ve,Xs),t(Xs,bi),t(ve,ji),p(e,to,l),g(Ve,e,l),p(e,so,l),p(e,Z,l),t(Z,ke),t(ke,Rs),g(Ze,Rs,null),t(Z,$i),t(Z,Ks),t(Ks,Ei),p(e,ao,l),p(e,G,l),t(G,Ai),t(G,Js),t(Js,Ti),t(G,qi),t(G,Qs),t(Qs,xi),t(G,Ci),p(e,oo,l),g(et,e,l),p(e,no,l),p(e,ee,l),t(ee,ye),t(ye,Vs),g(tt,Vs,null),t(ee,zi),t(ee,Zs),t(Zs,Mi),p(e,ro,l),p(e,z,l),t(z,Si),t(z,st),t(st,Li),t(z,Pi),t(z,ea),t(ea,Fi),t(z,Di),t(z,ta),t(ta,Ii),t(z,Oi),p(e,io,l),g(at,e,l),p(e,lo,l),p(e,M,l),t(M,Gi),t(M,sa),t(sa,Ni),t(M,Hi),t(M,aa),t(aa,Bi),t(M,Wi),t(M,zt),t(zt,Yi),t(M,Ui),p(e,po,l),p(e,te,l),t(te,we),t(we,oa),g(ot,oa,null),t(te,Xi),t(te,na),t(na,Ri),p(e,ho,l),p(e,Mt,l),t(Mt,Ki),p(e,co,l),p(e,be,l),t(be,Ji),t(be,ra),t(ra,Qi),t(be,Vi),p(e,uo,l),g(nt,e,l),p(e,mo,l),p(e,je,l),t(je,Zi),t(je,ia),t(ia,el),t(je,tl),p(e,go,l),g(rt,e,l),fo=!0},p(e,[l]){const it={};l&2&&(it.$$scope={dirty:l,ctx:e}),ue.$set(it)},i(e){fo||(f(Ce.$$.fragment,e),f(ze.$$.fragment,e),f(Me.$$.fragment,e),f(Se.$$.fragment,e),f(Le.$$.fragment,e),f(Pe.$$.fragment,e),f(De.$$.fragment,e),f(Ie.$$.fragment,e),f(Oe.$$.fragment,e),f(ue.$$.fragment,e),f(Ge.$$.fragment,e),f(Ne.$$.fragment,e),f(Be.$$.fragment,e),f(We.$$.fragment,e),f(Ye.$$.fragment,e),f(Re.$$.fragment,e),f(Ke.$$.fragment,e),f(Je.$$.fragment,e),f(Qe.$$.fragment,e),f(Ve.$$.fragment,e),f(Ze.$$.fragment,e),f(et.$$.fragment,e),f(tt.$$.fragment,e),f(at.$$.fragment,e),f(ot.$$.fragment,e),f(nt.$$.fragment,e),f(rt.$$.fragment,e),fo=!0)},o(e){_(Ce.$$.fragment,e),_(ze.$$.fragment,e),_(Me.$$.fragment,e),_(Se.$$.fragment,e),_(Le.$$.fragment,e),_(Pe.$$.fragment,e),_(De.$$.fragment,e),_(Ie.$$.fragment,e),_(Oe.$$.fragment,e),_(ue.$$.fragment,e),_(Ge.$$.fragment,e),_(Ne.$$.fragment,e),_(Be.$$.fragment,e),_(We.$$.fragment,e),_(Ye.$$.fragment,e),_(Re.$$.fragment,e),_(Ke.$$.fragment,e),_(Je.$$.fragment,e),_(Qe.$$.fragment,e),_(Ve.$$.fragment,e),_(Ze.$$.fragment,e),_(et.$$.fragment,e),_(tt.$$.fragment,e),_(at.$$.fragment,e),_(ot.$$.fragment,e),_(nt.$$.fragment,e),_(rt.$$.fragment,e),fo=!1},d(e){s(y),e&&s(se),e&&s(b),v(Ce),e&&s(ha),e&&s(pt),e&&s(ca),e&&s(ae),e&&s(ua),e&&s(L),e&&s(da),e&&s(mt),e&&s(ma),e&&s(oe),e&&s(ga),e&&s(gt),e&&s(fa),e&&s(P),e&&s(_a),e&&s(H),v(ze),e&&s(va),e&&s(F),e&&s(ka),e&&s(re),e&&s(ya),v(Me,e),e&&s(wa),e&&s(ie),e&&s(ba),e&&s(_t),e&&s(ja),e&&s(B),v(Se),e&&s($a),e&&s(D),e&&s(Ea),v(Le,e),e&&s(Aa),e&&s(vt),e&&s(Ta),e&&s(T),e&&s(qa),e&&s(W),v(Pe),e&&s(xa),e&&s(bt),e&&s(Ca),e&&s(q),e&&s(za),v(De,e),e&&s(Ma),e&&s(x),e&&s(Sa),v(Ie,e),e&&s(La),e&&s(X),v(Oe),e&&s(Pa),e&&s(k),e&&s(Fa),v(ue,e),e&&s(Da),e&&s(I),e&&s(Ia),v(Ge,e),e&&s(Oa),e&&s(R),v(Ne),e&&s(Ga),e&&s(C),e&&s(Na),e&&s(qt),e&&s(Ha),e&&s(K),v(Be),e&&s(Ba),e&&s(S),e&&s(Wa),v(We,e),e&&s(Ya),e&&s(J),v(Ye),e&&s(Ua),e&&s(j),e&&s(Xa),v(Re,e),e&&s(Ra),e&&s(Q),v(Ke),e&&s(Ka),e&&s(xt),e&&s(Ja),e&&s(O),e&&s(Qa),v(Je,e),e&&s(Va),e&&s(V),v(Qe),e&&s(Za),e&&s(Ct),e&&s(eo),e&&s(ve),e&&s(to),v(Ve,e),e&&s(so),e&&s(Z),v(Ze),e&&s(ao),e&&s(G),e&&s(oo),v(et,e),e&&s(no),e&&s(ee),v(tt),e&&s(ro),e&&s(z),e&&s(io),v(at,e),e&&s(lo),e&&s(M),e&&s(po),e&&s(te),v(ot),e&&s(ho),e&&s(Mt),e&&s(co),e&&s(be),e&&s(uo),v(nt,e),e&&s(mo),e&&s(je),e&&s(go),v(rt,e)}}}const _h={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 vh(pa){return dh(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class jh extends ph{constructor(y){super();hh(this,y,vh,fh,ch,{})}}export{jh as default,_h as metadata};
