import{s as ae,n as ne,o as se}from"../chunks/scheduler.d627b047.js";import{S as oe,i as me,g as m,s as n,r,A as re,h as i,f as l,c as s,j as te,u as p,x as _,k as le,y as ie,a,v as d,d as y,t as u,w as h}from"../chunks/index.73c51727.js";import{C as N}from"../chunks/CodeBlock.5f78c87f.js";import{H as P,E as pe}from"../chunks/index.8df1db42.js";function de(L){let o,$,v,C,c,j,f,A='Once you have trained a model using either the SFTTrainer, PPOTrainer, or DPOTrainer, you will have a fine-tuned model that can be used for text generation. In this section, we’ll walk through the process of loading the fine-tuned model and generating text. If you need to run an inference server with the trained model, you can explore libraries such as <a href="https://github.com/huggingface/text-generation-inference" rel="nofollow"><code>text-generation-inference</code></a>.',V,M,B,b,K="If you have fine-tuned a model fully, meaning without the use of PEFT you can simply load it like any other language model in transformers. E.g. the value head that was trained during the PPO training is no longer needed and if you load the model with the original transformer class it will be ignored:",X,U,F,Z,O="Alternatively you can also use the pipeline:",x,J,Y,w,E,W,I,g,D="You can also merge the adapters into the base model so you can use the model like a normal transformers model, however the checkpoint will be significantly bigger:",z,T,Q,G,ee="Once you have the model loaded and either merged the adapters or keep them separately on top you can run generation as with a normal model outlined above.",S,k,q,R,H;return c=new P({props:{title:"Use model after training",local:"use-model-after-training",headingTag:"h1"}}),M=new P({props:{title:"Load and Generate",local:"load-and-generate",headingTag:"h2"}}),U=new N({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTSUwQSUwQW1vZGVsX25hbWVfb3JfcGF0aCUyMCUzRCUyMCUyMmthc2hpZiUyRnN0YWNrLWxsYW1hLTIlMjIlMjAlMjNwYXRoJTJGdG8lMkZ5b3VyJTJGbW9kZWwlMkZvciUyRm5hbWUlMkZvbiUyRmh1YiUwQWRldmljZSUyMCUzRCUyMCUyMmNwdSUyMiUyMCUyMyUyMG9yJTIwJTIyY3VkYSUyMiUyMGlmJTIweW91JTIwaGF2ZSUyMGElMjBHUFUlMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNLmZyb21fcHJldHJhaW5lZChtb2RlbF9uYW1lX29yX3BhdGgpLnRvKGRldmljZSklMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9uYW1lX29yX3BhdGgpJTBBJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyLmVuY29kZSglMjJUaGlzJTIwbW92aWUlMjB3YXMlMjByZWFsbHklMjIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS50byhkZXZpY2UpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKGlucHV0cyklMEFwcmludCh0b2tlbml6ZXIuZGVjb2RlKG91dHB1dHMlNUIwJTVEKSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForCausalLM

model_name_or_path = <span class="hljs-string">&quot;kashif/stack-llama-2&quot;</span> <span class="hljs-comment">#path/to/your/model/or/name/on/hub</span>
device = <span class="hljs-string">&quot;cpu&quot;</span> <span class="hljs-comment"># or &quot;cuda&quot; if you have a GPU</span>

model = AutoModelForCausalLM.from_pretrained(model_name_or_path).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)

inputs = tokenizer.encode(<span class="hljs-string">&quot;This movie was really&quot;</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).to(device)
outputs = model.generate(inputs)
<span class="hljs-built_in">print</span>(tokenizer.decode(outputs[<span class="hljs-number">0</span>]))`,wrap:!1}}),J=new N({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbW9kZWxfbmFtZV9vcl9wYXRoJTIwJTNEJTIwJTIya2FzaGlmJTJGc3RhY2stbGxhbWEtMiUyMiUyMCUyM3BhdGglMkZ0byUyRnlvdXIlMkZtb2RlbCUyRm9yJTJGbmFtZSUyRm9uJTJGaHViJTBBcGlwZSUyMCUzRCUyMHBpcGVsaW5lKCUyMnRleHQtZ2VuZXJhdGlvbiUyMiUyQyUyMG1vZGVsJTNEbW9kZWxfbmFtZV9vcl9wYXRoKSUwQXByaW50KHBpcGUoJTIyVGhpcyUyMG1vdmllJTIwd2FzJTIwcmVhbGx5JTIyKSU1QjAlNUQlNUIlMjJnZW5lcmF0ZWRfdGV4dCUyMiU1RCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

model_name_or_path = <span class="hljs-string">&quot;kashif/stack-llama-2&quot;</span> <span class="hljs-comment">#path/to/your/model/or/name/on/hub</span>
pipe = pipeline(<span class="hljs-string">&quot;text-generation&quot;</span>, model=model_name_or_path)
<span class="hljs-built_in">print</span>(pipe(<span class="hljs-string">&quot;This movie was really&quot;</span>)[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;generated_text&quot;</span>])`,wrap:!1}}),w=new P({props:{title:"Use Adapters PEFT",local:"use-adapters-peft",headingTag:"h2"}}),W=new N({props:{code:"ZnJvbSUyMHBlZnQlMjBpbXBvcnQlMjBQZWZ0Q29uZmlnJTJDJTIwUGVmdE1vZGVsJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvckNhdXNhbExNJTJDJTIwQXV0b1Rva2VuaXplciUwQSUwQWJhc2VfbW9kZWxfbmFtZSUyMCUzRCUyMCUyMmthc2hpZiUyRnN0YWNrLWxsYW1hLTIlMjIlMjAlMjNwYXRoJTJGdG8lMkZ5b3VyJTJGbW9kZWwlMkZvciUyRm5hbWUlMkZvbiUyRmh1YiUyMiUwQWFkYXB0ZXJfbW9kZWxfbmFtZSUyMCUzRCUyMCUyMnBhdGglMkZ0byUyRm15JTJGYWRhcHRlciUyMiUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yQ2F1c2FsTE0uZnJvbV9wcmV0cmFpbmVkKGJhc2VfbW9kZWxfbmFtZSklMEFtb2RlbCUyMCUzRCUyMFBlZnRNb2RlbC5mcm9tX3ByZXRyYWluZWQobW9kZWwlMkMlMjBhZGFwdGVyX21vZGVsX25hbWUpJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoYmFzZV9tb2RlbF9uYW1lKQ==",highlighted:`<span class="hljs-keyword">from</span> peft <span class="hljs-keyword">import</span> PeftConfig, PeftModel
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForCausalLM, AutoTokenizer

base_model_name = <span class="hljs-string">&quot;kashif/stack-llama-2&quot;</span> <span class="hljs-comment">#path/to/your/model/or/name/on/hub&quot;</span>
adapter_model_name = <span class="hljs-string">&quot;path/to/my/adapter&quot;</span>

model = AutoModelForCausalLM.from_pretrained(base_model_name)
model = PeftModel.from_pretrained(model, adapter_model_name)

tokenizer = AutoTokenizer.from_pretrained(base_model_name)`,wrap:!1}}),T=new N({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JDYXVzYWxMTS5mcm9tX3ByZXRyYWluZWQoYmFzZV9tb2RlbF9uYW1lKSUwQW1vZGVsJTIwJTNEJTIwUGVmdE1vZGVsLmZyb21fcHJldHJhaW5lZChtb2RlbCUyQyUyMGFkYXB0ZXJfbW9kZWxfbmFtZSklMEElMEFtb2RlbCUyMCUzRCUyMG1vZGVsLm1lcmdlX2FuZF91bmxvYWQoKSUwQW1vZGVsLnNhdmVfcHJldHJhaW5lZCglMjJtZXJnZWRfYWRhcHRlcnMlMjIp",highlighted:`model = AutoModelForCausalLM.from_pretrained(base_model_name)
model = PeftModel.from_pretrained(model, adapter_model_name)

model = model.merge_and_unload()
model.save_pretrained(<span class="hljs-string">&quot;merged_adapters&quot;</span>)`,wrap:!1}}),k=new pe({props:{source:"https://github.com/huggingface/trl/blob/main/docs/source/use_model.md"}}),{c(){o=m("meta"),$=n(),v=m("p"),C=n(),r(c.$$.fragment),j=n(),f=m("p"),f.innerHTML=A,V=n(),r(M.$$.fragment),B=n(),b=m("p"),b.textContent=K,X=n(),r(U.$$.fragment),F=n(),Z=m("p"),Z.textContent=O,x=n(),r(J.$$.fragment),Y=n(),r(w.$$.fragment),E=n(),r(W.$$.fragment),I=n(),g=m("p"),g.textContent=D,z=n(),r(T.$$.fragment),Q=n(),G=m("p"),G.textContent=ee,S=n(),r(k.$$.fragment),q=n(),R=m("p"),this.h()},l(e){const t=re("svelte-u9bgzb",document.head);o=i(t,"META",{name:!0,content:!0}),t.forEach(l),$=s(e),v=i(e,"P",{}),te(v).forEach(l),C=s(e),p(c.$$.fragment,e),j=s(e),f=i(e,"P",{"data-svelte-h":!0}),_(f)!=="svelte-1f3c7jz"&&(f.innerHTML=A),V=s(e),p(M.$$.fragment,e),B=s(e),b=i(e,"P",{"data-svelte-h":!0}),_(b)!=="svelte-jh3nqo"&&(b.textContent=K),X=s(e),p(U.$$.fragment,e),F=s(e),Z=i(e,"P",{"data-svelte-h":!0}),_(Z)!=="svelte-slosoc"&&(Z.textContent=O),x=s(e),p(J.$$.fragment,e),Y=s(e),p(w.$$.fragment,e),E=s(e),p(W.$$.fragment,e),I=s(e),g=i(e,"P",{"data-svelte-h":!0}),_(g)!=="svelte-11j5qxm"&&(g.textContent=D),z=s(e),p(T.$$.fragment,e),Q=s(e),G=i(e,"P",{"data-svelte-h":!0}),_(G)!=="svelte-1hvquzo"&&(G.textContent=ee),S=s(e),p(k.$$.fragment,e),q=s(e),R=i(e,"P",{}),te(R).forEach(l),this.h()},h(){le(o,"name","hf:doc:metadata"),le(o,"content",ye)},m(e,t){ie(document.head,o),a(e,$,t),a(e,v,t),a(e,C,t),d(c,e,t),a(e,j,t),a(e,f,t),a(e,V,t),d(M,e,t),a(e,B,t),a(e,b,t),a(e,X,t),d(U,e,t),a(e,F,t),a(e,Z,t),a(e,x,t),d(J,e,t),a(e,Y,t),d(w,e,t),a(e,E,t),d(W,e,t),a(e,I,t),a(e,g,t),a(e,z,t),d(T,e,t),a(e,Q,t),a(e,G,t),a(e,S,t),d(k,e,t),a(e,q,t),a(e,R,t),H=!0},p:ne,i(e){H||(y(c.$$.fragment,e),y(M.$$.fragment,e),y(U.$$.fragment,e),y(J.$$.fragment,e),y(w.$$.fragment,e),y(W.$$.fragment,e),y(T.$$.fragment,e),y(k.$$.fragment,e),H=!0)},o(e){u(c.$$.fragment,e),u(M.$$.fragment,e),u(U.$$.fragment,e),u(J.$$.fragment,e),u(w.$$.fragment,e),u(W.$$.fragment,e),u(T.$$.fragment,e),u(k.$$.fragment,e),H=!1},d(e){e&&(l($),l(v),l(C),l(j),l(f),l(V),l(B),l(b),l(X),l(F),l(Z),l(x),l(Y),l(E),l(I),l(g),l(z),l(Q),l(G),l(S),l(q),l(R)),l(o),h(c,e),h(M,e),h(U,e),h(J,e),h(w,e),h(W,e),h(T,e),h(k,e)}}}const ye='{"title":"Use model after training","local":"use-model-after-training","sections":[{"title":"Load and Generate","local":"load-and-generate","sections":[],"depth":2},{"title":"Use Adapters PEFT","local":"use-adapters-peft","sections":[],"depth":2}],"depth":1}';function ue(L){return se(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class be extends oe{constructor(o){super(),me(this,o,ue,de,ae,{})}}export{be as component};
