import{s as ms,o as gs,n as ds}from"../chunks/scheduler.25b97de1.js";import{S as us,i as hs,g as o,s as a,r as d,m as is,A as fs,h as r,f as n,c as l,j as I,u as m,x as p,n as ps,k as Z,l as bs,y as i,a as s,v as g,d as u,t as h,w as f}from"../chunks/index.d9030fc9.js";import{D as Ie}from"../chunks/Docstring.ffac8efa.js";import{C}from"../chunks/CodeBlock.e6cd0d95.js";import{E as cs}from"../chunks/ExampleCodeBlock.22dfe688.js";import{H as x,E as ks}from"../chunks/EditOnGithub.91d95064.js";function _s(Ze){let b,z="Examples:",w,_,M;return _=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwc3JjX2xhbmclM0QlMjJlbmdfTGF0biUyMiUyQyUyMHRndF9sYW5nJTNEJTIyZnJhX0xhdG4lMjIlMEEpJTBBZXhhbXBsZV9lbmdsaXNoX3BocmFzZSUyMCUzRCUyMCUyMiUyMFVOJTIwQ2hpZWYlMjBTYXlzJTIwVGhlcmUlMjBJcyUyME5vJTIwTWlsaXRhcnklMjBTb2x1dGlvbiUyMGluJTIwU3lyaWElMjIlMEFleHBlY3RlZF90cmFuc2xhdGlvbl9mcmVuY2glMjAlM0QlMjAlMjJMZSUyMGNoZWYlMjBkZSUyMGwnT05VJTIwYWZmaXJtZSUyMHF1J2lsJTIwbid5JTIwYSUyMHBhcyUyMGRlJTIwc29sdXRpb24lMjBtaWxpdGFpcmUlMjBlbiUyMFN5cmllLiUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihleGFtcGxlX2VuZ2xpc2hfcGhyYXNlJTJDJTIwdGV4dF90YXJnZXQlM0RleHBlY3RlZF90cmFuc2xhdGlvbl9mcmVuY2glMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, src_lang=<span class="hljs-string">&quot;eng_Latn&quot;</span>, tgt_lang=<span class="hljs-string">&quot;fra_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>example_english_phrase = <span class="hljs-string">&quot; UN Chief Says There Is No Military Solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>expected_translation_french = <span class="hljs-string">&quot;Le chef de l&#x27;ONU affirme qu&#x27;il n&#x27;y a pas de solution militaire en Syrie.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(example_english_phrase, text_target=expected_translation_french, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`,wrap:!1}}),{c(){b=o("p"),b.textContent=z,w=a(),d(_.$$.fragment)},l(c){b=r(c,"P",{"data-svelte-h":!0}),p(b)!=="svelte-kvfsh7"&&(b.textContent=z),w=l(c),m(_.$$.fragment,c)},m(c,v){s(c,b,v),s(c,w,v),g(_,c,v),M=!0},p:ds,i(c){M||(u(_.$$.fragment,c),M=!0)},o(c){h(_.$$.fragment,c),M=!1},d(c){c&&(n(b),n(w)),f(_,c)}}}function ys(Ze){let b,z="Examples:",w,_,M;return _=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXJGYXN0JTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwTmxsYlRva2VuaXplckZhc3QuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmZhY2Vib29rJTJGbmxsYi0yMDAtZGlzdGlsbGVkLTYwME0lMjIlMkMlMjBzcmNfbGFuZyUzRCUyMmVuZ19MYXRuJTIyJTJDJTIwdGd0X2xhbmclM0QlMjJmcmFfTGF0biUyMiUwQSklMEFleGFtcGxlX2VuZ2xpc2hfcGhyYXNlJTIwJTNEJTIwJTIyJTIwVU4lMjBDaGllZiUyMFNheXMlMjBUaGVyZSUyMElzJTIwTm8lMjBNaWxpdGFyeSUyMFNvbHV0aW9uJTIwaW4lMjBTeXJpYSUyMiUwQWV4cGVjdGVkX3RyYW5zbGF0aW9uX2ZyZW5jaCUyMCUzRCUyMCUyMkxlJTIwY2hlZiUyMGRlJTIwbCdPTlUlMjBhZmZpcm1lJTIwcXUnaWwlMjBuJ3klMjBhJTIwcGFzJTIwZGUlMjBzb2x1dGlvbiUyMG1pbGl0YWlyZSUyMGVuJTIwU3lyaWUuJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGV4YW1wbGVfZW5nbGlzaF9waHJhc2UlMkMlMjB0ZXh0X3RhcmdldCUzRGV4cGVjdGVkX3RyYW5zbGF0aW9uX2ZyZW5jaCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizerFast

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizerFast.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, src_lang=<span class="hljs-string">&quot;eng_Latn&quot;</span>, tgt_lang=<span class="hljs-string">&quot;fra_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>example_english_phrase = <span class="hljs-string">&quot; UN Chief Says There Is No Military Solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>expected_translation_french = <span class="hljs-string">&quot;Le chef de l&#x27;ONU affirme qu&#x27;il n&#x27;y a pas de solution militaire en Syrie.&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(example_english_phrase, text_target=expected_translation_french, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`,wrap:!1}}),{c(){b=o("p"),b.textContent=z,w=a(),d(_.$$.fragment)},l(c){b=r(c,"P",{"data-svelte-h":!0}),p(b)!=="svelte-kvfsh7"&&(b.textContent=z),w=l(c),m(_.$$.fragment,c)},m(c,v){s(c,b,v),s(c,w,v),g(_,c,v),M=!0},p:ds,i(c){M||(u(_.$$.fragment,c),M=!0)},o(c){h(_.$$.fragment,c),M=!1},d(c){c&&(n(b),n(w)),f(_,c)}}}function Ms(Ze){let b,z,w,_,M,c,v,st,F,Mn=`<strong>DISCLAIMER:</strong> The default behaviour for the tokenizer was fixed and thus changed in April 2023.
The previous version adds <code>[self.eos_token_id, self.cur_lang_code]</code> at the end of the token sequence for both target and source tokenization. This is wrong as the NLLB paper mentions (page 48, 6.1.1. Model Architecture) :`,at,B,Tn=`<em>Note that we prefix the source sequence with the source language, as opposed to the target
language as previously done in several works (Arivazhagan et al., 2019; Johnson et al.,
2017). This is primarily because we prioritize optimizing zero-shot performance of our
model on any pair of 200 languages at a minor cost to supervised performance.</em>`,lt,X,wn="Previous behaviour:",ot,H,rt,E,vn="New behaviour",it,S,pt,Y,jn="Enabling the old behaviour can be done as follows:",ct,A,dt,D,Jn='For more details, feel free to check the linked <a href="https://github.com/huggingface/transformers/pull/22313" rel="nofollow">PR</a> and <a href="https://github.com/huggingface/transformers/issues/19943" rel="nofollow">Issue</a>.',mt,P,gt,Q,$n=`The NLLB model was presented in <a href="https://arxiv.org/abs/2207.04672" rel="nofollow">No Language Left Behind: Scaling Human-Centered Machine Translation</a> by Marta R. Costa-jussà, James Cross, Onur Çelebi,
Maha Elbayad, Kenneth Heafield, Kevin Heffernan, Elahe Kalbassi, Janice Lam, Daniel Licht, Jean Maillard, Anna Sun, Skyler Wang, Guillaume Wenzek, Al Youngblood, Bapi Akula,
Loic Barrault, Gabriel Mejia Gonzalez, Prangthip Hansanti, John Hoffman, Semarley Jarrett, Kaushik Ram Sadagopan, Dirk Rowe, Shannon Spruit, Chau Tran, Pierre Andrews,
Necip Fazil Ayan, Shruti Bhosale, Sergey Edunov, Angela Fan, Cynthia Gao, Vedanuj Goswami, Francisco Guzmán, Philipp Koehn, Alexandre Mourachko, Christophe Ropers,
Safiyyah Saleem, Holger Schwenk, and Jeff Wang.`,ut,K,xn="The abstract of the paper is the following:",ht,O,Un=`<em>Driven by the goal of eradicating language barriers on a global scale, machine translation has solidified itself as a key focus of artificial intelligence research today.
However, such efforts have coalesced around a small subset of languages, leaving behind the vast majority of mostly low-resource languages. What does it take to break the
200 language barrier while ensuring safe, high quality results, all while keeping ethical considerations in mind? In No Language Left Behind, we took on this challenge by
first contextualizing the need for low-resource language translation support through exploratory interviews with native speakers. Then, we created datasets and models aimed
at narrowing the performance gap between low and high-resource languages. More specifically, we developed a conditional compute model based on Sparsely Gated Mixture of
Experts that is trained on data obtained with novel and effective data mining techniques tailored for low-resource languages. We propose multiple architectural and training
improvements to counteract overfitting while training on thousands of tasks. Critically, we evaluated the performance of over 40,000 different translation directions using
a human-translated benchmark, Flores-200, and combined human evaluation with a novel toxicity benchmark covering all languages in Flores-200 to assess translation safety.
Our model achieves an improvement of 44% BLEU relative to the previous state-of-the-art, laying important groundwork towards realizing a universal translation system.</em>`,ft,ee,zn="This implementation contains the dense models available on release.",bt,te,Nn='<strong>The sparse model NLLB-MoE (Mixture of Expert) is now available! More details <a href="nllb-moe">here</a></strong>',kt,ne,qn='This model was contributed by <a href="https://huggingface.co/lysandre" rel="nofollow">Lysandre</a>. The authors’ code can be found <a href="https://github.com/facebookresearch/fairseq/tree/nllb" rel="nofollow">here</a>.',_t,se,yt,ae,Gn=`While generating the target text set the <code>forced_bos_token_id</code> to the target language id. The following
example shows how to translate English to French using the <em>facebook/nllb-200-distilled-600M</em> model.`,Mt,le,In=`Note that we’re using the BCP-47 code for French <code>fra_Latn</code>. See <a href="https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200" rel="nofollow">here</a>
for the list of all BCP-47 in the Flores 200 dataset.`,Tt,oe,wt,re,vt,ie,Zn=`English (<code>eng_Latn</code>) is set as the default language from which to translate. In order to specify that you’d like to translate from a different language,
you should specify the BCP-47 code in the <code>src_lang</code> keyword argument of the tokenizer initialization.`,jt,pe,Cn="See example below for a translation from romanian to german:",Jt,ce,$t,de,xt,me,Ln='<li><a href="../tasks/translation">Translation task guide</a></li> <li><a href="../tasks/summarization">Summarization task guide</a></li>',Ut,ge,zt,T,ue,Dt,Ce,Rn="Construct an NLLB tokenizer.",Pt,Le,Wn=`Adapted from <a href="/docs/transformers/main/en/model_doc/roberta#transformers.RobertaTokenizer">RobertaTokenizer</a> and <a href="/docs/transformers/main/en/model_doc/xlnet#transformers.XLNetTokenizer">XLNetTokenizer</a>. Based on
<a href="https://github.com/google/sentencepiece" rel="nofollow">SentencePiece</a>.`,Qt,Re,Vn="The tokenization method is <code>&lt;tokens&gt; &lt;eos&gt; &lt;language code&gt;</code> for source language documents, and `&lt;language code&gt;",Kt,L,Ot,$,he,en,We,Fn=`Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An NLLB sequence has the following format, where <code>X</code> represents the sequence:`,tn,Ve,Bn="<li><code>input_ids</code> (for encoder) <code>X [eos, src_lang_code]</code></li> <li><code>decoder_input_ids</code>: (for decoder) <code>X [eos, tgt_lang_code]</code></li>",nn,Fe,Xn=`BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
separator.`,Nt,fe,qt,k,be,sn,Be,Hn=`Construct a “fast” NLLB tokenizer (backed by HuggingFace’s <em>tokenizers</em> library). Based on
<a href="https://huggingface.co/docs/tokenizers/python/latest/components.html?highlight=BPE#models" rel="nofollow">BPE</a>.`,an,Xe,En=`This tokenizer inherits from <a href="/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizerFast">PreTrainedTokenizerFast</a> which contains most of the main methods. Users should
refer to this superclass for more information regarding those methods.`,ln,He,Sn="The tokenization method is <code>&lt;tokens&gt; &lt;eos&gt; &lt;language code&gt;</code> for source language documents, and `&lt;language code&gt;",on,R,rn,J,ke,pn,Ee,Yn=`Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. The special tokens depend on calling set_lang.`,cn,Se,An="An NLLB sequence has the following format, where <code>X</code> represents the sequence:",dn,Ye,Dn="<li><code>input_ids</code> (for encoder) <code>X [eos, src_lang_code]</code></li> <li><code>decoder_input_ids</code>: (for decoder) <code>X [eos, tgt_lang_code]</code></li>",mn,Ae,Pn=`BOS is never used. Pairs of sequences are not the expected use case, but they will be handled without a
separator.`,gn,W,_e,un,De,Qn=`Create a mask from the two sequences passed to be used in a sequence-pair classification task. nllb does not
make use of token type ids, therefore a list of zeros is returned.`,hn,N,ye,fn,Pe,Kn="Reset the special tokens to the source lang setting.",bn,Qe,On="<li>In legacy mode: No prefix and suffix=[eos, src_lang_code].</li> <li>In default mode: Prefix=[src_lang_code], suffix = [eos]</li>",kn,q,Me,_n,Ke,es="Reset the special tokens to the target lang setting.",yn,Oe,ts="<li>In legacy mode: No prefix and suffix=[eos, tgt_lang_code].</li> <li>In default mode: Prefix=[tgt_lang_code], suffix = [eos]</li>",Gt,Te,It,we,ns="Flash Attention 2 is a faster, optimized version of the attention scores computation which relies on <code>cuda</code> kernels.",Zt,ve,Ct,je,ss='First, check whether your hardware is compatible with Flash Attention 2. The latest list of compatible hardware can be found in the <a href="https://github.com/Dao-AILab/flash-attention#installation-and-features" rel="nofollow">official documentation</a>.',Lt,Je,as='Next, <a href="https://github.com/Dao-AILab/flash-attention#installation-and-features" rel="nofollow">install</a> the latest version of Flash Attention 2:',Rt,$e,Wt,xe,Vt,Ue,ls='To load a model using Flash Attention 2, we can pass the argument <code>attn_implementation=&quot;flash_attention_2&quot;</code> to <a href="https://huggingface.co/docs/transformers/main/en/main_classes/model#transformers.PreTrainedModel.from_pretrained" rel="nofollow"><code>.from_pretrained</code></a>. You can use either <code>torch.float16</code> or <code>torch.bfloat16</code> precision.',Ft,ze,Bt,Ne,Xt,qe,os="Below is an expected speedup diagram that compares pure inference time between the native implementation and the Flash Attention 2.",Ht,V,rs='<img src="https://huggingface.co/datasets/visheratin/documentation-images/resolve/main/nllb-speedup.webp"/>',Et,Ge,St,nt,Yt;return M=new x({props:{title:"NLLB",local:"nllb",headingTag:"h1"}}),v=new x({props:{title:"Updated tokenizer behavior",local:"transformers.NllbTokenizer",headingTag:"h2"}}),H=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQXRva2VuaXplciglMjJIb3clMjB3YXMlMjB5b3VyJTIwZGF5JTNGJTIyKS5pbnB1dF9pZHMlMEElMEElMjMlMjAyJTNBJTIwJyUzQyUyRnMlM0UnJTBBJTIzJTIwMjU2MDQ3JTIwJTNBJTIwJ2VuZ19MYXRuJw==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer(<span class="hljs-string">&quot;How was your day?&quot;</span>).input_ids
[<span class="hljs-number">13374</span>, <span class="hljs-number">1398</span>, <span class="hljs-number">4260</span>, <span class="hljs-number">4039</span>, <span class="hljs-number">248130</span>, <span class="hljs-number">2</span>, <span class="hljs-number">256047</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 2: &#x27;&lt;/s&gt;&#x27;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># 256047 : &#x27;eng_Latn&#x27;</span>`,wrap:!1}}),S=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQXRva2VuaXplciglMjJIb3clMjB3YXMlMjB5b3VyJTIwZGF5JTNGJTIyKS5pbnB1dF9pZHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer(<span class="hljs-string">&quot;How was your day?&quot;</span>).input_ids
[<span class="hljs-number">256047</span>, <span class="hljs-number">13374</span>, <span class="hljs-number">1398</span>, <span class="hljs-number">4260</span>, <span class="hljs-number">4039</span>, <span class="hljs-number">248130</span>, <span class="hljs-number">2</span>]`,wrap:!1}}),A=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyME5sbGJUb2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBObGxiVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwbGVnYWN5X2JlaGF2aW91ciUzRFRydWUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> NllbTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = NllbTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, legacy_behaviour=<span class="hljs-literal">True</span>)`,wrap:!1}}),P=new x({props:{title:"Overview",local:"overview",headingTag:"h2"}}),se=new x({props:{title:"Generating with NLLB",local:"generating-with-nllb",headingTag:"h2"}}),oe=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQSUwQWFydGljbGUlMjAlM0QlMjAlMjJVTiUyMENoaWVmJTIwc2F5cyUyMHRoZXJlJTIwaXMlMjBubyUyMG1pbGl0YXJ5JTIwc29sdXRpb24lMjBpbiUyMFN5cmlhJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGFydGljbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKSUwQSUwQXRyYW5zbGF0ZWRfdG9rZW5zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dHMlMkMlMjBmb3JjZWRfYm9zX3Rva2VuX2lkJTNEdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyglMjJmcmFfTGF0biUyMiklMkMlMjBtYXhfbGVuZ3RoJTNEMzAlMEEpJTBBdG9rZW5pemVyLmJhdGNoX2RlY29kZSh0cmFuc2xhdGVkX3Rva2VucyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;UN Chief says there is no military solution in Syria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.convert_tokens_to_ids(<span class="hljs-string">&quot;fra_Latn&quot;</span>), max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
Le chef de l<span class="hljs-string">&#x27;ONU dit qu&#x27;</span>il n<span class="hljs-string">&#x27;y a pas de solution militaire en Syrie</span>`,wrap:!1}}),re=new x({props:{title:"Generating from any other language than English",local:"generating-from-any-other-language-than-english",headingTag:"h3"}}),ce=new C({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwdG9rZW4lM0RUcnVlJTJDJTIwc3JjX2xhbmclM0QlMjJyb25fTGF0biUyMiUwQSklMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoJTIyZmFjZWJvb2slMkZubGxiLTIwMC1kaXN0aWxsZWQtNjAwTSUyMiUyQyUyMHRva2VuJTNEVHJ1ZSklMEElMEFhcnRpY2xlJTIwJTNEJTIwJTIyJUM1JTlFZWZ1bCUyME9OVSUyMHNwdW5lJTIwYyVDNCU4MyUyMG51JTIwZXhpc3QlQzQlODMlMjBvJTIwc29sdSVDNSVBM2llJTIwbWlsaXRhciVDNCU4MyUyMCVDMyVBRW4lMjBTaXJpYSUyMiUwQWlucHV0cyUyMCUzRCUyMHRva2VuaXplcihhcnRpY2xlJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJwdCUyMiklMEElMEF0cmFuc2xhdGVkX3Rva2VucyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCUwQSUyMCUyMCUyMCUyMCoqaW5wdXRzJTJDJTIwZm9yY2VkX2Jvc190b2tlbl9pZCUzRHRva2VuaXplci5jb252ZXJ0X3Rva2Vuc190b19pZHMoJTIyZGV1X0xhdG4lMjIpJTJDJTIwbWF4X2xlbmd0aCUzRDMwJTBBKSUwQXRva2VuaXplci5iYXRjaF9kZWNvZGUodHJhbnNsYXRlZF90b2tlbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklNUIwJTVE",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, token=<span class="hljs-literal">True</span>, src_lang=<span class="hljs-string">&quot;ron_Latn&quot;</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, token=<span class="hljs-literal">True</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Şeful ONU spune că nu există o soluţie militară în Siria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.convert_tokens_to_ids(<span class="hljs-string">&quot;deu_Latn&quot;</span>), max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
UN-Chef sagt, es gibt keine militärische Lösung <span class="hljs-keyword">in</span> Syrien`,wrap:!1}}),de=new x({props:{title:"Resources",local:"resources",headingTag:"h2"}}),ge=new x({props:{title:"NllbTokenizer",local:"nllbtokenizer",headingTag:"h2"}}),ue=new Ie({props:{name:"class transformers.NllbTokenizer",anchor:"transformers.NllbTokenizer",parameters:[{name:"vocab_file",val:""},{name:"bos_token",val:" = '<s>'"},{name:"eos_token",val:" = '</s>'"},{name:"sep_token",val:" = '</s>'"},{name:"cls_token",val:" = '<s>'"},{name:"unk_token",val:" = '<unk>'"},{name:"pad_token",val:" = '<pad>'"},{name:"mask_token",val:" = '<mask>'"},{name:"tokenizer_file",val:" = None"},{name:"src_lang",val:" = None"},{name:"tgt_lang",val:" = None"},{name:"sp_model_kwargs",val:": Optional = None"},{name:"additional_special_tokens",val:" = None"},{name:"legacy_behaviour",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.NllbTokenizer.vocab_file",description:`<strong>vocab_file</strong> (<code>str</code>) &#x2014;
Path to the vocabulary file.`,name:"vocab_file"},{anchor:"transformers.NllbTokenizer.bos_token",description:`<strong>bos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the <code>cls_token</code>.</p>

					</div>`,name:"bos_token"},{anchor:"transformers.NllbTokenizer.eos_token",description:`<strong>eos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The end of sequence token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the <code>sep_token</code>.</p>

					</div>`,name:"eos_token"},{anchor:"transformers.NllbTokenizer.sep_token",description:`<strong>sep_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.`,name:"sep_token"},{anchor:"transformers.NllbTokenizer.cls_token",description:`<strong>cls_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.`,name:"cls_token"},{anchor:"transformers.NllbTokenizer.unk_token",description:`<strong>unk_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;unk&gt;&quot;</code>) &#x2014;
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.`,name:"unk_token"},{anchor:"transformers.NllbTokenizer.pad_token",description:`<strong>pad_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;pad&gt;&quot;</code>) &#x2014;
The token used for padding, for example when batching sequences of different lengths.`,name:"pad_token"},{anchor:"transformers.NllbTokenizer.mask_token",description:`<strong>mask_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;mask&gt;&quot;</code>) &#x2014;
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict.`,name:"mask_token"},{anchor:"transformers.NllbTokenizer.tokenizer_file",description:`<strong>tokenizer_file</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The path to a tokenizer file to use instead of the vocab file.`,name:"tokenizer_file"},{anchor:"transformers.NllbTokenizer.src_lang",description:`<strong>src_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as source language for translation.`,name:"src_lang"},{anchor:"transformers.NllbTokenizer.tgt_lang",description:`<strong>tgt_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as target language for translation.`,name:"tgt_lang"},{anchor:"transformers.NllbTokenizer.sp_model_kwargs",description:`<strong>sp_model_kwargs</strong> (<code>Dict[str, str]</code>) &#x2014;
Additional keyword arguments to pass to the model initialization.`,name:"sp_model_kwargs"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb.py#L36"}}),L=new cs({props:{anchor:"transformers.NllbTokenizer.example",$$slots:{default:[_s]},$$scope:{ctx:Ze}}}),he=new Ie({props:{name:"build_inputs_with_special_tokens",anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs to which the special tokens will be added.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizer.build_inputs_with_special_tokens.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb.py#L243",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>List of <a href="../glossary#input-ids">input IDs</a> with the appropriate special tokens.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),fe=new x({props:{title:"NllbTokenizerFast",local:"nllbtokenizerfast",headingTag:"h2"}}),be=new Ie({props:{name:"class transformers.NllbTokenizerFast",anchor:"transformers.NllbTokenizerFast",parameters:[{name:"vocab_file",val:" = None"},{name:"tokenizer_file",val:" = None"},{name:"bos_token",val:" = '<s>'"},{name:"eos_token",val:" = '</s>'"},{name:"sep_token",val:" = '</s>'"},{name:"cls_token",val:" = '<s>'"},{name:"unk_token",val:" = '<unk>'"},{name:"pad_token",val:" = '<pad>'"},{name:"mask_token",val:" = '<mask>'"},{name:"src_lang",val:" = None"},{name:"tgt_lang",val:" = None"},{name:"additional_special_tokens",val:" = None"},{name:"legacy_behaviour",val:" = False"},{name:"**kwargs",val:""}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.vocab_file",description:`<strong>vocab_file</strong> (<code>str</code>) &#x2014;
Path to the vocabulary file.`,name:"vocab_file"},{anchor:"transformers.NllbTokenizerFast.bos_token",description:`<strong>bos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the beginning of
sequence. The token used is the <code>cls_token</code>.</p>

					</div>`,name:"bos_token"},{anchor:"transformers.NllbTokenizerFast.eos_token",description:`<strong>eos_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The end of sequence token.</p>
<div class="course-tip  bg-gradient-to-br dark:bg-gradient-to-r before:border-green-500 dark:before:border-green-800 from-green-50 dark:from-gray-900 to-white dark:to-gray-950 border border-green-50 text-green-700 dark:text-gray-400">
						
<p>When building a sequence using special tokens, this is not the token that is used for the end of sequence.
The token used is the <code>sep_token</code>.</p>

					</div>`,name:"eos_token"},{anchor:"transformers.NllbTokenizerFast.sep_token",description:`<strong>sep_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;/s&gt;&quot;</code>) &#x2014;
The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
sequence classification or for a text and a question for question answering. It is also used as the last
token of a sequence built with special tokens.`,name:"sep_token"},{anchor:"transformers.NllbTokenizerFast.cls_token",description:`<strong>cls_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;s&gt;&quot;</code>) &#x2014;
The classifier token which is used when doing sequence classification (classification of the whole sequence
instead of per-token classification). It is the first token of the sequence when built with special tokens.`,name:"cls_token"},{anchor:"transformers.NllbTokenizerFast.unk_token",description:`<strong>unk_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;unk&gt;&quot;</code>) &#x2014;
The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
token instead.`,name:"unk_token"},{anchor:"transformers.NllbTokenizerFast.pad_token",description:`<strong>pad_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;pad&gt;&quot;</code>) &#x2014;
The token used for padding, for example when batching sequences of different lengths.`,name:"pad_token"},{anchor:"transformers.NllbTokenizerFast.mask_token",description:`<strong>mask_token</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;&lt;mask&gt;&quot;</code>) &#x2014;
The token used for masking values. This is the token used when training this model with masked language
modeling. This is the token which the model will try to predict.`,name:"mask_token"},{anchor:"transformers.NllbTokenizerFast.tokenizer_file",description:`<strong>tokenizer_file</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The path to a tokenizer file to use instead of the vocab file.`,name:"tokenizer_file"},{anchor:"transformers.NllbTokenizerFast.src_lang",description:`<strong>src_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as source language for translation.`,name:"src_lang"},{anchor:"transformers.NllbTokenizerFast.tgt_lang",description:`<strong>tgt_lang</strong> (<code>str</code>, <em>optional</em>) &#x2014;
The language to use as target language for translation.`,name:"tgt_lang"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L42"}}),R=new cs({props:{anchor:"transformers.NllbTokenizerFast.example",$$slots:{default:[ys]},$$scope:{ctx:Ze}}}),ke=new Ie({props:{name:"build_inputs_with_special_tokens",anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs to which the special tokens will be added.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizerFast.build_inputs_with_special_tokens.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L182",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>list of <a href="../glossary#input-ids">input IDs</a> with the appropriate special tokens.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),_e=new Ie({props:{name:"create_token_type_ids_from_sequences",anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences",parameters:[{name:"token_ids_0",val:": List"},{name:"token_ids_1",val:": Optional = None"}],parametersDescription:[{anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences.token_ids_0",description:`<strong>token_ids_0</strong> (<code>List[int]</code>) &#x2014;
List of IDs.`,name:"token_ids_0"},{anchor:"transformers.NllbTokenizerFast.create_token_type_ids_from_sequences.token_ids_1",description:`<strong>token_ids_1</strong> (<code>List[int]</code>, <em>optional</em>) &#x2014;
Optional second list of IDs for sequence pairs.`,name:"token_ids_1"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L211",returnDescription:`<script context="module">export const metadata = 'undefined';<\/script>


<p>List of zeros.</p>
`,returnType:`<script context="module">export const metadata = 'undefined';<\/script>


<p><code>List[int]</code></p>
`}}),ye=new Ie({props:{name:"set_src_lang_special_tokens",anchor:"transformers.NllbTokenizerFast.set_src_lang_special_tokens",parameters:[{name:"src_lang",val:""}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L266"}}),Me=new Ie({props:{name:"set_tgt_lang_special_tokens",anchor:"transformers.NllbTokenizerFast.set_tgt_lang_special_tokens",parameters:[{name:"lang",val:": str"}],source:"https://github.com/huggingface/transformers/blob/main/src/transformers/models/nllb/tokenization_nllb_fast.py#L289"}}),Te=new x({props:{title:"Using Flash Attention 2",local:"using-flash-attention-2",headingTag:"h2"}}),ve=new x({props:{title:"Installation",local:"installation",headingTag:"h3"}}),$e=new C({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwZmxhc2gtYXR0biUyMC0tbm8tYnVpbGQtaXNvbGF0aW9u",highlighted:"pip install -U flash-attn --no-build-isolation",wrap:!1}}),xe=new x({props:{title:"Usage",local:"usage",headingTag:"h3"}}),ze=new C({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwYXR0bl9pbXBsZW1lbnRhdGlvbiUzRCUyMmZsYXNoX2F0dGVudGlvbl8yJTIyKS50byglMjJjdWRhJTIyKS5ldmFsKCklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJmYWNlYm9vayUyRm5sbGItMjAwLWRpc3RpbGxlZC02MDBNJTIyKSUwQSUwQWFydGljbGUlMjAlM0QlMjAlMjIlQzUlOUVlZnVsJTIwT05VJTIwc3B1bmUlMjBjJUM0JTgzJTIwbnUlMjBleGlzdCVDNCU4MyUyMG8lMjBzb2x1JUM1JUEzaWUlMjBtaWxpdGFyJUM0JTgzJTIwJUMzJUFFbiUyMFNpcmlhJTIyJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKGFydGljbGUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byglMjJjdWRhJTIyKSUwQSUwQXRyYW5zbGF0ZWRfdG9rZW5zJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwKippbnB1dHMlMkMlMjBmb3JjZWRfYm9zX3Rva2VuX2lkJTNEdG9rZW5pemVyLmNvbnZlcnRfdG9rZW5zX3RvX2lkcyglMjJkZXVfTGF0biUyMiklMkMlMjBtYXhfbGVuZ3RoJTNEMzAlMEEpJTBBdG9rZW5pemVyLmJhdGNoX2RlY29kZSh0cmFuc2xhdGVkX3Rva2VucyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>, torch_dtype=torch.float16, attn_implementation=<span class="hljs-string">&quot;flash_attention_2&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>).<span class="hljs-built_in">eval</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;facebook/nllb-200-distilled-600M&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>article = <span class="hljs-string">&quot;Şeful ONU spune că nu există o soluţie militară în Siria&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(article, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>translated_tokens = model.generate(
<span class="hljs-meta">... </span>    **inputs, forced_bos_token_id=tokenizer.convert_tokens_to_ids(<span class="hljs-string">&quot;deu_Latn&quot;</span>), max_length=<span class="hljs-number">30</span>
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.batch_decode(translated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>)[<span class="hljs-number">0</span>]
<span class="hljs-string">&quot;UN-Chef sagt, es gibt keine militärische Lösung in Syrien&quot;</span>`,wrap:!1}}),Ne=new x({props:{title:"Expected speedups",local:"expected-speedups",headingTag:"h3"}}),Ge=new ks({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/nllb.md"}}),{c(){b=o("meta"),z=a(),w=o("p"),_=a(),d(M.$$.fragment),c=a(),d(v.$$.fragment),st=a(),F=o("p"),F.innerHTML=Mn,at=a(),B=o("p"),B.innerHTML=Tn,lt=a(),X=o("p"),X.textContent=wn,ot=a(),d(H.$$.fragment),rt=a(),E=o("p"),E.textContent=vn,it=a(),d(S.$$.fragment),pt=a(),Y=o("p"),Y.textContent=jn,ct=a(),d(A.$$.fragment),dt=a(),D=o("p"),D.innerHTML=Jn,mt=a(),d(P.$$.fragment),gt=a(),Q=o("p"),Q.innerHTML=$n,ut=a(),K=o("p"),K.textContent=xn,ht=a(),O=o("p"),O.innerHTML=Un,ft=a(),ee=o("p"),ee.textContent=zn,bt=a(),te=o("p"),te.innerHTML=Nn,kt=a(),ne=o("p"),ne.innerHTML=qn,_t=a(),d(se.$$.fragment),yt=a(),ae=o("p"),ae.innerHTML=Gn,Mt=a(),le=o("p"),le.innerHTML=In,Tt=a(),d(oe.$$.fragment),wt=a(),d(re.$$.fragment),vt=a(),ie=o("p"),ie.innerHTML=Zn,jt=a(),pe=o("p"),pe.textContent=Cn,Jt=a(),d(ce.$$.fragment),$t=a(),d(de.$$.fragment),xt=a(),me=o("ul"),me.innerHTML=Ln,Ut=a(),d(ge.$$.fragment),zt=a(),T=o("div"),d(ue.$$.fragment),Dt=a(),Ce=o("p"),Ce.textContent=Rn,Pt=a(),Le=o("p"),Le.innerHTML=Wn,Qt=a(),Re=o("p"),Re.innerHTML=Vn,Kt=is(`
<tokens> <eos>\` for target language documents.
`),d(L.$$.fragment),Ot=a(),$=o("div"),d(he.$$.fragment),en=a(),We=o("p"),We.innerHTML=Fn,tn=a(),Ve=o("ul"),Ve.innerHTML=Bn,nn=a(),Fe=o("p"),Fe.textContent=Xn,Nt=a(),d(fe.$$.fragment),qt=a(),k=o("div"),d(be.$$.fragment),sn=a(),Be=o("p"),Be.innerHTML=Hn,an=a(),Xe=o("p"),Xe.innerHTML=En,ln=a(),He=o("p"),He.innerHTML=Sn,on=is(`
<tokens> <eos>\` for target language documents.
`),d(R.$$.fragment),rn=a(),J=o("div"),d(ke.$$.fragment),pn=a(),Ee=o("p"),Ee.textContent=Yn,cn=a(),Se=o("p"),Se.innerHTML=An,dn=a(),Ye=o("ul"),Ye.innerHTML=Dn,mn=a(),Ae=o("p"),Ae.textContent=Pn,gn=a(),W=o("div"),d(_e.$$.fragment),un=a(),De=o("p"),De.textContent=Qn,hn=a(),N=o("div"),d(ye.$$.fragment),fn=a(),Pe=o("p"),Pe.textContent=Kn,bn=a(),Qe=o("ul"),Qe.innerHTML=On,kn=a(),q=o("div"),d(Me.$$.fragment),_n=a(),Ke=o("p"),Ke.textContent=es,yn=a(),Oe=o("ul"),Oe.innerHTML=ts,Gt=a(),d(Te.$$.fragment),It=a(),we=o("p"),we.innerHTML=ns,Zt=a(),d(ve.$$.fragment),Ct=a(),je=o("p"),je.innerHTML=ss,Lt=a(),Je=o("p"),Je.innerHTML=as,Rt=a(),d($e.$$.fragment),Wt=a(),d(xe.$$.fragment),Vt=a(),Ue=o("p"),Ue.innerHTML=ls,Ft=a(),d(ze.$$.fragment),Bt=a(),d(Ne.$$.fragment),Xt=a(),qe=o("p"),qe.textContent=os,Ht=a(),V=o("div"),V.innerHTML=rs,Et=a(),d(Ge.$$.fragment),St=a(),nt=o("p"),this.h()},l(e){const t=fs("svelte-u9bgzb",document.head);b=r(t,"META",{name:!0,content:!0}),t.forEach(n),z=l(e),w=r(e,"P",{}),I(w).forEach(n),_=l(e),m(M.$$.fragment,e),c=l(e),m(v.$$.fragment,e),st=l(e),F=r(e,"P",{"data-svelte-h":!0}),p(F)!=="svelte-1bqcebz"&&(F.innerHTML=Mn),at=l(e),B=r(e,"P",{"data-svelte-h":!0}),p(B)!=="svelte-vrv0c7"&&(B.innerHTML=Tn),lt=l(e),X=r(e,"P",{"data-svelte-h":!0}),p(X)!=="svelte-vmuleo"&&(X.textContent=wn),ot=l(e),m(H.$$.fragment,e),rt=l(e),E=r(e,"P",{"data-svelte-h":!0}),p(E)!=="svelte-1qx2sah"&&(E.textContent=vn),it=l(e),m(S.$$.fragment,e),pt=l(e),Y=r(e,"P",{"data-svelte-h":!0}),p(Y)!=="svelte-obd9iw"&&(Y.textContent=jn),ct=l(e),m(A.$$.fragment,e),dt=l(e),D=r(e,"P",{"data-svelte-h":!0}),p(D)!=="svelte-ib1bh"&&(D.innerHTML=Jn),mt=l(e),m(P.$$.fragment,e),gt=l(e),Q=r(e,"P",{"data-svelte-h":!0}),p(Q)!=="svelte-12x4cpm"&&(Q.innerHTML=$n),ut=l(e),K=r(e,"P",{"data-svelte-h":!0}),p(K)!=="svelte-wu27l3"&&(K.textContent=xn),ht=l(e),O=r(e,"P",{"data-svelte-h":!0}),p(O)!=="svelte-1j7uypk"&&(O.innerHTML=Un),ft=l(e),ee=r(e,"P",{"data-svelte-h":!0}),p(ee)!=="svelte-1ayd4bm"&&(ee.textContent=zn),bt=l(e),te=r(e,"P",{"data-svelte-h":!0}),p(te)!=="svelte-qp2ubt"&&(te.innerHTML=Nn),kt=l(e),ne=r(e,"P",{"data-svelte-h":!0}),p(ne)!=="svelte-ywl52z"&&(ne.innerHTML=qn),_t=l(e),m(se.$$.fragment,e),yt=l(e),ae=r(e,"P",{"data-svelte-h":!0}),p(ae)!=="svelte-gz9jek"&&(ae.innerHTML=Gn),Mt=l(e),le=r(e,"P",{"data-svelte-h":!0}),p(le)!=="svelte-c2ujwv"&&(le.innerHTML=In),Tt=l(e),m(oe.$$.fragment,e),wt=l(e),m(re.$$.fragment,e),vt=l(e),ie=r(e,"P",{"data-svelte-h":!0}),p(ie)!=="svelte-ets0jr"&&(ie.innerHTML=Zn),jt=l(e),pe=r(e,"P",{"data-svelte-h":!0}),p(pe)!=="svelte-14hvt1f"&&(pe.textContent=Cn),Jt=l(e),m(ce.$$.fragment,e),$t=l(e),m(de.$$.fragment,e),xt=l(e),me=r(e,"UL",{"data-svelte-h":!0}),p(me)!=="svelte-6ej6p2"&&(me.innerHTML=Ln),Ut=l(e),m(ge.$$.fragment,e),zt=l(e),T=r(e,"DIV",{class:!0});var j=I(T);m(ue.$$.fragment,j),Dt=l(j),Ce=r(j,"P",{"data-svelte-h":!0}),p(Ce)!=="svelte-7mmiyn"&&(Ce.textContent=Rn),Pt=l(j),Le=r(j,"P",{"data-svelte-h":!0}),p(Le)!=="svelte-1serjol"&&(Le.innerHTML=Wn),Qt=l(j),Re=r(j,"P",{"data-svelte-h":!0}),p(Re)!=="svelte-1i8rh37"&&(Re.innerHTML=Vn),Kt=ps(j,`
<tokens> <eos>\` for target language documents.
`),m(L.$$.fragment,j),Ot=l(j),$=r(j,"DIV",{class:!0});var U=I($);m(he.$$.fragment,U),en=l(U),We=r(U,"P",{"data-svelte-h":!0}),p(We)!=="svelte-nkpot4"&&(We.innerHTML=Fn),tn=l(U),Ve=r(U,"UL",{"data-svelte-h":!0}),p(Ve)!=="svelte-mlrsks"&&(Ve.innerHTML=Bn),nn=l(U),Fe=r(U,"P",{"data-svelte-h":!0}),p(Fe)!=="svelte-46aam0"&&(Fe.textContent=Xn),U.forEach(n),j.forEach(n),Nt=l(e),m(fe.$$.fragment,e),qt=l(e),k=r(e,"DIV",{class:!0});var y=I(k);m(be.$$.fragment,y),sn=l(y),Be=r(y,"P",{"data-svelte-h":!0}),p(Be)!=="svelte-g5z8ln"&&(Be.innerHTML=Hn),an=l(y),Xe=r(y,"P",{"data-svelte-h":!0}),p(Xe)!=="svelte-fh0aq"&&(Xe.innerHTML=En),ln=l(y),He=r(y,"P",{"data-svelte-h":!0}),p(He)!=="svelte-1i8rh37"&&(He.innerHTML=Sn),on=ps(y,`
<tokens> <eos>\` for target language documents.
`),m(R.$$.fragment,y),rn=l(y),J=r(y,"DIV",{class:!0});var G=I(J);m(ke.$$.fragment,G),pn=l(G),Ee=r(G,"P",{"data-svelte-h":!0}),p(Ee)!=="svelte-1vll0v2"&&(Ee.textContent=Yn),cn=l(G),Se=r(G,"P",{"data-svelte-h":!0}),p(Se)!=="svelte-90np8u"&&(Se.innerHTML=An),dn=l(G),Ye=r(G,"UL",{"data-svelte-h":!0}),p(Ye)!=="svelte-mlrsks"&&(Ye.innerHTML=Dn),mn=l(G),Ae=r(G,"P",{"data-svelte-h":!0}),p(Ae)!=="svelte-46aam0"&&(Ae.textContent=Pn),G.forEach(n),gn=l(y),W=r(y,"DIV",{class:!0});var At=I(W);m(_e.$$.fragment,At),un=l(At),De=r(At,"P",{"data-svelte-h":!0}),p(De)!=="svelte-1bcwf97"&&(De.textContent=Qn),At.forEach(n),hn=l(y),N=r(y,"DIV",{class:!0});var et=I(N);m(ye.$$.fragment,et),fn=l(et),Pe=r(et,"P",{"data-svelte-h":!0}),p(Pe)!=="svelte-1euodjq"&&(Pe.textContent=Kn),bn=l(et),Qe=r(et,"UL",{"data-svelte-h":!0}),p(Qe)!=="svelte-rrgzfj"&&(Qe.innerHTML=On),et.forEach(n),kn=l(y),q=r(y,"DIV",{class:!0});var tt=I(q);m(Me.$$.fragment,tt),_n=l(tt),Ke=r(tt,"P",{"data-svelte-h":!0}),p(Ke)!=="svelte-1i6tlcm"&&(Ke.textContent=es),yn=l(tt),Oe=r(tt,"UL",{"data-svelte-h":!0}),p(Oe)!=="svelte-1durotj"&&(Oe.innerHTML=ts),tt.forEach(n),y.forEach(n),Gt=l(e),m(Te.$$.fragment,e),It=l(e),we=r(e,"P",{"data-svelte-h":!0}),p(we)!=="svelte-1oyivwb"&&(we.innerHTML=ns),Zt=l(e),m(ve.$$.fragment,e),Ct=l(e),je=r(e,"P",{"data-svelte-h":!0}),p(je)!=="svelte-3ltiwn"&&(je.innerHTML=ss),Lt=l(e),Je=r(e,"P",{"data-svelte-h":!0}),p(Je)!=="svelte-1pp3dkd"&&(Je.innerHTML=as),Rt=l(e),m($e.$$.fragment,e),Wt=l(e),m(xe.$$.fragment,e),Vt=l(e),Ue=r(e,"P",{"data-svelte-h":!0}),p(Ue)!=="svelte-1djrqq6"&&(Ue.innerHTML=ls),Ft=l(e),m(ze.$$.fragment,e),Bt=l(e),m(Ne.$$.fragment,e),Xt=l(e),qe=r(e,"P",{"data-svelte-h":!0}),p(qe)!=="svelte-bjnkty"&&(qe.textContent=os),Ht=l(e),V=r(e,"DIV",{style:!0,"data-svelte-h":!0}),p(V)!=="svelte-1obt1wq"&&(V.innerHTML=rs),Et=l(e),m(Ge.$$.fragment,e),St=l(e),nt=r(e,"P",{}),I(nt).forEach(n),this.h()},h(){Z(b,"name","hf:doc:metadata"),Z(b,"content",Ts),Z($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(k,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),bs(V,"text-align","center")},m(e,t){i(document.head,b),s(e,z,t),s(e,w,t),s(e,_,t),g(M,e,t),s(e,c,t),g(v,e,t),s(e,st,t),s(e,F,t),s(e,at,t),s(e,B,t),s(e,lt,t),s(e,X,t),s(e,ot,t),g(H,e,t),s(e,rt,t),s(e,E,t),s(e,it,t),g(S,e,t),s(e,pt,t),s(e,Y,t),s(e,ct,t),g(A,e,t),s(e,dt,t),s(e,D,t),s(e,mt,t),g(P,e,t),s(e,gt,t),s(e,Q,t),s(e,ut,t),s(e,K,t),s(e,ht,t),s(e,O,t),s(e,ft,t),s(e,ee,t),s(e,bt,t),s(e,te,t),s(e,kt,t),s(e,ne,t),s(e,_t,t),g(se,e,t),s(e,yt,t),s(e,ae,t),s(e,Mt,t),s(e,le,t),s(e,Tt,t),g(oe,e,t),s(e,wt,t),g(re,e,t),s(e,vt,t),s(e,ie,t),s(e,jt,t),s(e,pe,t),s(e,Jt,t),g(ce,e,t),s(e,$t,t),g(de,e,t),s(e,xt,t),s(e,me,t),s(e,Ut,t),g(ge,e,t),s(e,zt,t),s(e,T,t),g(ue,T,null),i(T,Dt),i(T,Ce),i(T,Pt),i(T,Le),i(T,Qt),i(T,Re),i(T,Kt),g(L,T,null),i(T,Ot),i(T,$),g(he,$,null),i($,en),i($,We),i($,tn),i($,Ve),i($,nn),i($,Fe),s(e,Nt,t),g(fe,e,t),s(e,qt,t),s(e,k,t),g(be,k,null),i(k,sn),i(k,Be),i(k,an),i(k,Xe),i(k,ln),i(k,He),i(k,on),g(R,k,null),i(k,rn),i(k,J),g(ke,J,null),i(J,pn),i(J,Ee),i(J,cn),i(J,Se),i(J,dn),i(J,Ye),i(J,mn),i(J,Ae),i(k,gn),i(k,W),g(_e,W,null),i(W,un),i(W,De),i(k,hn),i(k,N),g(ye,N,null),i(N,fn),i(N,Pe),i(N,bn),i(N,Qe),i(k,kn),i(k,q),g(Me,q,null),i(q,_n),i(q,Ke),i(q,yn),i(q,Oe),s(e,Gt,t),g(Te,e,t),s(e,It,t),s(e,we,t),s(e,Zt,t),g(ve,e,t),s(e,Ct,t),s(e,je,t),s(e,Lt,t),s(e,Je,t),s(e,Rt,t),g($e,e,t),s(e,Wt,t),g(xe,e,t),s(e,Vt,t),s(e,Ue,t),s(e,Ft,t),g(ze,e,t),s(e,Bt,t),g(Ne,e,t),s(e,Xt,t),s(e,qe,t),s(e,Ht,t),s(e,V,t),s(e,Et,t),g(Ge,e,t),s(e,St,t),s(e,nt,t),Yt=!0},p(e,[t]){const j={};t&2&&(j.$$scope={dirty:t,ctx:e}),L.$set(j);const U={};t&2&&(U.$$scope={dirty:t,ctx:e}),R.$set(U)},i(e){Yt||(u(M.$$.fragment,e),u(v.$$.fragment,e),u(H.$$.fragment,e),u(S.$$.fragment,e),u(A.$$.fragment,e),u(P.$$.fragment,e),u(se.$$.fragment,e),u(oe.$$.fragment,e),u(re.$$.fragment,e),u(ce.$$.fragment,e),u(de.$$.fragment,e),u(ge.$$.fragment,e),u(ue.$$.fragment,e),u(L.$$.fragment,e),u(he.$$.fragment,e),u(fe.$$.fragment,e),u(be.$$.fragment,e),u(R.$$.fragment,e),u(ke.$$.fragment,e),u(_e.$$.fragment,e),u(ye.$$.fragment,e),u(Me.$$.fragment,e),u(Te.$$.fragment,e),u(ve.$$.fragment,e),u($e.$$.fragment,e),u(xe.$$.fragment,e),u(ze.$$.fragment,e),u(Ne.$$.fragment,e),u(Ge.$$.fragment,e),Yt=!0)},o(e){h(M.$$.fragment,e),h(v.$$.fragment,e),h(H.$$.fragment,e),h(S.$$.fragment,e),h(A.$$.fragment,e),h(P.$$.fragment,e),h(se.$$.fragment,e),h(oe.$$.fragment,e),h(re.$$.fragment,e),h(ce.$$.fragment,e),h(de.$$.fragment,e),h(ge.$$.fragment,e),h(ue.$$.fragment,e),h(L.$$.fragment,e),h(he.$$.fragment,e),h(fe.$$.fragment,e),h(be.$$.fragment,e),h(R.$$.fragment,e),h(ke.$$.fragment,e),h(_e.$$.fragment,e),h(ye.$$.fragment,e),h(Me.$$.fragment,e),h(Te.$$.fragment,e),h(ve.$$.fragment,e),h($e.$$.fragment,e),h(xe.$$.fragment,e),h(ze.$$.fragment,e),h(Ne.$$.fragment,e),h(Ge.$$.fragment,e),Yt=!1},d(e){e&&(n(z),n(w),n(_),n(c),n(st),n(F),n(at),n(B),n(lt),n(X),n(ot),n(rt),n(E),n(it),n(pt),n(Y),n(ct),n(dt),n(D),n(mt),n(gt),n(Q),n(ut),n(K),n(ht),n(O),n(ft),n(ee),n(bt),n(te),n(kt),n(ne),n(_t),n(yt),n(ae),n(Mt),n(le),n(Tt),n(wt),n(vt),n(ie),n(jt),n(pe),n(Jt),n($t),n(xt),n(me),n(Ut),n(zt),n(T),n(Nt),n(qt),n(k),n(Gt),n(It),n(we),n(Zt),n(Ct),n(je),n(Lt),n(Je),n(Rt),n(Wt),n(Vt),n(Ue),n(Ft),n(Bt),n(Xt),n(qe),n(Ht),n(V),n(Et),n(St),n(nt)),n(b),f(M,e),f(v,e),f(H,e),f(S,e),f(A,e),f(P,e),f(se,e),f(oe,e),f(re,e),f(ce,e),f(de,e),f(ge,e),f(ue),f(L),f(he),f(fe,e),f(be),f(R),f(ke),f(_e),f(ye),f(Me),f(Te,e),f(ve,e),f($e,e),f(xe,e),f(ze,e),f(Ne,e),f(Ge,e)}}}const Ts='{"title":"NLLB","local":"nllb","sections":[{"title":"Updated tokenizer behavior","local":"transformers.NllbTokenizer","sections":[],"depth":2},{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Generating with NLLB","local":"generating-with-nllb","sections":[{"title":"Generating from any other language than English","local":"generating-from-any-other-language-than-english","sections":[],"depth":3}],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2},{"title":"NllbTokenizer","local":"nllbtokenizer","sections":[],"depth":2},{"title":"NllbTokenizerFast","local":"nllbtokenizerfast","sections":[],"depth":2},{"title":"Using Flash Attention 2","local":"using-flash-attention-2","sections":[{"title":"Installation","local":"installation","sections":[],"depth":3},{"title":"Usage","local":"usage","sections":[],"depth":3},{"title":"Expected speedups","local":"expected-speedups","sections":[],"depth":3}],"depth":2}],"depth":1}';function ws(Ze){return gs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zs extends us{constructor(b){super(),hs(this,b,ws,Ms,ms,{})}}export{zs as component};
