import{S as Nr,i as Hr,s as Ir,e as p,k as i,t as a,w as f,M as Rr,c as n,d as t,m as d,a as c,h as l,x as m,b as y,G as s,g as r,y as u,q as _,o as h,B as $,v as Br}from"../../chunks/vendor-hf-doc-builder.js";import{T as Mr}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Fr}from"../../chunks/Youtube-hf-doc-builder.js";import{I as Jr}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as k}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Yr}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Qr(Ge){let b,z,q,le,I;return{c(){b=p("p"),z=a("\u270F\uFE0F "),q=p("strong"),le=a("\u8BD5\u8BD5\u770B\uFF01"),I=a(" \u4FEE\u6539\u4E4B\u524D\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4EE5\u5728 SST-2 \u6570\u636E\u96C6\u4E0A\u5FAE\u8C03\u60A8\u7684\u6A21\u578B\u3002")},l(D){b=n(D,"P",{});var S=c(b);z=l(S,"\u270F\uFE0F "),q=n(S,"STRONG",{});var U=c(q);le=l(U,"\u8BD5\u8BD5\u770B\uFF01"),U.forEach(t),I=l(S," \u4FEE\u6539\u4E4B\u524D\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4EE5\u5728 SST-2 \u6570\u636E\u96C6\u4E0A\u5FAE\u8C03\u60A8\u7684\u6A21\u578B\u3002"),S.forEach(t)},m(D,S){r(D,b,S),s(b,z),s(b,q),s(q,le),s(b,I)},d(D){D&&t(b)}}}function Kr(Ge){let b;return{c(){b=a("\u26A0\uFE0F \u4E3A\u4E86\u4F7F\u4E91\u7AEF TPU \u63D0\u4F9B\u7684\u52A0\u901F\u53D1\u6325\u6700\u5927\u7684\u6548\u76CA\uFF0C\u6211\u4EEC\u5EFA\u8BAE\u4F7F\u7528\u6807\u8BB0\u5668(tokenizer)\u7684 `padding=max_length` \u548C `max_length` \u53C2\u6570\u5C06\u60A8\u7684\u6837\u672C\u586B\u5145\u5230\u56FA\u5B9A\u957F\u5EA6\u3002")},l(z){b=l(z,"\u26A0\uFE0F \u4E3A\u4E86\u4F7F\u4E91\u7AEF TPU \u63D0\u4F9B\u7684\u52A0\u901F\u53D1\u6325\u6700\u5927\u7684\u6548\u76CA\uFF0C\u6211\u4EEC\u5EFA\u8BAE\u4F7F\u7528\u6807\u8BB0\u5668(tokenizer)\u7684 `padding=max_length` \u548C `max_length` \u53C2\u6570\u5C06\u60A8\u7684\u6837\u672C\u586B\u5145\u5230\u56FA\u5B9A\u957F\u5EA6\u3002")},m(z,q){r(z,b,q)},d(z){z&&t(b)}}}function Vr(Ge){let b,z,q,le,I,D,S,U,Js,R,ra,Ze,pa,na,Ys,oe,Qs,re,ca,Ks,G,ia,es,da,fa,ss,ma,ua,Vs,L,N,_a,ts,ha,$a,as,ba,ka,va,T,ja,ls,Ea,wa,os,ya,qa,rs,za,ga,Ca,ps,Da,Xs,B,Pa,ns,Aa,Oa,Zs,pe,et,Le,xa,st,ne,tt,We,Sa,at,ce,lt,Me,Ta,ot,ie,rt,de,pt,W,Ua,cs,Ga,La,is,Wa,Ma,nt,Fe,Fa,ct,fe,it,J,Na,ds,Ha,Ia,dt,me,ft,ue,mt,j,Ra,fs,Ba,Ja,ms,Ya,Qa,us,Ka,Va,_s,Xa,Za,hs,el,sl,ut,E,tl,$s,al,ll,bs,ol,rl,ks,pl,nl,vs,cl,il,_e,dl,fl,_t,he,ht,M,ml,js,ul,_l,Es,hl,$l,$t,$e,bt,be,kt,ke,bl,vt,P,kl,ws,vl,jl,ys,El,wl,qs,yl,ql,jt,ve,Et,je,wt,Y,zl,zs,gl,Cl,yt,Ee,qt,Ne,Dl,zt,we,Pl,gt,w,Al,gs,Ol,xl,Cs,Sl,Tl,Ds,Ul,Gl,Ps,Ll,Wl,As,Ml,Fl,Ct,ye,Dt,qe,Pt,He,Nl,At,Q,Ot,H,K,Os,ze,Hl,xs,Il,xt,ge,St,V,Rl,Ce,Bl,Jl,Tt,De,Ut,Ie,Yl,Gt,Pe,Lt,g,Ql,Ss,Kl,Vl,Ts,Xl,Zl,Us,eo,so,Gs,to,ao,Wt,v,lo,Ls,oo,ro,Ws,po,no,Ms,co,io,Fs,fo,mo,Ns,uo,_o,Hs,ho,$o,Mt,X,Ft,Re,bo,Nt,Ae,Ht,Z,ko,Is,vo,jo,It,Oe,Rt,Be,Eo,Bt,xe,Jt,Je,wo,Yt,ee,yo,Rs,qo,zo,Qt,Se,Kt,se,go,Te,Co,Do,Vt;return D=new Yr({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter3/section4.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter3/section4.ipynb"}]}}),U=new Fr({props:{id:"Dh9CL8fyG80"}}),oe=new k({props:{code:`



`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, DataCollatorWithPadding

raw_datasets = load_dataset(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)


<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">example</span>):
    <span class="hljs-keyword">return</span> tokenizer(example[<span class="hljs-string">&quot;sentence1&quot;</span>], example[<span class="hljs-string">&quot;sentence2&quot;</span>], truncation=<span class="hljs-literal">True</span>)


tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)
data_collator = DataCollatorWithPadding(tokenizer=tokenizer)`}}),pe=new k({props:{code:`tokenized_datasets = tokenized_datasets.remove_columns(["sentence1", "sentence2", "idx"])
tokenized_datasets = tokenized_datasets.rename_column("label", "labels")
tokenized_datasets.set_format("torch")
tokenized_datasets["train"].column_names`,highlighted:`tokenized_datasets = tokenized_datasets.remove_columns([<span class="hljs-string">&quot;sentence1&quot;</span>, <span class="hljs-string">&quot;sentence2&quot;</span>, <span class="hljs-string">&quot;idx&quot;</span>])
tokenized_datasets = tokenized_datasets.rename_column(<span class="hljs-string">&quot;label&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>)
tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)
tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names`}}),ne=new k({props:{code:'["attention_mask", "input_ids", "labels", "token_type_ids"]',highlighted:'[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>]'}}),ce=new k({props:{code:"",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

train_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>], shuffle=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">8</span>, collate_fn=data_collator
)
eval_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], batch_size=<span class="hljs-number">8</span>, collate_fn=data_collator
)`}}),ie=new k({props:{code:`for batch in train_dataloader:
    break
{k: v.shape for k, v in batch.items()}`,highlighted:`<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
    <span class="hljs-keyword">break</span>
{k: v.shape <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}`}}),de=new k({props:{code:`{'attention_mask': torch.Size([8, 65]),
 'input_ids': torch.Size([8, 65]),
 'labels': torch.Size([8]),
 'token_type_ids': torch.Size([8, 65])}`,highlighted:`{<span class="hljs-string">&#x27;attention_mask&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>]),
 <span class="hljs-string">&#x27;input_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>]),
 <span class="hljs-string">&#x27;labels&#x27;</span>: torch.Size([<span class="hljs-number">8</span>]),
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">65</span>])}`}}),fe=new k({props:{code:"",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)`}}),me=new k({props:{code:`outputs = model(**batch)
print(outputs.loss, outputs.logits.shape)`,highlighted:`outputs = model(**batch)
<span class="hljs-built_in">print</span>(outputs.loss, outputs.logits.shape)`}}),ue=new k({props:{code:"tensor(0.5441, grad_fn=<NllLossBackward>) torch.Size([8, 2])",highlighted:'tensor(<span class="hljs-number">0.5441</span>, grad_fn=&lt;NllLossBackward&gt;) torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">2</span>])'}}),he=new k({props:{code:"",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">5e-5</span>)`}}),$e=new k({props:{code:"",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dataloader)
lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)
<span class="hljs-built_in">print</span>(num_training_steps)`}}),be=new k({props:{code:"1377",highlighted:'<span class="hljs-number">1377</span>'}}),ve=new k({props:{code:"",highlighted:`<span class="hljs-keyword">import</span> torch

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
model.to(device)
device`}}),je=new k({props:{code:"device(type='cuda')",highlighted:'device(<span class="hljs-built_in">type</span>=<span class="hljs-string">&#x27;cuda&#x27;</span>)'}}),Ee=new k({props:{code:`

`,highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
        batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
        outputs = model(**batch)
        loss = outputs.loss
        loss.backward()

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)`}}),ye=new k({props:{code:`

`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

metric = load_metric(<span class="hljs-string">&quot;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
model.<span class="hljs-built_in">eval</span>()
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
    batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
    <span class="hljs-keyword">with</span> torch.no_grad():
        outputs = model(**batch)

    logits = outputs.logits
    predictions = torch.argmax(logits, dim=-<span class="hljs-number">1</span>)
    metric.add_batch(predictions=predictions, references=batch[<span class="hljs-string">&quot;labels&quot;</span>])

metric.compute()`}}),qe=new k({props:{code:"{'accuracy': 0.8431372549019608, 'f1': 0.8907849829351535}",highlighted:'{<span class="hljs-string">&#x27;accuracy&#x27;</span>: <span class="hljs-number">0.8431372549019608</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.8907849829351535</span>}'}}),Q=new Mr({props:{$$slots:{default:[Qr]},$$scope:{ctx:Ge}}}),ze=new Jr({}),ge=new Fr({props:{id:"s7dy8QRgjJ0"}}),De=new k({props:{code:`




`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW, AutoModelForSequenceClassification, get_scheduler

model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">3e-5</span>)

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
model.to(device)

num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dataloader)
lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
        batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
        outputs = model(**batch)
        loss = outputs.loss
        loss.backward()

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)`}}),Pe=new k({props:{code:`






`,highlighted:`<span class="hljs-addition">+ from accelerate import Accelerator</span>
  from transformers import AdamW, AutoModelForSequenceClassification, get_scheduler

<span class="hljs-addition">+ accelerator = Accelerator()</span>

  model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
  optimizer = AdamW(model.parameters(), lr=3e-5)

<span class="hljs-deletion">- device = torch.device(&quot;cuda&quot;) if torch.cuda.is_available() else torch.device(&quot;cpu&quot;)</span>
<span class="hljs-deletion">- model.to(device)</span>

<span class="hljs-addition">+ train_dataloader, eval_dataloader, model, optimizer = accelerator.prepare(</span>
<span class="hljs-addition">+     train_dataloader, eval_dataloader, model, optimizer</span>
<span class="hljs-addition">+ )</span>

  num_epochs = 3
  num_training_steps = num_epochs * len(train_dataloader)
  lr_scheduler = get_scheduler(
      &quot;linear&quot;,
      optimizer=optimizer,
      num_warmup_steps=0,
      num_training_steps=num_training_steps
  )

  progress_bar = tqdm(range(num_training_steps))

  model.train()
  for epoch in range(num_epochs):
      for batch in train_dataloader:
<span class="hljs-deletion">-         batch = {k: v.to(device) for k, v in batch.items()}</span>
          outputs = model(**batch)
          loss = outputs.loss
<span class="hljs-deletion">-         loss.backward()</span>
<span class="hljs-addition">+         accelerator.backward(loss)</span>

          optimizer.step()
          lr_scheduler.step()
          optimizer.zero_grad()
          progress_bar.update(1)`}}),X=new Mr({props:{$$slots:{default:[Kr]},$$scope:{ctx:Ge}}}),Ae=new k({props:{code:`





`,highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW, AutoModelForSequenceClassification, get_scheduler

accelerator = Accelerator()

model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=<span class="hljs-number">2</span>)
optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">3e-5</span>)

train_dl, eval_dl, model, optimizer = accelerator.prepare(
    train_dataloader, eval_dataloader, model, optimizer
)

num_epochs = <span class="hljs-number">3</span>
num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dl)
lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

model.train()
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dl:
        outputs = model(**batch)
        loss = outputs.loss
        accelerator.backward(loss)

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)`}}),Oe=new k({props:{code:"accelerate config",highlighted:"accelerate config"}}),xe=new k({props:{code:"accelerate launch train.py",highlighted:'accelerate <span class="hljs-built_in">launch</span> train.py'}}),Se=new k({props:{code:"",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> notebook_launcher

notebook_launcher(training_function)`}}),{c(){b=p("meta"),z=i(),q=p("h1"),le=a("\u4E00\u4E2A\u5B8C\u6574\u7684\u8BAD\u7EC3"),I=i(),f(D.$$.fragment),S=i(),f(U.$$.fragment),Js=i(),R=p("p"),ra=a("\u73B0\u5728\uFF0C\u6211\u4EEC\u5C06\u4E86\u89E3\u5982\u4F55\u5728\u4E0D\u4F7F\u7528"),Ze=p("code"),pa=a("Trainer"),na=a("\u7C7B\u7684\u60C5\u51B5\u4E0B\u83B7\u5F97\u4E0E\u4E0A\u4E00\u8282\u76F8\u540C\u7684\u7ED3\u679C\u3002\u540C\u6837\uFF0C\u6211\u4EEC\u5047\u8BBE\u60A8\u5DF2\u7ECF\u5B66\u4E60\u4E86\u7B2C 2 \u8282\u4E2D\u7684\u6570\u636E\u5904\u7406\u3002\u4E0B\u9762\u662F\u4E00\u4E2A\u7B80\u77ED\u7684\u603B\u7ED3\uFF0C\u6DB5\u76D6\u4E86\u60A8\u9700\u8981\u7684\u6240\u6709\u5185\u5BB9:"),Ys=i(),f(oe.$$.fragment),Qs=i(),re=p("h3"),ca=a("\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"),Ks=i(),G=p("p"),ia=a("\u5728\u5B9E\u9645\u7F16\u5199\u6211\u4EEC\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5B9A\u4E49\u4E00\u4E9B\u5BF9\u8C61\u3002\u7B2C\u4E00\u4E2A\u662F\u6211\u4EEC\u5C06\u7528\u4E8E\u8FED\u4EE3\u6279\u6B21\u7684\u6570\u636E\u52A0\u8F7D\u5668\u3002\u6211\u4EEC\u9700\u8981\u5BF9\u6211\u4EEC\u7684"),es=p("code"),da=a("tokenized_datasets"),fa=a("\u505A\u4E00\u4E9B\u5904\u7406\uFF0C\u6765\u5904\u7406"),ss=p("code"),ma=a("Trainer"),ua=a("\u81EA\u52A8\u4E3A\u6211\u4EEC\u505A\u7684\u4E00\u4E9B\u4E8B\u60C5\u3002\u5177\u4F53\u6765\u8BF4\uFF0C\u6211\u4EEC\u9700\u8981:"),Vs=i(),L=p("ul"),N=p("li"),_a=a("\u5220\u9664\u4E0E\u6A21\u578B\u4E0D\u671F\u671B\u7684\u503C\u76F8\u5BF9\u5E94\u7684\u5217\uFF08\u5982"),ts=p("code"),ha=a("sentence1"),$a=a("\u548C"),as=p("code"),ba=a("sentence2"),ka=a("\u5217\uFF09\u3002"),va=i(),T=p("li"),ja=a("\u5C06\u5217\u540D"),ls=p("code"),Ea=a("label"),wa=a("\u91CD\u547D\u540D\u4E3A"),os=p("code"),ya=a("labels"),qa=a("\uFF08\u56E0\u4E3A\u6A21\u578B\u671F\u671B\u53C2\u6570\u662F"),rs=p("code"),za=a("labels"),ga=a("\uFF09\u3002"),Ca=i(),ps=p("li"),Da=a("\u8BBE\u7F6E\u6570\u636E\u96C6\u7684\u683C\u5F0F\uFF0C\u4F7F\u5176\u8FD4\u56DE PyTorch \u5F20\u91CF\u800C\u4E0D\u662F\u5217\u8868\u3002"),Xs=i(),B=p("p"),Pa=a("\u9488\u5BF9\u4E0A\u9762\u7684\u6BCF\u4E2A\u6B65\u9AA4\uFF0C\u6211\u4EEC\u7684 "),ns=p("code"),Aa=a("tokenized_datasets"),Oa=a(" \u90FD\u6709\u4E00\u4E2A\u65B9\u6CD5:"),Zs=i(),f(pe.$$.fragment),et=i(),Le=p("p"),xa=a("\u7136\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u68C0\u67E5\u7ED3\u679C\u4E2D\u662F\u5426\u53EA\u6709\u6A21\u578B\u80FD\u591F\u63A5\u53D7\u7684\u5217:"),st=i(),f(ne.$$.fragment),tt=i(),We=p("p"),Sa=a("\u81F3\u6B64\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u5B9A\u4E49\u6570\u636E\u52A0\u8F7D\u5668:"),at=i(),f(ce.$$.fragment),lt=i(),Me=p("p"),Ta=a("\u4E3A\u4E86\u5FEB\u901F\u68C0\u9A8C\u6570\u636E\u5904\u7406\u4E2D\u6CA1\u6709\u9519\u8BEF\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8FD9\u6837\u68C0\u9A8C\u5176\u4E2D\u7684\u4E00\u4E2A\u6279\u6B21:"),ot=i(),f(ie.$$.fragment),rt=i(),f(de.$$.fragment),pt=i(),W=p("p"),Ua=a("\u8BF7\u6CE8\u610F\uFF0C\u5B9E\u9645\u7684\u5F62\u72B6\u53EF\u80FD\u4E0E\u60A8\u7565\u6709\u4E0D\u540C\uFF0C\u56E0\u4E3A\u6211\u4EEC\u4E3A\u8BAD\u7EC3\u6570\u636E\u52A0\u8F7D\u5668\u8BBE\u7F6E\u4E86"),cs=p("code"),Ga=a("shuffle=True"),La=a("\uFF0C\u5E76\u4E14\u6A21\u578B\u4F1A\u5C06\u53E5\u5B50\u586B\u5145\u5230"),is=p("code"),Wa=a("batch"),Ma=a("\u4E2D\u7684\u6700\u5927\u957F\u5EA6\u3002"),nt=i(),Fe=p("p"),Fa=a("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u5B8C\u5168\u5B8C\u6210\u4E86\u6570\u636E\u9884\u5904\u7406\uFF08\u5BF9\u4E8E\u4EFB\u4F55 ML \u4ECE\u4E1A\u8005\u6765\u8BF4\u90FD\u662F\u4E00\u4E2A\u4EE4\u4EBA\u6EE1\u610F\u4F46\u96BE\u4EE5\u5B9E\u73B0\u7684\u76EE\u6807\uFF09\uFF0C\u8BA9\u6211\u4EEC\u5C06\u6CE8\u610F\u529B\u8F6C\u5411\u6A21\u578B\u3002\u6211\u4EEC\u5B8C\u5168\u50CF\u5728\u4E0A\u4E00\u8282\u4E2D\u6240\u505A\u7684\u90A3\u6837\u5B9E\u4F8B\u5316\u5B83:"),ct=i(),f(fe.$$.fragment),it=i(),J=p("p"),Na=a("\u4E3A\u4E86\u786E\u4FDD\u8BAD\u7EC3\u8FC7\u7A0B\u4E2D\u4E00\u5207\u987A\u5229\uFF0C\u6211\u4EEC\u5C06"),ds=p("code"),Ha=a("batch"),Ia=a("\u4F20\u9012\u7ED9\u8FD9\u4E2A\u6A21\u578B:"),dt=i(),f(me.$$.fragment),ft=i(),f(ue.$$.fragment),mt=i(),j=p("p"),Ra=a("\u5F53\u6211\u4EEC\u63D0\u4F9B "),fs=p("code"),Ba=a("labels"),Ja=a(" \u65F6\uFF0C \u{1F917} Transformers \u6A21\u578B\u90FD\u5C06\u8FD4\u56DE\u8FD9\u4E2A"),ms=p("code"),Ya=a("batch"),Qa=a("\u7684"),us=p("code"),Ka=a("loss"),Va=a("\uFF0C\u6211\u4EEC\u8FD8\u5F97\u5230\u4E86 "),_s=p("code"),Xa=a("logits"),Za=a("("),hs=p("code"),el=a("batch"),sl=a("\u4E2D\u7684\u6BCF\u4E2A\u8F93\u5165\u6709\u4E24\u4E2A\uFF0C\u6240\u4EE5\u5F20\u91CF\u5927\u5C0F\u4E3A 8 x 2)\u3002"),ut=i(),E=p("p"),tl=a("\u6211\u4EEC\u51E0\u4E4E\u51C6\u5907\u597D\u7F16\u5199\u6211\u4EEC\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4E86\uFF01\u6211\u4EEC\u53EA\u662F\u7F3A\u5C11\u4E24\u4EF6\u4E8B\uFF1A\u4F18\u5316\u5668\u548C\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u3002\u7531\u4E8E\u6211\u4EEC\u8BD5\u56FE\u81EA\u884C\u5B9E\u73B0 "),$s=p("code"),al=a("Trainer"),ll=a("\u7684\u529F\u80FD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u76F8\u540C\u7684\u4F18\u5316\u5668\u548C\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u3002"),bs=p("code"),ol=a("Trainer"),rl=a(" \u4F7F\u7528\u7684\u4F18\u5316\u5668\u662F "),ks=p("code"),pl=a("AdamW"),nl=a(" , \u4E0E "),vs=p("code"),cl=a("Adam"),il=a(" \u76F8\u540C\uFF0C\u4F46\u5728\u6743\u91CD\u8870\u51CF\u6B63\u5219\u5316\u65B9\u9762\u6709\u6240\u4E0D\u540C(\u53C2\u89C1"),_e=p("a"),dl=a("\u201CDecoupled Weight Decay Regularization\u201D"),fl=a("\u4F5C\u8005:Ilya Loshchilov \u548C Frank Hutter):"),_t=i(),f(he.$$.fragment),ht=i(),M=p("p"),ml=a("\u6700\u540E\uFF0C\u9ED8\u8BA4\u4F7F\u7528\u7684\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u53EA\u662F\u4ECE\u6700\u5927\u503C (5e-5) \u5230 0 \u7684\u7EBF\u6027\u8870\u51CF\u3002 \u4E3A\u4E86\u5B9A\u4E49\u5B83\uFF0C\u6211\u4EEC\u9700\u8981\u77E5\u9053\u6211\u4EEC\u8BAD\u7EC3\u7684\u6B21\u6570\uFF0C\u5373\u6240\u6709\u6570\u636E\u8BAD\u7EC3\u7684\u6B21\u6570(epochs)\u4E58\u4EE5\u7684\u6570\u636E\u91CF\uFF08\u8FD9\u662F\u6211\u4EEC\u6240\u6709\u8BAD\u7EC3\u6570\u636E\u7684\u6570\u91CF\uFF09\u3002"),js=p("code"),ul=a("Trainer"),_l=a("\u9ED8\u8BA4\u60C5\u51B5\u4E0B\u4F7F\u7528\u4E09\u4E2A"),Es=p("code"),hl=a("epochs"),$l=a("\uFF0C\u56E0\u6B64\u6211\u4EEC\u5B9A\u4E49\u8BAD\u7EC3\u8FC7\u7A0B\u5982\u4E0B:"),$t=i(),f($e.$$.fragment),bt=i(),f(be.$$.fragment),kt=i(),ke=p("h3"),bl=a("\u8BAD\u7EC3\u5FAA\u73AF"),vt=i(),P=p("p"),kl=a("\u6700\u540E\u4E00\u4EF6\u4E8B\uFF1A\u5982\u679C\u6211\u4EEC\u53EF\u4EE5\u8BBF\u95EE GPU,\u6211\u4EEC\u5C06\u5E0C\u671B\u4F7F\u7528 GPU(\u5728 CPU \u4E0A\uFF0C\u8BAD\u7EC3\u53EF\u80FD\u9700\u8981\u51E0\u4E2A\u5C0F\u65F6\u800C\u4E0D\u662F\u51E0\u5206\u949F)\u3002\u4E3A\u6B64\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E86\u4E00\u4E2A "),ws=p("code"),vl=a("device"),jl=a(",\u5B83\u5728GPU\u53EF\u7528\u7684\u60C5\u51B5\u4E0B\u6307\u5411GPU \u6211\u4EEC\u5C06\u628A\u6211\u4EEC\u7684\u6A21\u578B\u548C"),ys=p("code"),El=a("batche"),wl=a("\u653E\u5728"),qs=p("code"),yl=a("device"),ql=a("\u4E0A:"),jt=i(),f(ve.$$.fragment),Et=i(),f(je.$$.fragment),wt=i(),Y=p("p"),zl=a("\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u597D\u8BAD\u7EC3\u4E86\uFF01\u4E3A\u4E86\u4E86\u89E3\u8BAD\u7EC3\u4F55\u65F6\u7ED3\u675F\uFF0C\u6211\u4EEC\u4F7F\u7528 "),zs=p("code"),gl=a("tqdm"),Cl=a(" \u5E93,\u5728\u8BAD\u7EC3\u6B65\u9AA4\u6570\u4E0A\u6DFB\u52A0\u4E86\u4E00\u4E2A\u8FDB\u5EA6\u6761:"),yt=i(),f(Ee.$$.fragment),qt=i(),Ne=p("p"),Dl=a("\u60A8\u53EF\u4EE5\u770B\u5230\u8BAD\u7EC3\u5FAA\u73AF\u7684\u6838\u5FC3\u4E0E\u4ECB\u7ECD\u4E2D\u7684\u975E\u5E38\u76F8\u4F3C\u3002\u6211\u4EEC\u6CA1\u6709\u8981\u6C42\u4EFB\u4F55\u68C0\u9A8C\uFF0C\u6240\u4EE5\u8FD9\u4E2A\u8BAD\u7EC3\u5FAA\u73AF\u4E0D\u4F1A\u544A\u8BC9\u6211\u4EEC\u4EFB\u4F55\u5173\u4E8E\u6A21\u578B\u76EE\u524D\u7684\u72B6\u6001\u3002\u6211\u4EEC\u9700\u8981\u4E3A\u6B64\u6DFB\u52A0\u4E00\u4E2A\u8BC4\u4F30\u5FAA\u73AF\u3002"),zt=i(),we=p("h3"),Pl=a("\u8BC4\u4F30\u5FAA\u73AF"),gt=i(),w=p("p"),Al=a("\u6B63\u5982\u6211\u4EEC\u4E4B\u524D\u6240\u505A\u7684\u90A3\u6837\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 \u{1F917} Datasets \u5E93\u63D0\u4F9B\u7684\u6307\u6807\u3002\u6211\u4EEC\u5DF2\u7ECF\u4E86\u89E3\u4E86 "),gs=p("code"),Ol=a("metric.compute()"),xl=a(" \u65B9\u6CD5\uFF0C\u5F53\u6211\u4EEC\u4F7F\u7528 "),Cs=p("code"),Sl=a("add_batch()"),Tl=a("\u65B9\u6CD5\u8FDB\u884C\u9884\u6D4B\u5FAA\u73AF\u65F6\uFF0C\u5B9E\u9645\u4E0A\u8BE5\u6307\u6807\u53EF\u4EE5\u4E3A\u6211\u4EEC\u7D2F\u79EF\u6240\u6709 "),Ds=p("code"),Ul=a("batch"),Gl=a(" \u7684\u7ED3\u679C\u3002\u4E00\u65E6\u6211\u4EEC\u7D2F\u79EF\u4E86\u6240\u6709 "),Ps=p("code"),Ll=a("batch"),Wl=a(" \uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u4F7F\u7528 "),As=p("code"),Ml=a("metric.compute()"),Fl=a(" \u5F97\u5230\u6700\u7EC8\u7ED3\u679C .\u4EE5\u4E0B\u662F\u5728\u8BC4\u4F30\u5FAA\u73AF\u4E2D\u5B9E\u73B0\u6240\u6709\u8FD9\u4E9B\u7684\u65B9\u6CD5:"),Ct=i(),f(ye.$$.fragment),Dt=i(),f(qe.$$.fragment),Pt=i(),He=p("p"),Nl=a("\u540C\u6837\uFF0C\u7531\u4E8E\u6A21\u578B\u5934\u90E8\u521D\u59CB\u5316\u548C\u6570\u636E\u6539\u7EC4\u7684\u968F\u673A\u6027\uFF0C\u60A8\u7684\u7ED3\u679C\u4F1A\u7565\u6709\u4E0D\u540C\uFF0C\u4F46\u5B83\u4EEC\u5E94\u8BE5\u5728\u540C\u4E00\u4E2A\u8303\u56F4\u5185\u3002"),At=i(),f(Q.$$.fragment),Ot=i(),H=p("h3"),K=p("a"),Os=p("span"),f(ze.$$.fragment),Hl=i(),xs=p("span"),Il=a("S\u4F7F\u7528\u{1F917} Accelerate\u52A0\u901F\u60A8\u7684\u8BAD\u7EC3\u5FAA\u73AF"),xt=i(),f(ge.$$.fragment),St=i(),V=p("p"),Rl=a("\u6211\u4EEC\u4E4B\u524D\u5B9A\u4E49\u7684\u8BAD\u7EC3\u5FAA\u73AF\u5728\u5355\u4E2A CPU \u6216 GPU \u4E0A\u8FD0\u884C\u826F\u597D\u3002\u4F46\u662F\u4F7F\u7528"),Ce=p("a"),Bl=a("\u{1F917} Accelerate"),Jl=a("\u5E93\uFF0C\u53EA\u9700\u8FDB\u884C\u4E00\u4E9B\u8C03\u6574\uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u5728\u591A\u4E2A GPU \u6216 TPU \u4E0A\u542F\u7528\u5206\u5E03\u5F0F\u8BAD\u7EC3\u3002\u4ECE\u521B\u5EFA\u8BAD\u7EC3\u548C\u9A8C\u8BC1\u6570\u636E\u52A0\u8F7D\u5668\u5F00\u59CB\uFF0C\u6211\u4EEC\u7684\u624B\u52A8\u8BAD\u7EC3\u5FAA\u73AF\u5982\u4E0B\u6240\u793A\uFF1A"),Tt=i(),f(De.$$.fragment),Ut=i(),Ie=p("p"),Yl=a("\u4EE5\u4E0B\u662F\u53D8\u5316:"),Gt=i(),f(Pe.$$.fragment),Lt=i(),g=p("p"),Ql=a("\u8981\u6DFB\u52A0\u7684\u7B2C\u4E00\u884C\u662F\u5BFC\u5165"),Ss=p("code"),Kl=a("Accelerator"),Vl=a("\u3002\u7B2C\u4E8C\u884C\u5B9E\u4F8B\u5316\u4E00\u4E2A "),Ts=p("code"),Xl=a("Accelerator"),Zl=a("\u5BF9\u8C61 \uFF0C\u5B83\u5C06\u67E5\u770B\u73AF\u5883\u5E76\u521D\u59CB\u5316\u9002\u5F53\u7684\u5206\u5E03\u5F0F\u8BBE\u7F6E\u3002 \u{1F917} Accelerate \u4E3A\u60A8\u5904\u7406\u6570\u636E\u5728\u8BBE\u5907\u95F4\u7684\u4F20\u9012\uFF0C\u56E0\u6B64\u60A8\u53EF\u4EE5\u5220\u9664\u5C06\u6A21\u578B\u653E\u5728\u8BBE\u5907\u4E0A\u7684\u90A3\u884C\u4EE3\u7801\uFF08\u6216\u8005\uFF0C\u5982\u679C\u60A8\u613F\u610F\uFF0C\u53EF\u4F7F\u7528 "),Us=p("code"),eo=a("accelerator.device"),so=a(" \u4EE3\u66FF "),Gs=p("code"),to=a("device"),ao=a(" \uFF09\u3002"),Wt=i(),v=p("p"),lo=a("\u7136\u540E\u5927\u90E8\u5206\u5DE5\u4F5C\u4F1A\u5728\u5C06\u6570\u636E\u52A0\u8F7D\u5668\u3001\u6A21\u578B\u548C\u4F18\u5316\u5668\u53D1\u9001\u5230\u7684"),Ls=p("code"),oo=a("accelerator.prepare()"),ro=a("\u4E2D\u5B8C\u6210\u3002\u8FD9\u5C06\u4F1A\u628A\u8FD9\u4E9B\u5BF9\u8C61\u5305\u88C5\u5728\u9002\u5F53\u7684\u5BB9\u5668\u4E2D\uFF0C\u4EE5\u786E\u4FDD\u60A8\u7684\u5206\u5E03\u5F0F\u8BAD\u7EC3\u6309\u9884\u671F\u5DE5\u4F5C\u3002\u8981\u8FDB\u884C\u7684\u5176\u4F59\u66F4\u6539\u662F\u5220\u9664\u5C06"),Ws=p("code"),po=a("batch"),no=a("\u653E\u5728 "),Ms=p("code"),co=a("device"),io=a(" \u7684\u90A3\u884C\u4EE3\u7801\uFF08\u540C\u6837\uFF0C\u5982\u679C\u60A8\u60F3\u4FDD\u7559\u5B83\uFF0C\u60A8\u53EF\u4EE5\u5C06\u5176\u66F4\u6539\u4E3A\u4F7F\u7528 "),Fs=p("code"),fo=a("accelerator.device"),mo=a(" ) \u5E76\u5C06 "),Ns=p("code"),uo=a("loss.backward()"),_o=a(" \u66FF\u6362\u4E3A"),Hs=p("code"),ho=a("accelerator.backward(loss)"),$o=a("\u3002"),Mt=i(),f(X.$$.fragment),Ft=i(),Re=p("p"),bo=a("\u5982\u679C\u60A8\u60F3\u590D\u5236\u5E76\u7C98\u8D34\u6765\u76F4\u63A5\u8FD0\u884C\uFF0C\u4EE5\u4E0B\u662F \u{1F917} Accelerate \u7684\u5B8C\u6574\u8BAD\u7EC3\u5FAA\u73AF:"),Nt=i(),f(Ae.$$.fragment),Ht=i(),Z=p("p"),ko=a("\u628A\u8FD9\u4E2A\u653E\u5728 "),Is=p("code"),vo=a("train.py"),jo=a(" \u6587\u4EF6\u4E2D\uFF0C\u53EF\u4EE5\u8BA9\u5B83\u5728\u4EFB\u4F55\u7C7B\u578B\u7684\u5206\u5E03\u5F0F\u8BBE\u7F6E\u4E0A\u8FD0\u884C\u3002\u8981\u5728\u5206\u5E03\u5F0F\u8BBE\u7F6E\u4E2D\u8BD5\u7528\u5B83\uFF0C\u8BF7\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4:"),It=i(),f(Oe.$$.fragment),Rt=i(),Be=p("p"),Eo=a("\u8FD9\u5C06\u8BE2\u95EE\u60A8\u51E0\u4E2A\u914D\u7F6E\u7684\u95EE\u9898\u5E76\u5C06\u60A8\u7684\u56DE\u7B54\u8F6C\u50A8\u5230\u6B64\u547D\u4EE4\u4F7F\u7528\u7684\u914D\u7F6E\u6587\u4EF6\u4E2D:"),Bt=i(),f(xe.$$.fragment),Jt=i(),Je=p("p"),wo=a("\u8FD9\u5C06\u542F\u52A8\u5206\u5E03\u5F0F\u8BAD\u7EC3"),Yt=i(),ee=p("p"),yo=a("\u8FD9\u5C06\u542F\u52A8\u5206\u5E03\u5F0F\u8BAD\u7EC3\u3002\u5982\u679C\u60A8\u60F3\u5728 Notebook \u4E2D\u5C1D\u8BD5\u6B64\u64CD\u4F5C\uFF08\u4F8B\u5982\uFF0C\u5728 Colab \u4E0A\u4F7F\u7528 TPU \u8FDB\u884C\u6D4B\u8BD5\uFF09\uFF0C\u53EA\u9700\u5C06\u4EE3\u7801\u7C98\u8D34\u5230 "),Rs=p("code"),qo=a("training_function()"),zo=a(" \u5E76\u4F7F\u7528\u4EE5\u4E0B\u547D\u4EE4\u8FD0\u884C\u6700\u540E\u4E00\u4E2A\u5355\u5143\u683C:"),Qt=i(),f(Se.$$.fragment),Kt=i(),se=p("p"),go=a("\u60A8\u53EF\u4EE5\u5728"),Te=p("a"),Co=a("\u{1F917} Accelerate repo"),Do=a("\u627E\u5230\u66F4\u591A\u7684\u793A\u4F8B\u3002"),this.h()},l(e){const o=Rr('[data-svelte="svelte-1phssyn"]',document.head);b=n(o,"META",{name:!0,content:!0}),o.forEach(t),z=d(e),q=n(e,"H1",{id:!0});var Bs=c(q);le=l(Bs,"\u4E00\u4E2A\u5B8C\u6574\u7684\u8BAD\u7EC3"),Bs.forEach(t),I=d(e),m(D.$$.fragment,e),S=d(e),m(U.$$.fragment,e),Js=d(e),R=n(e,"P",{});var Ue=c(R);ra=l(Ue,"\u73B0\u5728\uFF0C\u6211\u4EEC\u5C06\u4E86\u89E3\u5982\u4F55\u5728\u4E0D\u4F7F\u7528"),Ze=n(Ue,"CODE",{});var Po=c(Ze);pa=l(Po,"Trainer"),Po.forEach(t),na=l(Ue,"\u7C7B\u7684\u60C5\u51B5\u4E0B\u83B7\u5F97\u4E0E\u4E0A\u4E00\u8282\u76F8\u540C\u7684\u7ED3\u679C\u3002\u540C\u6837\uFF0C\u6211\u4EEC\u5047\u8BBE\u60A8\u5DF2\u7ECF\u5B66\u4E60\u4E86\u7B2C 2 \u8282\u4E2D\u7684\u6570\u636E\u5904\u7406\u3002\u4E0B\u9762\u662F\u4E00\u4E2A\u7B80\u77ED\u7684\u603B\u7ED3\uFF0C\u6DB5\u76D6\u4E86\u60A8\u9700\u8981\u7684\u6240\u6709\u5185\u5BB9:"),Ue.forEach(t),Ys=d(e),m(oe.$$.fragment,e),Qs=d(e),re=n(e,"H3",{id:!0});var Ao=c(re);ca=l(Ao,"\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"),Ao.forEach(t),Ks=d(e),G=n(e,"P",{});var Ye=c(G);ia=l(Ye,"\u5728\u5B9E\u9645\u7F16\u5199\u6211\u4EEC\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4E4B\u524D\uFF0C\u6211\u4EEC\u9700\u8981\u5B9A\u4E49\u4E00\u4E9B\u5BF9\u8C61\u3002\u7B2C\u4E00\u4E2A\u662F\u6211\u4EEC\u5C06\u7528\u4E8E\u8FED\u4EE3\u6279\u6B21\u7684\u6570\u636E\u52A0\u8F7D\u5668\u3002\u6211\u4EEC\u9700\u8981\u5BF9\u6211\u4EEC\u7684"),es=n(Ye,"CODE",{});var Oo=c(es);da=l(Oo,"tokenized_datasets"),Oo.forEach(t),fa=l(Ye,"\u505A\u4E00\u4E9B\u5904\u7406\uFF0C\u6765\u5904\u7406"),ss=n(Ye,"CODE",{});var xo=c(ss);ma=l(xo,"Trainer"),xo.forEach(t),ua=l(Ye,"\u81EA\u52A8\u4E3A\u6211\u4EEC\u505A\u7684\u4E00\u4E9B\u4E8B\u60C5\u3002\u5177\u4F53\u6765\u8BF4\uFF0C\u6211\u4EEC\u9700\u8981:"),Ye.forEach(t),Vs=d(e),L=n(e,"UL",{});var Qe=c(L);N=n(Qe,"LI",{});var Ke=c(N);_a=l(Ke,"\u5220\u9664\u4E0E\u6A21\u578B\u4E0D\u671F\u671B\u7684\u503C\u76F8\u5BF9\u5E94\u7684\u5217\uFF08\u5982"),ts=n(Ke,"CODE",{});var So=c(ts);ha=l(So,"sentence1"),So.forEach(t),$a=l(Ke,"\u548C"),as=n(Ke,"CODE",{});var To=c(as);ba=l(To,"sentence2"),To.forEach(t),ka=l(Ke,"\u5217\uFF09\u3002"),Ke.forEach(t),va=d(Qe),T=n(Qe,"LI",{});var te=c(T);ja=l(te,"\u5C06\u5217\u540D"),ls=n(te,"CODE",{});var Uo=c(ls);Ea=l(Uo,"label"),Uo.forEach(t),wa=l(te,"\u91CD\u547D\u540D\u4E3A"),os=n(te,"CODE",{});var Go=c(os);ya=l(Go,"labels"),Go.forEach(t),qa=l(te,"\uFF08\u56E0\u4E3A\u6A21\u578B\u671F\u671B\u53C2\u6570\u662F"),rs=n(te,"CODE",{});var Lo=c(rs);za=l(Lo,"labels"),Lo.forEach(t),ga=l(te,"\uFF09\u3002"),te.forEach(t),Ca=d(Qe),ps=n(Qe,"LI",{});var Wo=c(ps);Da=l(Wo,"\u8BBE\u7F6E\u6570\u636E\u96C6\u7684\u683C\u5F0F\uFF0C\u4F7F\u5176\u8FD4\u56DE PyTorch \u5F20\u91CF\u800C\u4E0D\u662F\u5217\u8868\u3002"),Wo.forEach(t),Qe.forEach(t),Xs=d(e),B=n(e,"P",{});var Xt=c(B);Pa=l(Xt,"\u9488\u5BF9\u4E0A\u9762\u7684\u6BCF\u4E2A\u6B65\u9AA4\uFF0C\u6211\u4EEC\u7684 "),ns=n(Xt,"CODE",{});var Mo=c(ns);Aa=l(Mo,"tokenized_datasets"),Mo.forEach(t),Oa=l(Xt," \u90FD\u6709\u4E00\u4E2A\u65B9\u6CD5:"),Xt.forEach(t),Zs=d(e),m(pe.$$.fragment,e),et=d(e),Le=n(e,"P",{});var Fo=c(Le);xa=l(Fo,"\u7136\u540E\uFF0C\u6211\u4EEC\u53EF\u4EE5\u68C0\u67E5\u7ED3\u679C\u4E2D\u662F\u5426\u53EA\u6709\u6A21\u578B\u80FD\u591F\u63A5\u53D7\u7684\u5217:"),Fo.forEach(t),st=d(e),m(ne.$$.fragment,e),tt=d(e),We=n(e,"P",{});var No=c(We);Sa=l(No,"\u81F3\u6B64\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8F7B\u677E\u5B9A\u4E49\u6570\u636E\u52A0\u8F7D\u5668:"),No.forEach(t),at=d(e),m(ce.$$.fragment,e),lt=d(e),Me=n(e,"P",{});var Ho=c(Me);Ta=l(Ho,"\u4E3A\u4E86\u5FEB\u901F\u68C0\u9A8C\u6570\u636E\u5904\u7406\u4E2D\u6CA1\u6709\u9519\u8BEF\uFF0C\u6211\u4EEC\u53EF\u4EE5\u8FD9\u6837\u68C0\u9A8C\u5176\u4E2D\u7684\u4E00\u4E2A\u6279\u6B21:"),Ho.forEach(t),ot=d(e),m(ie.$$.fragment,e),rt=d(e),m(de.$$.fragment,e),pt=d(e),W=n(e,"P",{});var Ve=c(W);Ua=l(Ve,"\u8BF7\u6CE8\u610F\uFF0C\u5B9E\u9645\u7684\u5F62\u72B6\u53EF\u80FD\u4E0E\u60A8\u7565\u6709\u4E0D\u540C\uFF0C\u56E0\u4E3A\u6211\u4EEC\u4E3A\u8BAD\u7EC3\u6570\u636E\u52A0\u8F7D\u5668\u8BBE\u7F6E\u4E86"),cs=n(Ve,"CODE",{});var Io=c(cs);Ga=l(Io,"shuffle=True"),Io.forEach(t),La=l(Ve,"\uFF0C\u5E76\u4E14\u6A21\u578B\u4F1A\u5C06\u53E5\u5B50\u586B\u5145\u5230"),is=n(Ve,"CODE",{});var Ro=c(is);Wa=l(Ro,"batch"),Ro.forEach(t),Ma=l(Ve,"\u4E2D\u7684\u6700\u5927\u957F\u5EA6\u3002"),Ve.forEach(t),nt=d(e),Fe=n(e,"P",{});var Bo=c(Fe);Fa=l(Bo,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u5B8C\u5168\u5B8C\u6210\u4E86\u6570\u636E\u9884\u5904\u7406\uFF08\u5BF9\u4E8E\u4EFB\u4F55 ML \u4ECE\u4E1A\u8005\u6765\u8BF4\u90FD\u662F\u4E00\u4E2A\u4EE4\u4EBA\u6EE1\u610F\u4F46\u96BE\u4EE5\u5B9E\u73B0\u7684\u76EE\u6807\uFF09\uFF0C\u8BA9\u6211\u4EEC\u5C06\u6CE8\u610F\u529B\u8F6C\u5411\u6A21\u578B\u3002\u6211\u4EEC\u5B8C\u5168\u50CF\u5728\u4E0A\u4E00\u8282\u4E2D\u6240\u505A\u7684\u90A3\u6837\u5B9E\u4F8B\u5316\u5B83:"),Bo.forEach(t),ct=d(e),m(fe.$$.fragment,e),it=d(e),J=n(e,"P",{});var Zt=c(J);Na=l(Zt,"\u4E3A\u4E86\u786E\u4FDD\u8BAD\u7EC3\u8FC7\u7A0B\u4E2D\u4E00\u5207\u987A\u5229\uFF0C\u6211\u4EEC\u5C06"),ds=n(Zt,"CODE",{});var Jo=c(ds);Ha=l(Jo,"batch"),Jo.forEach(t),Ia=l(Zt,"\u4F20\u9012\u7ED9\u8FD9\u4E2A\u6A21\u578B:"),Zt.forEach(t),dt=d(e),m(me.$$.fragment,e),ft=d(e),m(ue.$$.fragment,e),mt=d(e),j=n(e,"P",{});var A=c(j);Ra=l(A,"\u5F53\u6211\u4EEC\u63D0\u4F9B "),fs=n(A,"CODE",{});var Yo=c(fs);Ba=l(Yo,"labels"),Yo.forEach(t),Ja=l(A," \u65F6\uFF0C \u{1F917} Transformers \u6A21\u578B\u90FD\u5C06\u8FD4\u56DE\u8FD9\u4E2A"),ms=n(A,"CODE",{});var Qo=c(ms);Ya=l(Qo,"batch"),Qo.forEach(t),Qa=l(A,"\u7684"),us=n(A,"CODE",{});var Ko=c(us);Ka=l(Ko,"loss"),Ko.forEach(t),Va=l(A,"\uFF0C\u6211\u4EEC\u8FD8\u5F97\u5230\u4E86 "),_s=n(A,"CODE",{});var Vo=c(_s);Xa=l(Vo,"logits"),Vo.forEach(t),Za=l(A,"("),hs=n(A,"CODE",{});var Xo=c(hs);el=l(Xo,"batch"),Xo.forEach(t),sl=l(A,"\u4E2D\u7684\u6BCF\u4E2A\u8F93\u5165\u6709\u4E24\u4E2A\uFF0C\u6240\u4EE5\u5F20\u91CF\u5927\u5C0F\u4E3A 8 x 2)\u3002"),A.forEach(t),ut=d(e),E=n(e,"P",{});var O=c(E);tl=l(O,"\u6211\u4EEC\u51E0\u4E4E\u51C6\u5907\u597D\u7F16\u5199\u6211\u4EEC\u7684\u8BAD\u7EC3\u5FAA\u73AF\u4E86\uFF01\u6211\u4EEC\u53EA\u662F\u7F3A\u5C11\u4E24\u4EF6\u4E8B\uFF1A\u4F18\u5316\u5668\u548C\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u3002\u7531\u4E8E\u6211\u4EEC\u8BD5\u56FE\u81EA\u884C\u5B9E\u73B0 "),$s=n(O,"CODE",{});var Zo=c($s);al=l(Zo,"Trainer"),Zo.forEach(t),ll=l(O,"\u7684\u529F\u80FD\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528\u76F8\u540C\u7684\u4F18\u5316\u5668\u548C\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u3002"),bs=n(O,"CODE",{});var er=c(bs);ol=l(er,"Trainer"),er.forEach(t),rl=l(O," \u4F7F\u7528\u7684\u4F18\u5316\u5668\u662F "),ks=n(O,"CODE",{});var sr=c(ks);pl=l(sr,"AdamW"),sr.forEach(t),nl=l(O," , \u4E0E "),vs=n(O,"CODE",{});var tr=c(vs);cl=l(tr,"Adam"),tr.forEach(t),il=l(O," \u76F8\u540C\uFF0C\u4F46\u5728\u6743\u91CD\u8870\u51CF\u6B63\u5219\u5316\u65B9\u9762\u6709\u6240\u4E0D\u540C(\u53C2\u89C1"),_e=n(O,"A",{href:!0,rel:!0});var ar=c(_e);dl=l(ar,"\u201CDecoupled Weight Decay Regularization\u201D"),ar.forEach(t),fl=l(O,"\u4F5C\u8005:Ilya Loshchilov \u548C Frank Hutter):"),O.forEach(t),_t=d(e),m(he.$$.fragment,e),ht=d(e),M=n(e,"P",{});var Xe=c(M);ml=l(Xe,"\u6700\u540E\uFF0C\u9ED8\u8BA4\u4F7F\u7528\u7684\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u53EA\u662F\u4ECE\u6700\u5927\u503C (5e-5) \u5230 0 \u7684\u7EBF\u6027\u8870\u51CF\u3002 \u4E3A\u4E86\u5B9A\u4E49\u5B83\uFF0C\u6211\u4EEC\u9700\u8981\u77E5\u9053\u6211\u4EEC\u8BAD\u7EC3\u7684\u6B21\u6570\uFF0C\u5373\u6240\u6709\u6570\u636E\u8BAD\u7EC3\u7684\u6B21\u6570(epochs)\u4E58\u4EE5\u7684\u6570\u636E\u91CF\uFF08\u8FD9\u662F\u6211\u4EEC\u6240\u6709\u8BAD\u7EC3\u6570\u636E\u7684\u6570\u91CF\uFF09\u3002"),js=n(Xe,"CODE",{});var lr=c(js);ul=l(lr,"Trainer"),lr.forEach(t),_l=l(Xe,"\u9ED8\u8BA4\u60C5\u51B5\u4E0B\u4F7F\u7528\u4E09\u4E2A"),Es=n(Xe,"CODE",{});var or=c(Es);hl=l(or,"epochs"),or.forEach(t),$l=l(Xe,"\uFF0C\u56E0\u6B64\u6211\u4EEC\u5B9A\u4E49\u8BAD\u7EC3\u8FC7\u7A0B\u5982\u4E0B:"),Xe.forEach(t),$t=d(e),m($e.$$.fragment,e),bt=d(e),m(be.$$.fragment,e),kt=d(e),ke=n(e,"H3",{id:!0});var rr=c(ke);bl=l(rr,"\u8BAD\u7EC3\u5FAA\u73AF"),rr.forEach(t),vt=d(e),P=n(e,"P",{});var ae=c(P);kl=l(ae,"\u6700\u540E\u4E00\u4EF6\u4E8B\uFF1A\u5982\u679C\u6211\u4EEC\u53EF\u4EE5\u8BBF\u95EE GPU,\u6211\u4EEC\u5C06\u5E0C\u671B\u4F7F\u7528 GPU(\u5728 CPU \u4E0A\uFF0C\u8BAD\u7EC3\u53EF\u80FD\u9700\u8981\u51E0\u4E2A\u5C0F\u65F6\u800C\u4E0D\u662F\u51E0\u5206\u949F)\u3002\u4E3A\u6B64\uFF0C\u6211\u4EEC\u5B9A\u4E49\u4E86\u4E00\u4E2A "),ws=n(ae,"CODE",{});var pr=c(ws);vl=l(pr,"device"),pr.forEach(t),jl=l(ae,",\u5B83\u5728GPU\u53EF\u7528\u7684\u60C5\u51B5\u4E0B\u6307\u5411GPU \u6211\u4EEC\u5C06\u628A\u6211\u4EEC\u7684\u6A21\u578B\u548C"),ys=n(ae,"CODE",{});var nr=c(ys);El=l(nr,"batche"),nr.forEach(t),wl=l(ae,"\u653E\u5728"),qs=n(ae,"CODE",{});var cr=c(qs);yl=l(cr,"device"),cr.forEach(t),ql=l(ae,"\u4E0A:"),ae.forEach(t),jt=d(e),m(ve.$$.fragment,e),Et=d(e),m(je.$$.fragment,e),wt=d(e),Y=n(e,"P",{});var ea=c(Y);zl=l(ea,"\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u597D\u8BAD\u7EC3\u4E86\uFF01\u4E3A\u4E86\u4E86\u89E3\u8BAD\u7EC3\u4F55\u65F6\u7ED3\u675F\uFF0C\u6211\u4EEC\u4F7F\u7528 "),zs=n(ea,"CODE",{});var ir=c(zs);gl=l(ir,"tqdm"),ir.forEach(t),Cl=l(ea," \u5E93,\u5728\u8BAD\u7EC3\u6B65\u9AA4\u6570\u4E0A\u6DFB\u52A0\u4E86\u4E00\u4E2A\u8FDB\u5EA6\u6761:"),ea.forEach(t),yt=d(e),m(Ee.$$.fragment,e),qt=d(e),Ne=n(e,"P",{});var dr=c(Ne);Dl=l(dr,"\u60A8\u53EF\u4EE5\u770B\u5230\u8BAD\u7EC3\u5FAA\u73AF\u7684\u6838\u5FC3\u4E0E\u4ECB\u7ECD\u4E2D\u7684\u975E\u5E38\u76F8\u4F3C\u3002\u6211\u4EEC\u6CA1\u6709\u8981\u6C42\u4EFB\u4F55\u68C0\u9A8C\uFF0C\u6240\u4EE5\u8FD9\u4E2A\u8BAD\u7EC3\u5FAA\u73AF\u4E0D\u4F1A\u544A\u8BC9\u6211\u4EEC\u4EFB\u4F55\u5173\u4E8E\u6A21\u578B\u76EE\u524D\u7684\u72B6\u6001\u3002\u6211\u4EEC\u9700\u8981\u4E3A\u6B64\u6DFB\u52A0\u4E00\u4E2A\u8BC4\u4F30\u5FAA\u73AF\u3002"),dr.forEach(t),zt=d(e),we=n(e,"H3",{id:!0});var fr=c(we);Pl=l(fr,"\u8BC4\u4F30\u5FAA\u73AF"),fr.forEach(t),gt=d(e),w=n(e,"P",{});var x=c(w);Al=l(x,"\u6B63\u5982\u6211\u4EEC\u4E4B\u524D\u6240\u505A\u7684\u90A3\u6837\uFF0C\u6211\u4EEC\u5C06\u4F7F\u7528 \u{1F917} Datasets \u5E93\u63D0\u4F9B\u7684\u6307\u6807\u3002\u6211\u4EEC\u5DF2\u7ECF\u4E86\u89E3\u4E86 "),gs=n(x,"CODE",{});var mr=c(gs);Ol=l(mr,"metric.compute()"),mr.forEach(t),xl=l(x," \u65B9\u6CD5\uFF0C\u5F53\u6211\u4EEC\u4F7F\u7528 "),Cs=n(x,"CODE",{});var ur=c(Cs);Sl=l(ur,"add_batch()"),ur.forEach(t),Tl=l(x,"\u65B9\u6CD5\u8FDB\u884C\u9884\u6D4B\u5FAA\u73AF\u65F6\uFF0C\u5B9E\u9645\u4E0A\u8BE5\u6307\u6807\u53EF\u4EE5\u4E3A\u6211\u4EEC\u7D2F\u79EF\u6240\u6709 "),Ds=n(x,"CODE",{});var _r=c(Ds);Ul=l(_r,"batch"),_r.forEach(t),Gl=l(x," \u7684\u7ED3\u679C\u3002\u4E00\u65E6\u6211\u4EEC\u7D2F\u79EF\u4E86\u6240\u6709 "),Ps=n(x,"CODE",{});var hr=c(Ps);Ll=l(hr,"batch"),hr.forEach(t),Wl=l(x," \uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u4F7F\u7528 "),As=n(x,"CODE",{});var $r=c(As);Ml=l($r,"metric.compute()"),$r.forEach(t),Fl=l(x," \u5F97\u5230\u6700\u7EC8\u7ED3\u679C .\u4EE5\u4E0B\u662F\u5728\u8BC4\u4F30\u5FAA\u73AF\u4E2D\u5B9E\u73B0\u6240\u6709\u8FD9\u4E9B\u7684\u65B9\u6CD5:"),x.forEach(t),Ct=d(e),m(ye.$$.fragment,e),Dt=d(e),m(qe.$$.fragment,e),Pt=d(e),He=n(e,"P",{});var br=c(He);Nl=l(br,"\u540C\u6837\uFF0C\u7531\u4E8E\u6A21\u578B\u5934\u90E8\u521D\u59CB\u5316\u548C\u6570\u636E\u6539\u7EC4\u7684\u968F\u673A\u6027\uFF0C\u60A8\u7684\u7ED3\u679C\u4F1A\u7565\u6709\u4E0D\u540C\uFF0C\u4F46\u5B83\u4EEC\u5E94\u8BE5\u5728\u540C\u4E00\u4E2A\u8303\u56F4\u5185\u3002"),br.forEach(t),At=d(e),m(Q.$$.fragment,e),Ot=d(e),H=n(e,"H3",{class:!0});var sa=c(H);K=n(sa,"A",{id:!0,class:!0,href:!0});var kr=c(K);Os=n(kr,"SPAN",{});var vr=c(Os);m(ze.$$.fragment,vr),vr.forEach(t),kr.forEach(t),Hl=d(sa),xs=n(sa,"SPAN",{});var jr=c(xs);Il=l(jr,"S\u4F7F\u7528\u{1F917} Accelerate\u52A0\u901F\u60A8\u7684\u8BAD\u7EC3\u5FAA\u73AF"),jr.forEach(t),sa.forEach(t),xt=d(e),m(ge.$$.fragment,e),St=d(e),V=n(e,"P",{});var ta=c(V);Rl=l(ta,"\u6211\u4EEC\u4E4B\u524D\u5B9A\u4E49\u7684\u8BAD\u7EC3\u5FAA\u73AF\u5728\u5355\u4E2A CPU \u6216 GPU \u4E0A\u8FD0\u884C\u826F\u597D\u3002\u4F46\u662F\u4F7F\u7528"),Ce=n(ta,"A",{href:!0,rel:!0});var Er=c(Ce);Bl=l(Er,"\u{1F917} Accelerate"),Er.forEach(t),Jl=l(ta,"\u5E93\uFF0C\u53EA\u9700\u8FDB\u884C\u4E00\u4E9B\u8C03\u6574\uFF0C\u6211\u4EEC\u5C31\u53EF\u4EE5\u5728\u591A\u4E2A GPU \u6216 TPU \u4E0A\u542F\u7528\u5206\u5E03\u5F0F\u8BAD\u7EC3\u3002\u4ECE\u521B\u5EFA\u8BAD\u7EC3\u548C\u9A8C\u8BC1\u6570\u636E\u52A0\u8F7D\u5668\u5F00\u59CB\uFF0C\u6211\u4EEC\u7684\u624B\u52A8\u8BAD\u7EC3\u5FAA\u73AF\u5982\u4E0B\u6240\u793A\uFF1A"),ta.forEach(t),Tt=d(e),m(De.$$.fragment,e),Ut=d(e),Ie=n(e,"P",{});var wr=c(Ie);Yl=l(wr,"\u4EE5\u4E0B\u662F\u53D8\u5316:"),wr.forEach(t),Gt=d(e),m(Pe.$$.fragment,e),Lt=d(e),g=n(e,"P",{});var F=c(g);Ql=l(F,"\u8981\u6DFB\u52A0\u7684\u7B2C\u4E00\u884C\u662F\u5BFC\u5165"),Ss=n(F,"CODE",{});var yr=c(Ss);Kl=l(yr,"Accelerator"),yr.forEach(t),Vl=l(F,"\u3002\u7B2C\u4E8C\u884C\u5B9E\u4F8B\u5316\u4E00\u4E2A "),Ts=n(F,"CODE",{});var qr=c(Ts);Xl=l(qr,"Accelerator"),qr.forEach(t),Zl=l(F,"\u5BF9\u8C61 \uFF0C\u5B83\u5C06\u67E5\u770B\u73AF\u5883\u5E76\u521D\u59CB\u5316\u9002\u5F53\u7684\u5206\u5E03\u5F0F\u8BBE\u7F6E\u3002 \u{1F917} Accelerate \u4E3A\u60A8\u5904\u7406\u6570\u636E\u5728\u8BBE\u5907\u95F4\u7684\u4F20\u9012\uFF0C\u56E0\u6B64\u60A8\u53EF\u4EE5\u5220\u9664\u5C06\u6A21\u578B\u653E\u5728\u8BBE\u5907\u4E0A\u7684\u90A3\u884C\u4EE3\u7801\uFF08\u6216\u8005\uFF0C\u5982\u679C\u60A8\u613F\u610F\uFF0C\u53EF\u4F7F\u7528 "),Us=n(F,"CODE",{});var zr=c(Us);eo=l(zr,"accelerator.device"),zr.forEach(t),so=l(F," \u4EE3\u66FF "),Gs=n(F,"CODE",{});var gr=c(Gs);to=l(gr,"device"),gr.forEach(t),ao=l(F," \uFF09\u3002"),F.forEach(t),Wt=d(e),v=n(e,"P",{});var C=c(v);lo=l(C,"\u7136\u540E\u5927\u90E8\u5206\u5DE5\u4F5C\u4F1A\u5728\u5C06\u6570\u636E\u52A0\u8F7D\u5668\u3001\u6A21\u578B\u548C\u4F18\u5316\u5668\u53D1\u9001\u5230\u7684"),Ls=n(C,"CODE",{});var Cr=c(Ls);oo=l(Cr,"accelerator.prepare()"),Cr.forEach(t),ro=l(C,"\u4E2D\u5B8C\u6210\u3002\u8FD9\u5C06\u4F1A\u628A\u8FD9\u4E9B\u5BF9\u8C61\u5305\u88C5\u5728\u9002\u5F53\u7684\u5BB9\u5668\u4E2D\uFF0C\u4EE5\u786E\u4FDD\u60A8\u7684\u5206\u5E03\u5F0F\u8BAD\u7EC3\u6309\u9884\u671F\u5DE5\u4F5C\u3002\u8981\u8FDB\u884C\u7684\u5176\u4F59\u66F4\u6539\u662F\u5220\u9664\u5C06"),Ws=n(C,"CODE",{});var Dr=c(Ws);po=l(Dr,"batch"),Dr.forEach(t),no=l(C,"\u653E\u5728 "),Ms=n(C,"CODE",{});var Pr=c(Ms);co=l(Pr,"device"),Pr.forEach(t),io=l(C," \u7684\u90A3\u884C\u4EE3\u7801\uFF08\u540C\u6837\uFF0C\u5982\u679C\u60A8\u60F3\u4FDD\u7559\u5B83\uFF0C\u60A8\u53EF\u4EE5\u5C06\u5176\u66F4\u6539\u4E3A\u4F7F\u7528 "),Fs=n(C,"CODE",{});var Ar=c(Fs);fo=l(Ar,"accelerator.device"),Ar.forEach(t),mo=l(C," ) \u5E76\u5C06 "),Ns=n(C,"CODE",{});var Or=c(Ns);uo=l(Or,"loss.backward()"),Or.forEach(t),_o=l(C," \u66FF\u6362\u4E3A"),Hs=n(C,"CODE",{});var xr=c(Hs);ho=l(xr,"accelerator.backward(loss)"),xr.forEach(t),$o=l(C,"\u3002"),C.forEach(t),Mt=d(e),m(X.$$.fragment,e),Ft=d(e),Re=n(e,"P",{});var Sr=c(Re);bo=l(Sr,"\u5982\u679C\u60A8\u60F3\u590D\u5236\u5E76\u7C98\u8D34\u6765\u76F4\u63A5\u8FD0\u884C\uFF0C\u4EE5\u4E0B\u662F \u{1F917} Accelerate \u7684\u5B8C\u6574\u8BAD\u7EC3\u5FAA\u73AF:"),Sr.forEach(t),Nt=d(e),m(Ae.$$.fragment,e),Ht=d(e),Z=n(e,"P",{});var aa=c(Z);ko=l(aa,"\u628A\u8FD9\u4E2A\u653E\u5728 "),Is=n(aa,"CODE",{});var Tr=c(Is);vo=l(Tr,"train.py"),Tr.forEach(t),jo=l(aa," \u6587\u4EF6\u4E2D\uFF0C\u53EF\u4EE5\u8BA9\u5B83\u5728\u4EFB\u4F55\u7C7B\u578B\u7684\u5206\u5E03\u5F0F\u8BBE\u7F6E\u4E0A\u8FD0\u884C\u3002\u8981\u5728\u5206\u5E03\u5F0F\u8BBE\u7F6E\u4E2D\u8BD5\u7528\u5B83\uFF0C\u8BF7\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4:"),aa.forEach(t),It=d(e),m(Oe.$$.fragment,e),Rt=d(e),Be=n(e,"P",{});var Ur=c(Be);Eo=l(Ur,"\u8FD9\u5C06\u8BE2\u95EE\u60A8\u51E0\u4E2A\u914D\u7F6E\u7684\u95EE\u9898\u5E76\u5C06\u60A8\u7684\u56DE\u7B54\u8F6C\u50A8\u5230\u6B64\u547D\u4EE4\u4F7F\u7528\u7684\u914D\u7F6E\u6587\u4EF6\u4E2D:"),Ur.forEach(t),Bt=d(e),m(xe.$$.fragment,e),Jt=d(e),Je=n(e,"P",{});var Gr=c(Je);wo=l(Gr,"\u8FD9\u5C06\u542F\u52A8\u5206\u5E03\u5F0F\u8BAD\u7EC3"),Gr.forEach(t),Yt=d(e),ee=n(e,"P",{});var la=c(ee);yo=l(la,"\u8FD9\u5C06\u542F\u52A8\u5206\u5E03\u5F0F\u8BAD\u7EC3\u3002\u5982\u679C\u60A8\u60F3\u5728 Notebook \u4E2D\u5C1D\u8BD5\u6B64\u64CD\u4F5C\uFF08\u4F8B\u5982\uFF0C\u5728 Colab \u4E0A\u4F7F\u7528 TPU \u8FDB\u884C\u6D4B\u8BD5\uFF09\uFF0C\u53EA\u9700\u5C06\u4EE3\u7801\u7C98\u8D34\u5230 "),Rs=n(la,"CODE",{});var Lr=c(Rs);qo=l(Lr,"training_function()"),Lr.forEach(t),zo=l(la," \u5E76\u4F7F\u7528\u4EE5\u4E0B\u547D\u4EE4\u8FD0\u884C\u6700\u540E\u4E00\u4E2A\u5355\u5143\u683C:"),la.forEach(t),Qt=d(e),m(Se.$$.fragment,e),Kt=d(e),se=n(e,"P",{});var oa=c(se);go=l(oa,"\u60A8\u53EF\u4EE5\u5728"),Te=n(oa,"A",{href:!0,rel:!0});var Wr=c(Te);Co=l(Wr,"\u{1F917} Accelerate repo"),Wr.forEach(t),Do=l(oa,"\u627E\u5230\u66F4\u591A\u7684\u793A\u4F8B\u3002"),oa.forEach(t),this.h()},h(){y(b,"name","hf:doc:metadata"),y(b,"content",JSON.stringify(Xr)),y(q,"id",""),y(re,"id",""),y(_e,"href","https://arxiv.org/abs/1711.05101"),y(_e,"rel","nofollow"),y(ke,"id",""),y(we,"id",""),y(K,"id","s-accelerate"),y(K,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),y(K,"href","#s-accelerate"),y(H,"class","relative group"),y(Ce,"href","https://github.com/huggingface/accelerate"),y(Ce,"rel","nofollow"),y(Te,"href","https://github.com/huggingface/accelerate/tree/main/examples"),y(Te,"rel","nofollow")},m(e,o){s(document.head,b),r(e,z,o),r(e,q,o),s(q,le),r(e,I,o),u(D,e,o),r(e,S,o),u(U,e,o),r(e,Js,o),r(e,R,o),s(R,ra),s(R,Ze),s(Ze,pa),s(R,na),r(e,Ys,o),u(oe,e,o),r(e,Qs,o),r(e,re,o),s(re,ca),r(e,Ks,o),r(e,G,o),s(G,ia),s(G,es),s(es,da),s(G,fa),s(G,ss),s(ss,ma),s(G,ua),r(e,Vs,o),r(e,L,o),s(L,N),s(N,_a),s(N,ts),s(ts,ha),s(N,$a),s(N,as),s(as,ba),s(N,ka),s(L,va),s(L,T),s(T,ja),s(T,ls),s(ls,Ea),s(T,wa),s(T,os),s(os,ya),s(T,qa),s(T,rs),s(rs,za),s(T,ga),s(L,Ca),s(L,ps),s(ps,Da),r(e,Xs,o),r(e,B,o),s(B,Pa),s(B,ns),s(ns,Aa),s(B,Oa),r(e,Zs,o),u(pe,e,o),r(e,et,o),r(e,Le,o),s(Le,xa),r(e,st,o),u(ne,e,o),r(e,tt,o),r(e,We,o),s(We,Sa),r(e,at,o),u(ce,e,o),r(e,lt,o),r(e,Me,o),s(Me,Ta),r(e,ot,o),u(ie,e,o),r(e,rt,o),u(de,e,o),r(e,pt,o),r(e,W,o),s(W,Ua),s(W,cs),s(cs,Ga),s(W,La),s(W,is),s(is,Wa),s(W,Ma),r(e,nt,o),r(e,Fe,o),s(Fe,Fa),r(e,ct,o),u(fe,e,o),r(e,it,o),r(e,J,o),s(J,Na),s(J,ds),s(ds,Ha),s(J,Ia),r(e,dt,o),u(me,e,o),r(e,ft,o),u(ue,e,o),r(e,mt,o),r(e,j,o),s(j,Ra),s(j,fs),s(fs,Ba),s(j,Ja),s(j,ms),s(ms,Ya),s(j,Qa),s(j,us),s(us,Ka),s(j,Va),s(j,_s),s(_s,Xa),s(j,Za),s(j,hs),s(hs,el),s(j,sl),r(e,ut,o),r(e,E,o),s(E,tl),s(E,$s),s($s,al),s(E,ll),s(E,bs),s(bs,ol),s(E,rl),s(E,ks),s(ks,pl),s(E,nl),s(E,vs),s(vs,cl),s(E,il),s(E,_e),s(_e,dl),s(E,fl),r(e,_t,o),u(he,e,o),r(e,ht,o),r(e,M,o),s(M,ml),s(M,js),s(js,ul),s(M,_l),s(M,Es),s(Es,hl),s(M,$l),r(e,$t,o),u($e,e,o),r(e,bt,o),u(be,e,o),r(e,kt,o),r(e,ke,o),s(ke,bl),r(e,vt,o),r(e,P,o),s(P,kl),s(P,ws),s(ws,vl),s(P,jl),s(P,ys),s(ys,El),s(P,wl),s(P,qs),s(qs,yl),s(P,ql),r(e,jt,o),u(ve,e,o),r(e,Et,o),u(je,e,o),r(e,wt,o),r(e,Y,o),s(Y,zl),s(Y,zs),s(zs,gl),s(Y,Cl),r(e,yt,o),u(Ee,e,o),r(e,qt,o),r(e,Ne,o),s(Ne,Dl),r(e,zt,o),r(e,we,o),s(we,Pl),r(e,gt,o),r(e,w,o),s(w,Al),s(w,gs),s(gs,Ol),s(w,xl),s(w,Cs),s(Cs,Sl),s(w,Tl),s(w,Ds),s(Ds,Ul),s(w,Gl),s(w,Ps),s(Ps,Ll),s(w,Wl),s(w,As),s(As,Ml),s(w,Fl),r(e,Ct,o),u(ye,e,o),r(e,Dt,o),u(qe,e,o),r(e,Pt,o),r(e,He,o),s(He,Nl),r(e,At,o),u(Q,e,o),r(e,Ot,o),r(e,H,o),s(H,K),s(K,Os),u(ze,Os,null),s(H,Hl),s(H,xs),s(xs,Il),r(e,xt,o),u(ge,e,o),r(e,St,o),r(e,V,o),s(V,Rl),s(V,Ce),s(Ce,Bl),s(V,Jl),r(e,Tt,o),u(De,e,o),r(e,Ut,o),r(e,Ie,o),s(Ie,Yl),r(e,Gt,o),u(Pe,e,o),r(e,Lt,o),r(e,g,o),s(g,Ql),s(g,Ss),s(Ss,Kl),s(g,Vl),s(g,Ts),s(Ts,Xl),s(g,Zl),s(g,Us),s(Us,eo),s(g,so),s(g,Gs),s(Gs,to),s(g,ao),r(e,Wt,o),r(e,v,o),s(v,lo),s(v,Ls),s(Ls,oo),s(v,ro),s(v,Ws),s(Ws,po),s(v,no),s(v,Ms),s(Ms,co),s(v,io),s(v,Fs),s(Fs,fo),s(v,mo),s(v,Ns),s(Ns,uo),s(v,_o),s(v,Hs),s(Hs,ho),s(v,$o),r(e,Mt,o),u(X,e,o),r(e,Ft,o),r(e,Re,o),s(Re,bo),r(e,Nt,o),u(Ae,e,o),r(e,Ht,o),r(e,Z,o),s(Z,ko),s(Z,Is),s(Is,vo),s(Z,jo),r(e,It,o),u(Oe,e,o),r(e,Rt,o),r(e,Be,o),s(Be,Eo),r(e,Bt,o),u(xe,e,o),r(e,Jt,o),r(e,Je,o),s(Je,wo),r(e,Yt,o),r(e,ee,o),s(ee,yo),s(ee,Rs),s(Rs,qo),s(ee,zo),r(e,Qt,o),u(Se,e,o),r(e,Kt,o),r(e,se,o),s(se,go),s(se,Te),s(Te,Co),s(se,Do),Vt=!0},p(e,[o]){const Bs={};o&2&&(Bs.$$scope={dirty:o,ctx:e}),Q.$set(Bs);const Ue={};o&2&&(Ue.$$scope={dirty:o,ctx:e}),X.$set(Ue)},i(e){Vt||(_(D.$$.fragment,e),_(U.$$.fragment,e),_(oe.$$.fragment,e),_(pe.$$.fragment,e),_(ne.$$.fragment,e),_(ce.$$.fragment,e),_(ie.$$.fragment,e),_(de.$$.fragment,e),_(fe.$$.fragment,e),_(me.$$.fragment,e),_(ue.$$.fragment,e),_(he.$$.fragment,e),_($e.$$.fragment,e),_(be.$$.fragment,e),_(ve.$$.fragment,e),_(je.$$.fragment,e),_(Ee.$$.fragment,e),_(ye.$$.fragment,e),_(qe.$$.fragment,e),_(Q.$$.fragment,e),_(ze.$$.fragment,e),_(ge.$$.fragment,e),_(De.$$.fragment,e),_(Pe.$$.fragment,e),_(X.$$.fragment,e),_(Ae.$$.fragment,e),_(Oe.$$.fragment,e),_(xe.$$.fragment,e),_(Se.$$.fragment,e),Vt=!0)},o(e){h(D.$$.fragment,e),h(U.$$.fragment,e),h(oe.$$.fragment,e),h(pe.$$.fragment,e),h(ne.$$.fragment,e),h(ce.$$.fragment,e),h(ie.$$.fragment,e),h(de.$$.fragment,e),h(fe.$$.fragment,e),h(me.$$.fragment,e),h(ue.$$.fragment,e),h(he.$$.fragment,e),h($e.$$.fragment,e),h(be.$$.fragment,e),h(ve.$$.fragment,e),h(je.$$.fragment,e),h(Ee.$$.fragment,e),h(ye.$$.fragment,e),h(qe.$$.fragment,e),h(Q.$$.fragment,e),h(ze.$$.fragment,e),h(ge.$$.fragment,e),h(De.$$.fragment,e),h(Pe.$$.fragment,e),h(X.$$.fragment,e),h(Ae.$$.fragment,e),h(Oe.$$.fragment,e),h(xe.$$.fragment,e),h(Se.$$.fragment,e),Vt=!1},d(e){t(b),e&&t(z),e&&t(q),e&&t(I),$(D,e),e&&t(S),$(U,e),e&&t(Js),e&&t(R),e&&t(Ys),$(oe,e),e&&t(Qs),e&&t(re),e&&t(Ks),e&&t(G),e&&t(Vs),e&&t(L),e&&t(Xs),e&&t(B),e&&t(Zs),$(pe,e),e&&t(et),e&&t(Le),e&&t(st),$(ne,e),e&&t(tt),e&&t(We),e&&t(at),$(ce,e),e&&t(lt),e&&t(Me),e&&t(ot),$(ie,e),e&&t(rt),$(de,e),e&&t(pt),e&&t(W),e&&t(nt),e&&t(Fe),e&&t(ct),$(fe,e),e&&t(it),e&&t(J),e&&t(dt),$(me,e),e&&t(ft),$(ue,e),e&&t(mt),e&&t(j),e&&t(ut),e&&t(E),e&&t(_t),$(he,e),e&&t(ht),e&&t(M),e&&t($t),$($e,e),e&&t(bt),$(be,e),e&&t(kt),e&&t(ke),e&&t(vt),e&&t(P),e&&t(jt),$(ve,e),e&&t(Et),$(je,e),e&&t(wt),e&&t(Y),e&&t(yt),$(Ee,e),e&&t(qt),e&&t(Ne),e&&t(zt),e&&t(we),e&&t(gt),e&&t(w),e&&t(Ct),$(ye,e),e&&t(Dt),$(qe,e),e&&t(Pt),e&&t(He),e&&t(At),$(Q,e),e&&t(Ot),e&&t(H),$(ze),e&&t(xt),$(ge,e),e&&t(St),e&&t(V),e&&t(Tt),$(De,e),e&&t(Ut),e&&t(Ie),e&&t(Gt),$(Pe,e),e&&t(Lt),e&&t(g),e&&t(Wt),e&&t(v),e&&t(Mt),$(X,e),e&&t(Ft),e&&t(Re),e&&t(Nt),$(Ae,e),e&&t(Ht),e&&t(Z),e&&t(It),$(Oe,e),e&&t(Rt),e&&t(Be),e&&t(Bt),$(xe,e),e&&t(Jt),e&&t(Je),e&&t(Yt),e&&t(ee),e&&t(Qt),$(Se,e),e&&t(Kt),e&&t(se)}}}const Xr={local:"",sections:[{local:"",title:"\u8BAD\u7EC3\u524D\u7684\u51C6\u5907"},{local:"",title:"\u8BAD\u7EC3\u5FAA\u73AF"},{local:"",title:"\u8BC4\u4F30\u5FAA\u73AF"},{local:"s-accelerate",title:"S\u4F7F\u7528\u{1F917} Accelerate\u52A0\u901F\u60A8\u7684\u8BAD\u7EC3\u5FAA\u73AF"}],title:"\u4E00\u4E2A\u5B8C\u6574\u7684\u8BAD\u7EC3"};function Zr(Ge){return Br(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rp extends Nr{constructor(b){super();Hr(this,b,Zr,Vr,Ir,{})}}export{rp as default,Xr as metadata};
