LLM(大規模言語モデル)のmodulesを見るにはstr(model.moludes)
大規模言語モデルをPEFTでファインチューニングしようとしたとき、target_modulesを指定する箇所があって、その調べ方です。PEFTのサンプルスクリプトの以下の部分です。
q_projとかv_projってなんだと思ったら、モデルを読み込んで、modulesを見ると出てくるものでした。
OPT-6.7Bだと、modulesの冒頭20行はこんな感じ(全体は長いです)。v_proj, q_projというのが見つかりますね!
<bound method Module.modules of OPTForCausalLM(
(model): OPTModel(
(decoder): OPTDecoder(
(embed_tokens): Embedding(50272, 4096, padding_idx=1)
(embed_positions): OPTLearnedPositionalEmbedding(2050, 4096)
(final_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
(layers): ModuleList(
(0): OPTDecoderLayer(
(self_attn): OPTAttention(
(k_proj): Linear8bitLt(in_features=4096, out_features=4096, bias=True)
(v_proj): Linear8bitLt(in_features=4096, out_features=4096, bias=True)
(q_proj): Linear8bitLt(in_features=4096, out_features=4096, bias=True)
(out_proj): Linear8bitLt(in_features=4096, out_features=4096, bias=True)
)
(activation_fn): ReLU()
(self_attn_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
(fc1): Linear8bitLt(in_features=4096, out_features=16384, bias=True)
(fc2): Linear8bitLt(in_features=16384, out_features=4096, bias=True)
(final_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True)
)
(1): OPTDecoderLayer(
もし、別のモデルで同じような個所を探すときのヒントになります。rinna/japanese-gpt-1bでは以下のような感じでした。
<bound method Module.modules of GPT2LMHeadModel(
(transformer): GPT2Model(
(wte): Embedding(44928, 2048)
(wpe): Embedding(1024, 2048)
(drop): Dropout(p=0.1, inplace=False)
(h): ModuleList(
(0): GPT2Block(
(ln_1): LayerNorm((2048,), eps=1e-05, elementwise_affine=True)
(attn): GPT2Attention(
(c_attn): Conv1D()
(c_proj): Conv1D()
(attn_dropout): Dropout(p=0.1, inplace=False)
(resid_dropout): Dropout(p=0.1, inplace=False)
)
(ln_2): LayerNorm((2048,), eps=1e-05, elementwise_affine=True)
(mlp): GPT2MLP(
(c_fc): Conv1D()
(c_proj): Conv1D()
(act): FastGELUActivation()
(dropout): Dropout(p=0.1, inplace=False)
)
)
(1): GPT2Block(
私はrinna/japanese-gpt-1bのPEFTによるファインチューニングにはまだ成功してないのでどこをどうするといいのかは探索中ですが、ちょこちょこ試しているところです。
というわけで、modulesの調べ方のメモでした。
この記事が気に入ったらサポートをしてみませんか?