深度學(xué)習(xí)自然語言處理 原創(chuàng)
作者:pp
幾天前,OpenAI「超級(jí)對(duì)齊」(Superalignment)團(tuán)隊(duì)發(fā)布了成立以來的首篇論文,聲稱開辟了對(duì)超人類模型進(jìn)行實(shí)證對(duì)齊的新研究方向。GPT-2能監(jiān)督GPT-4,Ilya帶頭OpenAI超級(jí)對(duì)齊首篇論文來了:AI對(duì)齊AI取得實(shí)證結(jié)果
可能是為了讓大家更容易實(shí)現(xiàn)論文中的思路,也可能是為了讓自己的研究更加接地氣,不再被調(diào)侃為“CloseAI”。在公布這篇論文的同時(shí),OpenAI也在GitHub開源了論文提出的"weak-to-strong"框架的代碼[1]
在觀察了倉庫中的代碼之后我們有了如下發(fā)現(xiàn):
既有NLP版本也有CV版本
主代碼倉庫是一個(gè)對(duì)二元分類(binary classification)任務(wù)的“weak-to-strong”方法的實(shí)現(xiàn)。包含用于微調(diào)預(yù)訓(xùn)練語言模型的代碼(訓(xùn)練弱模型,生成若標(biāo)簽),以及針對(duì)來自另一種語言模型的標(biāo)簽進(jìn)行訓(xùn)練的代碼(使用弱標(biāo)簽,訓(xùn)練強(qiáng)學(xué)生)。
Vision目錄中則包含視覺模型"weak-to-strong"的實(shí)現(xiàn)(AlexNet -> DINO)。

支持論文中描述的各種損失函數(shù),如置信度輔助損失函數(shù),也可以自己定義損失函數(shù),見weak_to_strong/loss.py。
#Customlossfunction classxent_loss(LossFnBase): def__call__( self,logits:torch.Tensor,labels:torch.Tensor,step_frac:float )->torch.Tensor: """ Thisfunctioncalculatesthecrossentropylossbetweenlogitsandlabels. Parameters: logits:Thepredictedvalues. labels:Theactualvalues. step_frac:Thefractionoftotaltrainingstepscompleted. Returns: Themeanofthecrossentropyloss. """ loss=torch.nn.functional.cross_entropy(logits,labels) returnloss.mean() classproduct_loss_fn(LossFnBase): ... returnloss.mean() classlogconf_loss_fn(LossFnBase): ... returnloss.mean()
Qwen(千問)模型出現(xiàn)在代碼中
在主文件train_weak_to_strong.py中,OpenAI以自己的GPT2模型,和國產(chǎn)的Qwen(千問)模型為例
ModelConfig(
name="gpt2",
default_lr=5e-5,
eval_batch_size=32,
custom_kwargs={
"bf16":torch.cuda.is_bf16_supported(),
"fp32":nottorch.cuda.is_bf16_supported(),
},
),
ModelConfig(
name="gpt2-medium",
default_lr=5e-5,
eval_batch_size=32,
custom_kwargs={
"bf16":torch.cuda.is_bf16_supported(),
"fp32":nottorch.cuda.is_bf16_supported(),
},
),
...
ModelConfig( name="Qwen/Qwen-7B", default_lr=1e-5, eval_batch_size=2, gradient_checkpointing=True, model_parallel=True, #note:youwillprobablynotbeabletorunthiswithoutmanygpus custom_kwargs={ "trust_remote_code":True, "bf16":torch.cuda.is_bf16_supported(), "fp32":nottorch.cuda.is_bf16_supported(), }, ), ModelConfig( name="Qwen/Qwen-14B", default_lr=1e-5, eval_batch_size=2, gradient_checkpointing=True, model_parallel=True, #note:youwillprobablynotbeabletorunthiswithoutbf16supportandmanygpus custom_kwargs={ "trust_remote_code":True, "bf16":torch.cuda.is_bf16_supported(), "fp32":nottorch.cuda.is_bf16_supported(), }, ), ...
兩階段訓(xùn)練
Weak-to-strong關(guān)注的重點(diǎn)是:一個(gè)弱監(jiān)督者如何監(jiān)督一個(gè)比它聰明得多的模型?為此,OpenAI提出了一個(gè)兩階段的訓(xùn)練方法:
對(duì)于一個(gè)給定的任務(wù):
構(gòu)建弱監(jiān)督者。通過在一半訓(xùn)練數(shù)據(jù)上微調(diào)較小的預(yù)訓(xùn)練模型來構(gòu)造弱監(jiān)督者,他們把弱監(jiān)督者的表現(xiàn)稱為弱表現(xiàn),并通過弱模型的預(yù)測來生成弱標(biāo)簽。(Stage 1)
#Traintheweakmodelonthefirsthalfofthetrainingdata
print(f"Trainingweakmodel,size{weak_model_size}")
weak_test_results,weak_ds=train_model(
weak_model_config,
train1_ds,
test_ds,
loss_type="xent",
label="weak",
subpath=os.path.join("weak_model_gt",weak_model_size.replace("/","_")),
lr=weak_lr,
eval_batch_size=weak_eval_batch_size,
inference_ds=train2_ds,
epochs=gt_epochs,
linear_probe=linear_probe,
optimizer_name=weak_optim,
)
訓(xùn)練一個(gè)用于比較的性能上限的強(qiáng)模型。在另一半訓(xùn)練數(shù)據(jù)上以Ground Truth作為標(biāo)簽訓(xùn)練一個(gè)較大的模型作為比較的上限。(Upper bound)
#Trainthestrongmodelonthesecondhalfofthetrainingdata
print(f"Trainingstrongmodel,size{strong_model_size}")
strong_test_results,_=train_model(
strong_model_config,
train2_ds,
test_ds,
loss_type="xent",
label="strong",
subpath=os.path.join("strong_model_gt",strong_model_size.replace("/","_")),
lr=strong_lr,
eval_batch_size=strong_eval_batch_size,
epochs=gt_epochs,
linear_probe=linear_probe,
optimizer_name=strong_optim,
)
通過第一步中的弱監(jiān)督訓(xùn)練強(qiáng)學(xué)生模型。本文使用生成的弱標(biāo)簽微調(diào)強(qiáng)模型,并將該模型稱為強(qiáng)學(xué)生模型,將其產(chǎn)生的性能稱為從弱到強(qiáng)(weak-to-strong)的性能。(Stage 2)
#Trainthestrongmodelonthesecondhalfofthetrainingdatawithlabelsgeneratedbytheweakmodel
all_transfer_test_results={}
fortlossintransfer_losses:
print(
f"Trainingtransfermodel,size{strong_model_size}onlabelsfrom{weak_model_size},withloss{tloss}"
)
transfer_test_results,_=train_model(
strong_model_config,
weak_ds,
test_ds,
loss_type=tloss,
label="weak2strong",
subpath=os.path.join(
"strong_model_transfer",
f"{weak_model_size.replace('/','_')}_{strong_model_size.replace('/','_')}_{tloss}",
),
lr=transfer_lr,
eval_batch_size=strong_eval_batch_size,
epochs=transfer_epochs,
linear_probe=linear_probe,
optimizer_name=transfer_optim,
)
all_transfer_test_results[tloss]=transfer_test_results
deltransfer_test_results
復(fù)刻版本,并非源碼
OpenAI在倉庫中提到,目前開源的代碼并非與論文實(shí)驗(yàn)部分完全一致,不過是結(jié)果相近的。
"STATUS: This codebase is not well tested and does not use the exact same settings we used in the paper, but in our experience gives qualitatively similar results when using large model size gaps and multiple seeds. Expected results can be found for two datasets below. We may update the code significantly in the coming week."
這次開源的weak-to-strong實(shí)現(xiàn)代碼較為簡單,感興趣的朋友可以去嘗試一下,結(jié)合論文也許會(huì)有不一樣的感受。OpenAI正在大力研究超級(jí)對(duì)齊(Superalignment),不僅僅放出論文,開源代碼,同時(shí)也宣布了一項(xiàng)高達(dá)1000萬美金的資助計(jì)劃,我們將在之后的文章中為您帶來詳細(xì)解讀,敬請(qǐng)期待!
-
開源
+關(guān)注
關(guān)注
3文章
4173瀏覽量
46003 -
模型
+關(guān)注
關(guān)注
1文章
3730瀏覽量
52053 -
OpenAI
+關(guān)注
關(guān)注
9文章
1244瀏覽量
9989
原文標(biāo)題:OpenAI開源"weak-to-strong"方法代碼框架!我們帶你一探究竟
文章出處:【微信號(hào):zenRRan,微信公眾號(hào):深度學(xué)習(xí)自然語言處理】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
如何利用Transformers了解視覺語言模型
__attribute__((weak)) __weak_symbol在idf4.4庫中無效的原因?
在Fast-Strong情況下是否會(huì)出現(xiàn)過多的過沖
keil中__weak的功能和應(yīng)用是什么
__attribute__((weak)) __weak_symbol在idf4.4庫中無效,要怎么操作才能起作用呢?
目標(biāo)跟蹤的視覺注意計(jì)算模型
【MCU】Keil編譯無法識(shí)別__WEAK問題
keil中__weak的功能和應(yīng)用
OpenCV中支持的非分類與檢測視覺模型
基于可變形卷積的大規(guī)模視覺基礎(chǔ)模型
Strong ARM比較器電路的工作原理
?VLM(視覺語言模型)?詳細(xì)解析
視覺模型weak-to-strong的實(shí)現(xiàn)
評(píng)論