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