import{s as xt,n as Gt,o as wt}from"../chunks/scheduler.8a2cc2fa.js";import{S as zt,i as Tt,e as s,s as a,c as d,h as kt,a as r,d as e,b as o,f as D,g as l,j as B,k as S,l as m,m as i,n as p,t as c,o as b,p as _}from"../chunks/index.7079e750.js";import{C as Ct,H as pt,E as Nt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.ac36d8ed.js";import{D as W}from"../chunks/Docstring.c96e8772.js";function Et(ft){let g,O,M,R,x,U,G,J,w,vt="Stochastic gradient descent (SGD) is a basic gradient descent optimizer to minimize loss given a set of model parameters and updates the parameters in the opposite direction of the gradient. The update is performed on a randomly sampled mini-batch of data from the dataset.",K,z,yt="bitsandbytes also supports momentum and Nesterov momentum to accelerate SGD by adding a weighted average of past gradients to the current gradient.",Q,T,X,u,k,ct,v,C,bt,q,$t="Base SGD optimizer.",Y,N,Z,h,E,_t,y,P,gt,I,Dt="8-bit SGD optimizer.",tt,F,et,f,L,ut,$,j,ht,V,St="32-bit SGD optimizer.",nt,A,it,H,at;return x=new Ct({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),G=new pt({props:{title:"SGD",local:"sgd",headingTag:"h1"}}),T=new pt({props:{title:"SGD",local:"api-class ][ bitsandbytes.optim.SGD",headingTag:"h2"}}),k=new W({props:{name:"class bitsandbytes.optim.SGD",anchor:"bitsandbytes.optim.SGD",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"optim_bits",val:" = 32"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L8"}}),C=new W({props:{name:"__init__",anchor:"bitsandbytes.optim.SGD.__init__",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"optim_bits",val:" = 32"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],parametersDescription:[{anchor:"bitsandbytes.optim.SGD.__init__.params",description:`<strong>params</strong> (<code>torch.tensor</code>) &#x2014;
The input parameters to optimize.`,name:"params"},{anchor:"bitsandbytes.optim.SGD.__init__.lr",description:`<strong>lr</strong> (<code>float</code>) &#x2014;
The learning rate.`,name:"lr"},{anchor:"bitsandbytes.optim.SGD.__init__.momentum",description:`<strong>momentum</strong> (<code>float</code>, defaults to 0) &#x2014;
The momentum value speeds up the optimizer by taking bigger steps.`,name:"momentum"},{anchor:"bitsandbytes.optim.SGD.__init__.dampening",description:`<strong>dampening</strong> (<code>float</code>, defaults to 0) &#x2014;
The dampening value reduces the momentum of the optimizer.`,name:"dampening"},{anchor:"bitsandbytes.optim.SGD.__init__.weight_decay",description:`<strong>weight_decay</strong> (<code>float</code>, defaults to 0.0) &#x2014;
The weight decay value for the optimizer.`,name:"weight_decay"},{anchor:"bitsandbytes.optim.SGD.__init__.nesterov",description:`<strong>nesterov</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use Nesterov momentum.`,name:"nesterov"},{anchor:"bitsandbytes.optim.SGD.__init__.optim_bits",description:`<strong>optim_bits</strong> (<code>int</code>, defaults to 32) &#x2014;
The number of bits of the optimizer state.`,name:"optim_bits"},{anchor:"bitsandbytes.optim.SGD.__init__.args",description:`<strong>args</strong> (<code>object</code>, defaults to <code>None</code>) &#x2014;
An object with additional arguments.`,name:"args"},{anchor:"bitsandbytes.optim.SGD.__init__.min_8bit_size",description:`<strong>min_8bit_size</strong> (<code>int</code>, defaults to 4096) &#x2014;
The minimum number of elements of the parameter tensors for 8-bit optimization.`,name:"min_8bit_size"},{anchor:"bitsandbytes.optim.SGD.__init__.percentile_clipping",description:`<strong>percentile_clipping</strong> (<code>int</code>, defaults to 100) &#x2014;
Adapts clipping threshold automatically by tracking the last 100 gradient norms and clipping the gradient at a certain percentile to improve stability.`,name:"percentile_clipping"},{anchor:"bitsandbytes.optim.SGD.__init__.block_wise",description:`<strong>block_wise</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether to independently quantize each block of tensors to reduce outlier effects and improve stability.`,name:"block_wise"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L9"}}),N=new pt({props:{title:"SGD8bit",local:"bitsandbytes.optim.SGD8bit",headingTag:"h2"}}),E=new W({props:{name:"class bitsandbytes.optim.SGD8bit",anchor:"bitsandbytes.optim.SGD8bit",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L67"}}),P=new W({props:{name:"__init__",anchor:"bitsandbytes.optim.SGD8bit.__init__",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],parametersDescription:[{anchor:"bitsandbytes.optim.SGD8bit.__init__.params",description:`<strong>params</strong> (<code>torch.tensor</code>) &#x2014;
The input parameters to optimize.`,name:"params"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.lr",description:`<strong>lr</strong> (<code>float</code>) &#x2014;
The learning rate.`,name:"lr"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.momentum",description:`<strong>momentum</strong> (<code>float</code>, defaults to 0) &#x2014;
The momentum value speeds up the optimizer by taking bigger steps.`,name:"momentum"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.dampening",description:`<strong>dampening</strong> (<code>float</code>, defaults to 0) &#x2014;
The dampening value reduces the momentum of the optimizer.`,name:"dampening"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.weight_decay",description:`<strong>weight_decay</strong> (<code>float</code>, defaults to 0.0) &#x2014;
The weight decay value for the optimizer.`,name:"weight_decay"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.nesterov",description:`<strong>nesterov</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use Nesterov momentum.`,name:"nesterov"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.args",description:`<strong>args</strong> (<code>object</code>, defaults to <code>None</code>) &#x2014;
An object with additional arguments.`,name:"args"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.min_8bit_size",description:`<strong>min_8bit_size</strong> (<code>int</code>, defaults to 4096) &#x2014;
The minimum number of elements of the parameter tensors for 8-bit optimization.`,name:"min_8bit_size"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.percentile_clipping",description:`<strong>percentile_clipping</strong> (<code>int</code>, defaults to 100) &#x2014;
Adapts clipping threshold automatically by tracking the last 100 gradient norms and clipping the gradient at a certain percentile to improve stability.`,name:"percentile_clipping"},{anchor:"bitsandbytes.optim.SGD8bit.__init__.block_wise",description:`<strong>block_wise</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether to independently quantize each block of tensors to reduce outlier effects and improve stability.`,name:"block_wise"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L68"}}),F=new pt({props:{title:"SGD32bit",local:"bitsandbytes.optim.SGD32bit",headingTag:"h2"}}),L=new W({props:{name:"class bitsandbytes.optim.SGD32bit",anchor:"bitsandbytes.optim.SGD32bit",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L123"}}),j=new W({props:{name:"__init__",anchor:"bitsandbytes.optim.SGD32bit.__init__",parameters:[{name:"params",val:""},{name:"lr",val:""},{name:"momentum",val:" = 0"},{name:"dampening",val:" = 0"},{name:"weight_decay",val:" = 0"},{name:"nesterov",val:" = False"},{name:"args",val:" = None"},{name:"min_8bit_size",val:" = 4096"},{name:"percentile_clipping",val:" = 100"},{name:"block_wise",val:" = True"}],parametersDescription:[{anchor:"bitsandbytes.optim.SGD32bit.__init__.params",description:`<strong>params</strong> (<code>torch.tensor</code>) &#x2014;
The input parameters to optimize.`,name:"params"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.lr",description:`<strong>lr</strong> (<code>float</code>) &#x2014;
The learning rate.`,name:"lr"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.momentum",description:`<strong>momentum</strong> (<code>float</code>, defaults to 0) &#x2014;
The momentum value speeds up the optimizer by taking bigger steps.`,name:"momentum"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.dampening",description:`<strong>dampening</strong> (<code>float</code>, defaults to 0) &#x2014;
The dampening value reduces the momentum of the optimizer.`,name:"dampening"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.weight_decay",description:`<strong>weight_decay</strong> (<code>float</code>, defaults to 0.0) &#x2014;
The weight decay value for the optimizer.`,name:"weight_decay"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.nesterov",description:`<strong>nesterov</strong> (<code>bool</code>, defaults to <code>False</code>) &#x2014;
Whether to use Nesterov momentum.`,name:"nesterov"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.args",description:`<strong>args</strong> (<code>object</code>, defaults to <code>None</code>) &#x2014;
An object with additional arguments.`,name:"args"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.min_8bit_size",description:`<strong>min_8bit_size</strong> (<code>int</code>, defaults to 4096) &#x2014;
The minimum number of elements of the parameter tensors for 8-bit optimization.`,name:"min_8bit_size"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.percentile_clipping",description:`<strong>percentile_clipping</strong> (<code>int</code>, defaults to 100) &#x2014;
Adapts clipping threshold automatically by tracking the last 100 gradient norms and clipping the gradient at a certain percentile to improve stability.`,name:"percentile_clipping"},{anchor:"bitsandbytes.optim.SGD32bit.__init__.block_wise",description:`<strong>block_wise</strong> (<code>bool</code>, defaults to <code>True</code>) &#x2014;
Whether to independently quantize each block of tensors to reduce outlier effects and improve stability.`,name:"block_wise"}],source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/bitsandbytes/optim/sgd.py#L124"}}),A=new Nt({props:{source:"https://github.com/bitsandbytes-foundation/bitsandbytes/blob/main/docs/source/reference/optim/sgd.mdx"}}),{c(){g=s("meta"),O=a(),M=s("p"),R=a(),d(x.$$.fragment),U=a(),d(G.$$.fragment),J=a(),w=s("p"),w.textContent=vt,K=a(),z=s("p"),z.textContent=yt,Q=a(),d(T.$$.fragment),X=a(),u=s("div"),d(k.$$.fragment),ct=a(),v=s("div"),d(C.$$.fragment),bt=a(),q=s("p"),q.textContent=$t,Y=a(),d(N.$$.fragment),Z=a(),h=s("div"),d(E.$$.fragment),_t=a(),y=s("div"),d(P.$$.fragment),gt=a(),I=s("p"),I.textContent=Dt,tt=a(),d(F.$$.fragment),et=a(),f=s("div"),d(L.$$.fragment),ut=a(),$=s("div"),d(j.$$.fragment),ht=a(),V=s("p"),V.textContent=St,nt=a(),d(A.$$.fragment),it=a(),H=s("p"),this.h()},l(t){const n=kt("svelte-u9bgzb",document.head);g=r(n,"META",{name:!0,content:!0}),n.forEach(e),O=o(t),M=r(t,"P",{}),D(M).forEach(e),R=o(t),l(x.$$.fragment,t),U=o(t),l(G.$$.fragment,t),J=o(t),w=r(t,"P",{"data-svelte-h":!0}),B(w)!=="svelte-q53bao"&&(w.textContent=vt),K=o(t),z=r(t,"P",{"data-svelte-h":!0}),B(z)!=="svelte-xtlqke"&&(z.textContent=yt),Q=o(t),l(T.$$.fragment,t),X=o(t),u=r(t,"DIV",{class:!0});var ot=D(u);l(k.$$.fragment,ot),ct=o(ot),v=r(ot,"DIV",{class:!0});var st=D(v);l(C.$$.fragment,st),bt=o(st),q=r(st,"P",{"data-svelte-h":!0}),B(q)!=="svelte-1r01lii"&&(q.textContent=$t),st.forEach(e),ot.forEach(e),Y=o(t),l(N.$$.fragment,t),Z=o(t),h=r(t,"DIV",{class:!0});var rt=D(h);l(E.$$.fragment,rt),_t=o(rt),y=r(rt,"DIV",{class:!0});var mt=D(y);l(P.$$.fragment,mt),gt=o(mt),I=r(mt,"P",{"data-svelte-h":!0}),B(I)!=="svelte-utr5h5"&&(I.textContent=Dt),mt.forEach(e),rt.forEach(e),tt=o(t),l(F.$$.fragment,t),et=o(t),f=r(t,"DIV",{class:!0});var dt=D(f);l(L.$$.fragment,dt),ut=o(dt),$=r(dt,"DIV",{class:!0});var lt=D($);l(j.$$.fragment,lt),ht=o(lt),V=r(lt,"P",{"data-svelte-h":!0}),B(V)!=="svelte-wdls4c"&&(V.textContent=St),lt.forEach(e),dt.forEach(e),nt=o(t),l(A.$$.fragment,t),it=o(t),H=r(t,"P",{}),D(H).forEach(e),this.h()},h(){S(g,"name","hf:doc:metadata"),S(g,"content",Pt),S(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S(u,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S(y,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S(h,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),S(f,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(t,n){m(document.head,g),i(t,O,n),i(t,M,n),i(t,R,n),p(x,t,n),i(t,U,n),p(G,t,n),i(t,J,n),i(t,w,n),i(t,K,n),i(t,z,n),i(t,Q,n),p(T,t,n),i(t,X,n),i(t,u,n),p(k,u,null),m(u,ct),m(u,v),p(C,v,null),m(v,bt),m(v,q),i(t,Y,n),p(N,t,n),i(t,Z,n),i(t,h,n),p(E,h,null),m(h,_t),m(h,y),p(P,y,null),m(y,gt),m(y,I),i(t,tt,n),p(F,t,n),i(t,et,n),i(t,f,n),p(L,f,null),m(f,ut),m(f,$),p(j,$,null),m($,ht),m($,V),i(t,nt,n),p(A,t,n),i(t,it,n),i(t,H,n),at=!0},p:Gt,i(t){at||(c(x.$$.fragment,t),c(G.$$.fragment,t),c(T.$$.fragment,t),c(k.$$.fragment,t),c(C.$$.fragment,t),c(N.$$.fragment,t),c(E.$$.fragment,t),c(P.$$.fragment,t),c(F.$$.fragment,t),c(L.$$.fragment,t),c(j.$$.fragment,t),c(A.$$.fragment,t),at=!0)},o(t){b(x.$$.fragment,t),b(G.$$.fragment,t),b(T.$$.fragment,t),b(k.$$.fragment,t),b(C.$$.fragment,t),b(N.$$.fragment,t),b(E.$$.fragment,t),b(P.$$.fragment,t),b(F.$$.fragment,t),b(L.$$.fragment,t),b(j.$$.fragment,t),b(A.$$.fragment,t),at=!1},d(t){t&&(e(O),e(M),e(R),e(U),e(J),e(w),e(K),e(z),e(Q),e(X),e(u),e(Y),e(Z),e(h),e(tt),e(et),e(f),e(nt),e(it),e(H)),e(g),_(x,t),_(G,t),_(T,t),_(k),_(C),_(N,t),_(E),_(P),_(F,t),_(L),_(j),_(A,t)}}}const Pt='{"title":"SGD","local":"sgd","sections":[{"title":"SGD","local":"api-class ][ bitsandbytes.optim.SGD","sections":[],"depth":2},{"title":"SGD8bit","local":"bitsandbytes.optim.SGD8bit","sections":[],"depth":2},{"title":"SGD32bit","local":"bitsandbytes.optim.SGD32bit","sections":[],"depth":2}],"depth":1}';function Ft(ft){return wt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class It extends zt{constructor(g){super(),Tt(this,g,Ft,Et,xt,{})}}export{It as component};
