import{s as _e,o as ke,n as xe}from"../chunks/scheduler.25b97de1.js";import{S as Ce,i as Ue,g as d,s as l,r as g,A as Le,h as r,f as o,c as n,j as $e,u as b,x as m,k as Te,y as Je,a,v as y,d as M,t as w,w as v}from"../chunks/index.d9030fc9.js";import{T as je}from"../chunks/Tip.baa67368.js";import{C as ce}from"../chunks/CodeBlock.e6cd0d95.js";import{H as re,E as We}from"../chunks/EditOnGithub.91d95064.js";function Ge(P){let s,_=`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>.`,h,p,u="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.",f,c,k="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(){s=d("p"),s.innerHTML=_,h=l(),p=d("p"),p.innerHTML=u,f=l(),c=d("p"),c.innerHTML=k},l(i){s=r(i,"P",{"data-svelte-h":!0}),m(s)!=="svelte-1lksm71"&&(s.innerHTML=_),h=n(i),p=r(i,"P",{"data-svelte-h":!0}),m(p)!=="svelte-17gt3kv"&&(p.innerHTML=u),f=n(i),c=r(i,"P",{"data-svelte-h":!0}),m(c)!=="svelte-wna3bo"&&(c.innerHTML=k)},m(i,$){a(i,s,$),a(i,h,$),a(i,p,$),a(i,f,$),a(i,c,$)},p:xe,d(i){i&&(o(s),o(h),o(p),o(f),o(c))}}}function He(P){let s,_,h,p,u,f,c,k,i,$='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.',I,x,me="The abstract from the blogpost is the following:",V,C,pe="<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>",Y,U,he=`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>.`,F,L,N,T,S,J,ue="Tips:",Q,j,fe='<li>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></li> <li>The architecture is exactly the same as Llama2.</li> <li>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.</li> <li>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.</li> <li>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:</li>',O,W,D,G,ge="<li>After conversion, the model and tokenizer can be loaded via:</li>",K,H,ee,q,be=`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,R,ye="<li>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.</li>",oe,Z,Me="## Quick usage",ae,A,le,X,ne,z,we="A ton of cool resources are already available on the documentation page of [~llama2], inviting contributors to add new resources curated for Llama3 here! 🤗",ie,E,se,B,de;return u=new re({props:{title:"Llama3",local:"llama3",headingTag:"h1"}}),c=new re({props:{title:"Overview",local:"overview",headingTag:"h2"}}),L=new re({props:{title:"Usage tips",local:"usage-tips",headingTag:"h2"}}),T=new je({props:{warning:!0,$$slots:{default:[Ge]},$$scope:{ctx:P}}}),W=new ce({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}}),H=new ce({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}}),A=new ce({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}}),X=new re({props:{title:"Resources",local:"resources",headingTag:"h2"}}),E=new We({props:{source:"https://github.com/huggingface/transformers/blob/main/docs/source/en/model_doc/llama3.md"}}),{c(){s=d("meta"),_=l(),h=d("p"),p=l(),g(u.$$.fragment),f=l(),g(c.$$.fragment),k=l(),i=d("p"),i.innerHTML=$,I=l(),x=d("p"),x.textContent=me,V=l(),C=d("p"),C.innerHTML=pe,Y=l(),U=d("p"),U.innerHTML=he,F=l(),g(L.$$.fragment),N=l(),g(T.$$.fragment),S=l(),J=d("p"),J.textContent=ue,Q=l(),j=d("ul"),j.innerHTML=fe,O=l(),g(W.$$.fragment),D=l(),G=d("ul"),G.innerHTML=ge,K=l(),g(H.$$.fragment),ee=l(),q=d("p"),q.textContent=be,te=l(),R=d("ul"),R.innerHTML=ye,oe=l(),Z=d("p"),Z.textContent=Me,ae=l(),g(A.$$.fragment),le=l(),g(X.$$.fragment),ne=l(),z=d("p"),z.textContent=we,ie=l(),g(E.$$.fragment),se=l(),B=d("p"),this.h()},l(e){const t=Le("svelte-u9bgzb",document.head);s=r(t,"META",{name:!0,content:!0}),t.forEach(o),_=n(e),h=r(e,"P",{}),$e(h).forEach(o),p=n(e),b(u.$$.fragment,e),f=n(e),b(c.$$.fragment,e),k=n(e),i=r(e,"P",{"data-svelte-h":!0}),m(i)!=="svelte-1ngolsb"&&(i.innerHTML=$),I=n(e),x=r(e,"P",{"data-svelte-h":!0}),m(x)!=="svelte-14ru3ry"&&(x.textContent=me),V=n(e),C=r(e,"P",{"data-svelte-h":!0}),m(C)!=="svelte-ggt8ju"&&(C.innerHTML=pe),Y=n(e),U=r(e,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1xj5glz"&&(U.innerHTML=he),F=n(e),b(L.$$.fragment,e),N=n(e),b(T.$$.fragment,e),S=n(e),J=r(e,"P",{"data-svelte-h":!0}),m(J)!=="svelte-axv494"&&(J.textContent=ue),Q=n(e),j=r(e,"UL",{"data-svelte-h":!0}),m(j)!=="svelte-wl76m7"&&(j.innerHTML=fe),O=n(e),b(W.$$.fragment,e),D=n(e),G=r(e,"UL",{"data-svelte-h":!0}),m(G)!=="svelte-yjbkch"&&(G.innerHTML=ge),K=n(e),b(H.$$.fragment,e),ee=n(e),q=r(e,"P",{"data-svelte-h":!0}),m(q)!=="svelte-199e5ee"&&(q.textContent=be),te=n(e),R=r(e,"UL",{"data-svelte-h":!0}),m(R)!=="svelte-1dgndgd"&&(R.innerHTML=ye),oe=n(e),Z=r(e,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-rdbvqu"&&(Z.textContent=Me),ae=n(e),b(A.$$.fragment,e),le=n(e),b(X.$$.fragment,e),ne=n(e),z=r(e,"P",{"data-svelte-h":!0}),m(z)!=="svelte-1ox04n7"&&(z.textContent=we),ie=n(e),b(E.$$.fragment,e),se=n(e),B=r(e,"P",{}),$e(B).forEach(o),this.h()},h(){Te(s,"name","hf:doc:metadata"),Te(s,"content",qe)},m(e,t){Je(document.head,s),a(e,_,t),a(e,h,t),a(e,p,t),y(u,e,t),a(e,f,t),y(c,e,t),a(e,k,t),a(e,i,t),a(e,I,t),a(e,x,t),a(e,V,t),a(e,C,t),a(e,Y,t),a(e,U,t),a(e,F,t),y(L,e,t),a(e,N,t),y(T,e,t),a(e,S,t),a(e,J,t),a(e,Q,t),a(e,j,t),a(e,O,t),y(W,e,t),a(e,D,t),a(e,G,t),a(e,K,t),y(H,e,t),a(e,ee,t),a(e,q,t),a(e,te,t),a(e,R,t),a(e,oe,t),a(e,Z,t),a(e,ae,t),y(A,e,t),a(e,le,t),y(X,e,t),a(e,ne,t),a(e,z,t),a(e,ie,t),y(E,e,t),a(e,se,t),a(e,B,t),de=!0},p(e,[t]){const ve={};t&2&&(ve.$$scope={dirty:t,ctx:e}),T.$set(ve)},i(e){de||(M(u.$$.fragment,e),M(c.$$.fragment,e),M(L.$$.fragment,e),M(T.$$.fragment,e),M(W.$$.fragment,e),M(H.$$.fragment,e),M(A.$$.fragment,e),M(X.$$.fragment,e),M(E.$$.fragment,e),de=!0)},o(e){w(u.$$.fragment,e),w(c.$$.fragment,e),w(L.$$.fragment,e),w(T.$$.fragment,e),w(W.$$.fragment,e),w(H.$$.fragment,e),w(A.$$.fragment,e),w(X.$$.fragment,e),w(E.$$.fragment,e),de=!1},d(e){e&&(o(_),o(h),o(p),o(f),o(k),o(i),o(I),o(x),o(V),o(C),o(Y),o(U),o(F),o(N),o(S),o(J),o(Q),o(j),o(O),o(D),o(G),o(K),o(ee),o(q),o(te),o(R),o(oe),o(Z),o(ae),o(le),o(ne),o(z),o(ie),o(se),o(B)),o(s),v(u,e),v(c,e),v(L,e),v(T,e),v(W,e),v(H,e),v(A,e),v(X,e),v(E,e)}}}const qe='{"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 Re(P){return ke(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Be extends Ce{constructor(s){super(),Ue(this,s,Re,He,_e,{})}}export{Be as component};
