import{s as Ee,o as Xe,n as ze}from"../chunks/scheduler.25b97de1.js";import{S as Ie,i as Be,g as i,s as l,r as w,A as Pe,h as s,f as o,c as n,j as D,u as T,x as m,k as Ae,y as d,a,v as $,d as _,t as k,w as L}from"../chunks/index.d9030fc9.js";import{T as Ve}from"../chunks/Tip.baa67368.js";import{C as $e}from"../chunks/CodeBlock.e6cd0d95.js";import{H as me,E as Ye}from"../chunks/EditOnGithub.91d95064.js";function Fe(K){let p,C=`The <code>Llama3</code> models were trained using <code>bfloat16</code>, but the original inference uses <code>float16</code>. The checkpoints uploaded on the Hub use <code>torch_dtype = &#39;float16&#39;</code>, which will be
used by the <code>AutoModel</code> API to cast the checkpoints from <code>torch.float32</code> to <code>torch.float16</code>.`,g,f,b="The <code>dtype</code> of the online weights is mostly irrelevant unless you are using <code>torch_dtype=&quot;auto&quot;</code> when initializing a model using <code>model = AutoModelForCausalLM.from_pretrained(&quot;path&quot;, torch_dtype = &quot;auto&quot;)</code>. The reason is that the model will first be downloaded ( using the <code>dtype</code> of the checkpoints online), then it will be casted to the default <code>dtype</code> of <code>torch</code> (becomes <code>torch.float32</code>), and finally, if there is a <code>torch_dtype</code> provided in the config, it will be used.",v,u,U="Training the model in <code>float16</code> is not recommended and is known to produce <code>nan</code>; as such, the model should be trained in <code>bfloat16</code>.";return{c(){p=i("p"),p.innerHTML=C,g=l(),f=i("p"),f.innerHTML=b,v=l(),u=i("p"),u.innerHTML=U},l(r){p=s(r,"P",{"data-svelte-h":!0}),m(p)!=="svelte-1lksm71"&&(p.innerHTML=C),g=n(r),f=s(r,"P",{"data-svelte-h":!0}),m(f)!=="svelte-17gt3kv"&&(f.innerHTML=b),v=n(r),u=s(r,"P",{"data-svelte-h":!0}),m(u)!=="svelte-wna3bo"&&(u.innerHTML=U)},m(r,M){a(r,p,M),a(r,g,M),a(r,f,M),a(r,v,M),a(r,u,M)},p:ze,d(r){r&&(o(p),o(g),o(f),o(v),o(u))}}}function Ne(K){let p,C,g,f,b,v,u,U,r,M,H,_e='The Llama3 model was proposed in <a href="https://ai.meta.com/blog/meta-llama-3/" rel="nofollow">Introducing Meta Llama 3: The most capable openly available LLM to date</a> by the meta AI team.',ee,j,ke="The abstract from the blogpost is the following:",te,J,Le="<em>Today, we’re excited to share the first two models of the next generation of Llama, Meta Llama 3, available for broad use. This release features pretrained and instruction-fine-tuned language models with 8B and 70B parameters that can support a broad range of use cases. This next generation of Llama demonstrates state-of-the-art performance on a wide range of industry benchmarks and offers new capabilities, including improved reasoning. We believe these are the best open source models of their class, period. In support of our longstanding open approach, we’re putting Llama 3 in the hands of the community. We want to kickstart the next wave of innovation in AI across the stack—from applications to developer tools to evals to inference optimizations and more. We can’t wait to see what you build and look forward to your feedback.</em>",oe,W,xe=`Checkout all Llama3 model checkpoints <a href="https://huggingface.co/models?search=llama3" rel="nofollow">here</a>.
The original code of the authors can be found <a href="https://github.com/meta-llama/llama3" rel="nofollow">here</a>.`,ae,q,le,x,ne,G,Ce="Tips:",ie,c,I,Ue='<p>Weights for the Llama3 models can be obtained by filling out <a href="https://ai.meta.com/resources/models-and-libraries/llama-downloads/" rel="nofollow">this form</a></p>',ue,B,He="<p>The architecture is exactly the same as Llama2.</p>",fe,P,je='<p>The tokenizer is a BPE model based on <a href="https://github.com/openai/tiktoken" rel="nofollow">tiktoken</a> (vs the one based on sentencepiece implementation for Llama2). The main difference that it ignores BPE merge rules when an input token is part of the vocab. This means that if no merge exist to produce <code>&quot;hugging&quot;</code>, instead of having the smallest units, like <code>[&quot;hug&quot;,&quot;ging&quot;] form 2 tokens, if </code>“hugging”` is part of the vocab, it will be automatically returned as a token.</p>',ge,V,Je="<p>The original model uses <code>pad_id = -1</code> which means that there is no padding token. We can’t have the same logic, make sure to add a padding token using <code>tokenizer.add_special_tokens({&quot;pad_token&quot;:&quot;&lt;pad&gt;&quot;})</code> and resize the token embedding accordingly. You should also set the <code>model.config.pad_token_id</code>. The <code>embed_tokens</code> layer of the model is initialized with <code>self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.config.padding_idx)</code>, which makes sure that encoding the padding token will output zeros, so passing it when initializing is recommended.</p>",be,R,Y,We='The original checkpoint can be converted using the <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/models/llama/convert_llama_weights_to_hf.py" rel="nofollow">conversion script</a>. The script can be called with the following (example) command:',Me,Z,ve,y,F,qe="After conversion, the model and tokenizer can be loaded via:",ye,A,we,N,Ge=`Note that executing the script requires enough CPU RAM to host the whole model in float16 precision (even if the biggest versions
come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM). For the 75B model, it’s thus 145GB of RAM needed.`,Te,S,Re="<p>When using Flash Attention 2 via <code>attn_implementation=&quot;flash_attention_2&quot;</code>, don’t pass <code>torch_dtype</code> to the <code>from_pretrained</code> class method and use Automatic Mixed-Precision training. When using <code>Trainer</code>, it is simply specifying either <code>fp16</code> or <code>bf16</code> to <code>True</code>. Otherwise, make sure you are using <code>torch.autocast</code>. This is required because the Flash Attention only support <code>fp16</code> and <code>bf16</code> data type.</p>",se,E,re,X,Ze='A ton of cool resources are already available on the documentation page of <a href="./llama2">Llama2</a>, inviting contributors to add new resources curated for Llama3 here! 🤗',de,z,ce,O,pe;return b=new me({props:{title:"Llama3",local:"llama3",headingTag:"h1"}}),u=new $e({props:{code:"aW1wb3J0JTIwdHJhbnNmb3JtZXJzJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMm1ldGEtbGxhbWElMkZNZXRhLUxsYW1hLTMtOEIlMjIlMEElMEFwaXBlbGluZSUyMCUzRCUyMHRyYW5zZm9ybWVycy5waXBlbGluZSglMjJ0ZXh0LWdlbmVyYXRpb24lMjIlMkMlMjBtb2RlbCUzRG1vZGVsX2lkJTJDJTIwbW9kZWxfa3dhcmdzJTNEJTdCJTIydG9yY2hfZHR5cGUlMjIlM0ElMjB0b3JjaC5iZmxvYXQxNiU3RCUyQyUyMGRldmljZV9tYXAlM0QlMjJhdXRvJTIyKSUwQXBpcGVsaW5lKCUyMkhleSUyMGhvdyUyMGFyZSUyMHlvdSUyMGRvaW5nJTIwdG9kYXklM0YlMjIp",highlighted:`<span class="hljs-keyword">import</span> transformers
<span class="hljs-keyword">import</span> torch

<span class="hljs-title">model_id</span> = <span class="hljs-string">&quot;meta-llama/Meta-Llama-3-8B&quot;</span>

<span class="hljs-title">pipeline</span> = transformers.pipeline(<span class="hljs-string">&quot;text-generation&quot;</span>, model=model_id, model_kwargs={<span class="hljs-string">&quot;torch_dtype&quot;</span>: torch.bfloat16}, device_map=<span class="hljs-string">&quot;auto&quot;</span>)
<span class="hljs-title">pipeline</span>(<span class="hljs-string">&quot;Hey how are you doing today?&quot;</span>)`,wrap:!1}}),r=new me({props:{title:"Overview",local:"overview",headingTag:"h2"}}),q=new me({props:{title:"Usage tips",local:"usage-tips",headingTag:"h2"}}),x=new Ve({props:{warning:!0,$$slots:{default:[Fe]},$$scope:{ctx:K}}}),Z=new $e({props:{code:"cHl0aG9uJTIwc3JjJTJGdHJhbnNmb3JtZXJzJTJGbW9kZWxzJTJGbGxhbWElMkZjb252ZXJ0X2xsYW1hX3dlaWdodHNfdG9faGYucHklMjAlNUMlMEElMjAlMjAlMjAlMjAtLWlucHV0X2RpciUyMCUyRnBhdGglMkZ0byUyRmRvd25sb2FkZWQlMkZsbGFtYSUyRndlaWdodHMlMjAtLW1vZGVsX3NpemUlMjA3QiUyMC0tb3V0cHV0X2RpciUyMCUyRm91dHB1dCUyRnBhdGglMjAtLWxsYW1hX3ZlcnNpb24lMjAz",highlighted:`python src/transformers/models/llama/convert_llama_weights_to_hf.py \\
    --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path --llama_version 3`,wrap:!1}}),A=new $e({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKCUyMiUyRm91dHB1dCUyRnBhdGglMjIpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoJTIyJTJGb3V0cHV0JTJGcGF0aCUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;/output/path&quot;</span>)
model = AutoModelForCausalLM.from_pretrained(<span class="hljs-string">&quot;/output/path&quot;</span>)`,wrap:!1}}),E=new me({props:{title:"Resources",local:"resources",headingTag:"h2"}}),z=new Ye({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/llama3.md"}}),{c(){p=i("meta"),C=l(),g=i("p"),f=l(),w(b.$$.fragment),v=l(),w(u.$$.fragment),U=l(),w(r.$$.fragment),M=l(),H=i("p"),H.innerHTML=_e,ee=l(),j=i("p"),j.textContent=ke,te=l(),J=i("p"),J.innerHTML=Le,oe=l(),W=i("p"),W.innerHTML=xe,ae=l(),w(q.$$.fragment),le=l(),w(x.$$.fragment),ne=l(),G=i("p"),G.textContent=Ce,ie=l(),c=i("ul"),I=i("li"),I.innerHTML=Ue,ue=l(),B=i("li"),B.innerHTML=He,fe=l(),P=i("li"),P.innerHTML=je,ge=l(),V=i("li"),V.innerHTML=Je,be=l(),R=i("li"),Y=i("p"),Y.innerHTML=We,Me=l(),w(Z.$$.fragment),ve=l(),y=i("li"),F=i("p"),F.textContent=qe,ye=l(),w(A.$$.fragment),we=l(),N=i("p"),N.textContent=Ge,Te=l(),S=i("li"),S.innerHTML=Re,se=l(),w(E.$$.fragment),re=l(),X=i("p"),X.innerHTML=Ze,de=l(),w(z.$$.fragment),ce=l(),O=i("p"),this.h()},l(e){const t=Pe("svelte-u9bgzb",document.head);p=s(t,"META",{name:!0,content:!0}),t.forEach(o),C=n(e),g=s(e,"P",{}),D(g).forEach(o),f=n(e),T(b.$$.fragment,e),v=n(e),T(u.$$.fragment,e),U=n(e),T(r.$$.fragment,e),M=n(e),H=s(e,"P",{"data-svelte-h":!0}),m(H)!=="svelte-1ngolsb"&&(H.innerHTML=_e),ee=n(e),j=s(e,"P",{"data-svelte-h":!0}),m(j)!=="svelte-14ru3ry"&&(j.textContent=ke),te=n(e),J=s(e,"P",{"data-svelte-h":!0}),m(J)!=="svelte-ggt8ju"&&(J.innerHTML=Le),oe=n(e),W=s(e,"P",{"data-svelte-h":!0}),m(W)!=="svelte-1xj5glz"&&(W.innerHTML=xe),ae=n(e),T(q.$$.fragment,e),le=n(e),T(x.$$.fragment,e),ne=n(e),G=s(e,"P",{"data-svelte-h":!0}),m(G)!=="svelte-axv494"&&(G.textContent=Ce),ie=n(e),c=s(e,"UL",{});var h=D(c);I=s(h,"LI",{"data-svelte-h":!0}),m(I)!=="svelte-152iser"&&(I.innerHTML=Ue),ue=n(h),B=s(h,"LI",{"data-svelte-h":!0}),m(B)!=="svelte-1gaq40l"&&(B.innerHTML=He),fe=n(h),P=s(h,"LI",{"data-svelte-h":!0}),m(P)!=="svelte-2r23bq"&&(P.innerHTML=je),ge=n(h),V=s(h,"LI",{"data-svelte-h":!0}),m(V)!=="svelte-1iokj9y"&&(V.innerHTML=Je),be=n(h),R=s(h,"LI",{});var he=D(R);Y=s(he,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-1vss5eo"&&(Y.innerHTML=We),Me=n(he),T(Z.$$.fragment,he),he.forEach(o),ve=n(h),y=s(h,"LI",{});var Q=D(y);F=s(Q,"P",{"data-svelte-h":!0}),m(F)!=="svelte-b5pwv6"&&(F.textContent=qe),ye=n(Q),T(A.$$.fragment,Q),we=n(Q),N=s(Q,"P",{"data-svelte-h":!0}),m(N)!=="svelte-oga8ra"&&(N.textContent=Ge),Q.forEach(o),Te=n(h),S=s(h,"LI",{"data-svelte-h":!0}),m(S)!=="svelte-174tptj"&&(S.innerHTML=Re),h.forEach(o),se=n(e),T(E.$$.fragment,e),re=n(e),X=s(e,"P",{"data-svelte-h":!0}),m(X)!=="svelte-f4fme6"&&(X.innerHTML=Ze),de=n(e),T(z.$$.fragment,e),ce=n(e),O=s(e,"P",{}),D(O).forEach(o),this.h()},h(){Ae(p,"name","hf:doc:metadata"),Ae(p,"content",Se)},m(e,t){d(document.head,p),a(e,C,t),a(e,g,t),a(e,f,t),$(b,e,t),a(e,v,t),$(u,e,t),a(e,U,t),$(r,e,t),a(e,M,t),a(e,H,t),a(e,ee,t),a(e,j,t),a(e,te,t),a(e,J,t),a(e,oe,t),a(e,W,t),a(e,ae,t),$(q,e,t),a(e,le,t),$(x,e,t),a(e,ne,t),a(e,G,t),a(e,ie,t),a(e,c,t),d(c,I),d(c,ue),d(c,B),d(c,fe),d(c,P),d(c,ge),d(c,V),d(c,be),d(c,R),d(R,Y),d(R,Me),$(Z,R,null),d(c,ve),d(c,y),d(y,F),d(y,ye),$(A,y,null),d(y,we),d(y,N),d(c,Te),d(c,S),a(e,se,t),$(E,e,t),a(e,re,t),a(e,X,t),a(e,de,t),$(z,e,t),a(e,ce,t),a(e,O,t),pe=!0},p(e,[t]){const h={};t&2&&(h.$$scope={dirty:t,ctx:e}),x.$set(h)},i(e){pe||(_(b.$$.fragment,e),_(u.$$.fragment,e),_(r.$$.fragment,e),_(q.$$.fragment,e),_(x.$$.fragment,e),_(Z.$$.fragment,e),_(A.$$.fragment,e),_(E.$$.fragment,e),_(z.$$.fragment,e),pe=!0)},o(e){k(b.$$.fragment,e),k(u.$$.fragment,e),k(r.$$.fragment,e),k(q.$$.fragment,e),k(x.$$.fragment,e),k(Z.$$.fragment,e),k(A.$$.fragment,e),k(E.$$.fragment,e),k(z.$$.fragment,e),pe=!1},d(e){e&&(o(C),o(g),o(f),o(v),o(U),o(M),o(H),o(ee),o(j),o(te),o(J),o(oe),o(W),o(ae),o(le),o(ne),o(G),o(ie),o(c),o(se),o(re),o(X),o(de),o(ce),o(O)),o(p),L(b,e),L(u,e),L(r,e),L(q,e),L(x,e),L(Z),L(A),L(E,e),L(z,e)}}}const Se='{"title":"Llama3","local":"llama3","sections":[{"title":"Overview","local":"overview","sections":[],"depth":2},{"title":"Usage tips","local":"usage-tips","sections":[],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2}],"depth":1}';function Qe(K){return Xe(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ot extends Ie{constructor(p){super(),Be(this,p,Qe,Ne,Ee,{})}}export{ot as component};
