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