import{s as ne,n as oe,o as ie}from"../chunks/scheduler.78382b47.js";import{S as se,i as re,e as l,s as o,c as w,h as le,a as d,d as a,b as i,f as W,g as R,j,k as G,l as J,m as n,n as y,t as x,o as T,p as C}from"../chunks/index.6dd35eb6.js";import{C as de,H as K,E as pe}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.6888f903.js";import{D as ae}from"../chunks/Docstring.286e0aef.js";function me(Q){let s,A,L,k,p,P,m,U,f,X='<a href="https://huggingface.co/papers/2409.00119" rel="nofollow">RoAd</a> is a parameter‑efficient fine‑tuning technique that adapts large language models by learning a small set of 2×2 rotation matrices (and optional scaling factors) applied to pairs of hidden dimensions. RoAd achieves competitive or superior performance compared to other PEFT methods with under 0.1% trainable parameters. Unlike LoRA’s batched low‑rank updates, RoAd’s sparse rotations reformulate to simple element‑wise operations, yielding significantly higher serving throughput when handling heterogeneous requests in the same batch, i.e. serving multiple adapters simulatenously. Moreover, RoAd integrates seamlessly into a distributed interchange intervention framework, interpreting its sparse 2D rotations as task-specific interventions within learned subspaces of hidden representations. These orthogonal subspaces can be composed to merge multiple task-specific behaviors—like multilingual capabilities or instruction following—without additional fine-tuning, enabling modular, interpretable adaptations in LLMs.',O,h,Y="Finetuning with RoAd typically requires higher learning rate compared to LoRA or similar methods, around 1e-3. Currently RoAd only supports linear layers and it can be used on models quantized with bitsandbytes (4-bit or 8-bit).",N,c,Z='For running inference with different RoAd adapters in the same batch see <a href="../developer_guides/lora#inference-with-different-lora-adapters-in-the-same-batch">Inference with different LoRA adapters in the same batch</a>.',E,u,D,r,g,B,M,ee=`This is the configuration class to store the configuration of a <a href="/docs/peft/v0.18.0/en/package_reference/road#peft.RoadModel">RoadModel</a>. RoAd adapter is proposed in
<a href="https://huggingface.co/papers/2409.00119" rel="nofollow">https://huggingface.co/papers/2409.00119</a>.`,H,_,I,v,b,q,$,F,z,V;return p=new de({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),m=new K({props:{title:"RoAd",local:"road",headingTag:"h1"}}),u=new K({props:{title:"RoadConfig",local:"peft.RoadConfig",headingTag:"h2"}}),g=new ae({props:{name:"class peft.RoadConfig",anchor:"peft.RoadConfig",parameters:[{name:"task_type",val:": Optional[Union[str, TaskType]] = None"},{name:"peft_type",val:": Optional[Union[str, PeftType]] = None"},{name:"auto_mapping",val:": Optional[dict] = None"},{name:"peft_version",val:": Optional[str] = None"},{name:"base_model_name_or_path",val:": Optional[str] = None"},{name:"revision",val:": Optional[str] = None"},{name:"inference_mode",val:": bool = False"},{name:"variant",val:": Union[str, RoadVariant] = 'road_1'"},{name:"group_size",val:": int = 64"},{name:"init_weights",val:": bool = True"},{name:"target_modules",val:": Optional[Union[list[str], str]] = None"},{name:"modules_to_save",val:": Optional[list[str]] = None"}],parametersDescription:[{anchor:"peft.RoadConfig.variant",description:`<strong>variant</strong> (Union[<code>RoadVariant</code>, <code>str</code>]) &#x2014;
The variant of the Road model to use. It can be one of road_1, road_2, or road_4. Refer to the paper for
more details.
<ul>
<li>road_1: Uses the same scale and angle for all pairs of elements.
This variant has lowest number of parameters, it stores a number equal to the output hidden size of
parameters for each layer that RoAd is applied to.</li>
<li>road_2: Uses the same scale and angle for each element.
This variant has 2x the number of parameters compared to road_1.</li>
<li>road_4: Uses two different scales and angles for each ellement.
This variant has 4x the number of parameters compared to road_1.</li>
</ul>`,name:"variant"},{anchor:"peft.RoadConfig.group_size",description:`<strong>group_size</strong> (<code>int</code>) &#x2014;
Group size defines how elements are grouped together into 2D vectors for rotation. Within each group
element 0 is paired with element group_size/2, then element 1 is paired with element group_size/2+1 and so
on. This has no effect on the model performance, since elements are unordered, however it has some effect
on inference speed when used in e.g. VLLM. For best speed group size of at least 32 or 64 (the default) is
recommended. Note that model hidden size (or hidden size per partition when used with tensor parallelism)
must be divisible by group_size, so for very small models you might need to reduce this parameter.`,name:"group_size"},{anchor:"peft.RoadConfig.init_weights",description:`<strong>init_weights</strong> (<code>bool</code>) &#x2014;
Whether to perform initialization of RoAd weights.`,name:"init_weights"},{anchor:"peft.RoadConfig.target_modules",description:`<strong>target_modules</strong> (<code>Optional[Union[List[str], str]]</code>) &#x2014;
The names of the modules to apply the adapter to. If this is specified, only the modules with the specified
names will be replaced. When passing a string, a regex match will be performed. When passing a list of
strings, either an exact match will be performed or it is checked if the name of the module ends with any
of the passed strings. If this is specified as &#x2018;all-linear&#x2019;, then all linear/Conv1D modules are chosen (if
the model is a PreTrainedModel, the output layer excluded). If this is not specified, modules will be
chosen according to the model architecture. If the architecture is not known, an error will be raised &#x2014; in
this case, you should specify the target modules manually.`,name:"target_modules"},{anchor:"peft.RoadConfig.modules_to_save",description:`<strong>modules_to_save</strong> (<code>List[str]</code>) &#x2014;
List of modules apart from Road layers to be set as trainable and saved in the final checkpoint.`,name:"modules_to_save"}],source:"https://github.com/huggingface/peft/blob/v0.18.0/src/peft/tuners/road/config.py#L28"}}),_=new K({props:{title:"RoadModel",local:"peft.RoadModel",headingTag:"h2"}}),b=new ae({props:{name:"class peft.RoadModel",anchor:"peft.RoadModel",parameters:[{name:"model",val:""},{name:"peft_config",val:": Union[PeftConfig, dict[str, PeftConfig]]"},{name:"adapter_name",val:": str"},{name:"low_cpu_mem_usage",val:": bool = False"},{name:"state_dict",val:": Optional[dict[str, torch.Tensor]] = None"}],source:"https://github.com/huggingface/peft/blob/v0.18.0/src/peft/tuners/road/model.py#L38"}}),$=new pe({props:{source:"https://github.com/huggingface/peft/blob/main/docs/source/package_reference/road.md"}}),{c(){s=l("meta"),A=o(),L=l("p"),k=o(),w(p.$$.fragment),P=o(),w(m.$$.fragment),U=o(),f=l("p"),f.innerHTML=X,O=o(),h=l("p"),h.textContent=Y,N=o(),c=l("p"),c.innerHTML=Z,E=o(),w(u.$$.fragment),D=o(),r=l("div"),w(g.$$.fragment),B=o(),M=l("p"),M.innerHTML=ee,H=o(),w(_.$$.fragment),I=o(),v=l("div"),w(b.$$.fragment),q=o(),w($.$$.fragment),F=o(),z=l("p"),this.h()},l(e){const t=le("svelte-u9bgzb",document.head);s=d(t,"META",{name:!0,content:!0}),t.forEach(a),A=i(e),L=d(e,"P",{}),W(L).forEach(a),k=i(e),R(p.$$.fragment,e),P=i(e),R(m.$$.fragment,e),U=i(e),f=d(e,"P",{"data-svelte-h":!0}),j(f)!=="svelte-1vvf1a9"&&(f.innerHTML=X),O=i(e),h=d(e,"P",{"data-svelte-h":!0}),j(h)!=="svelte-15mje69"&&(h.textContent=Y),N=i(e),c=d(e,"P",{"data-svelte-h":!0}),j(c)!=="svelte-1x12tsl"&&(c.innerHTML=Z),E=i(e),R(u.$$.fragment,e),D=i(e),r=d(e,"DIV",{class:!0});var S=W(r);R(g.$$.fragment,S),B=i(S),M=d(S,"P",{"data-svelte-h":!0}),j(M)!=="svelte-pz5kac"&&(M.innerHTML=ee),S.forEach(a),H=i(e),R(_.$$.fragment,e),I=i(e),v=d(e,"DIV",{class:!0});var te=W(v);R(b.$$.fragment,te),te.forEach(a),q=i(e),R($.$$.fragment,e),F=i(e),z=d(e,"P",{}),W(z).forEach(a),this.h()},h(){G(s,"name","hf:doc:metadata"),G(s,"content",fe),G(r,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),G(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,t){J(document.head,s),n(e,A,t),n(e,L,t),n(e,k,t),y(p,e,t),n(e,P,t),y(m,e,t),n(e,U,t),n(e,f,t),n(e,O,t),n(e,h,t),n(e,N,t),n(e,c,t),n(e,E,t),y(u,e,t),n(e,D,t),n(e,r,t),y(g,r,null),J(r,B),J(r,M),n(e,H,t),y(_,e,t),n(e,I,t),n(e,v,t),y(b,v,null),n(e,q,t),y($,e,t),n(e,F,t),n(e,z,t),V=!0},p:oe,i(e){V||(x(p.$$.fragment,e),x(m.$$.fragment,e),x(u.$$.fragment,e),x(g.$$.fragment,e),x(_.$$.fragment,e),x(b.$$.fragment,e),x($.$$.fragment,e),V=!0)},o(e){T(p.$$.fragment,e),T(m.$$.fragment,e),T(u.$$.fragment,e),T(g.$$.fragment,e),T(_.$$.fragment,e),T(b.$$.fragment,e),T($.$$.fragment,e),V=!1},d(e){e&&(a(A),a(L),a(k),a(P),a(U),a(f),a(O),a(h),a(N),a(c),a(E),a(D),a(r),a(H),a(I),a(v),a(q),a(F),a(z)),a(s),C(p,e),C(m,e),C(u,e),C(g),C(_,e),C(b),C($,e)}}}const fe='{"title":"RoAd","local":"road","sections":[{"title":"RoadConfig","local":"peft.RoadConfig","sections":[],"depth":2},{"title":"RoadModel","local":"peft.RoadModel","sections":[],"depth":2}],"depth":1}';function he(Q){return ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ve extends se{constructor(s){super(),re(this,s,he,me,ne,{})}}export{ve as component};
