Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IA3 Modules for Phi #1407

Merged
merged 2 commits into from
Jan 30, 2024
Merged

Add IA3 Modules for Phi #1407

merged 2 commits into from
Jan 30, 2024

Conversation

arnavgarg1
Copy link
Contributor

Here's what the model architecture looks like with my proposed target modules:

>>> get_peft_model(model, ia3_config)
PeftModelForCausalLM(
  (base_model): IA3Model(
    (model): PhiForCausalLM(
      (model): PhiModel(
        (embed_tokens): Embedding(51200, 2560)
        (embed_dropout): Dropout(p=0.0, inplace=False)
        (layers): ModuleList(
          (0-31): 32 x PhiDecoderLayer(
            (self_attn): PhiAttention(
              (q_proj): Linear(
                (base_layer): Linear(in_features=2560, out_features=2560, bias=True)
                (ia3_l): ParameterDict(  (default): Parameter containing: [torch.FloatTensor of size 2560x1])
              )
              (k_proj): Linear(in_features=2560, out_features=2560, bias=True)
              (v_proj): Linear(
                (base_layer): Linear(in_features=2560, out_features=2560, bias=True)
                (ia3_l): ParameterDict(  (default): Parameter containing: [torch.FloatTensor of size 2560x1])
              )
              (dense): Linear(in_features=2560, out_features=2560, bias=True)
              (rotary_emb): PhiRotaryEmbedding()
            )
            (mlp): PhiMLP(
              (activation_fn): NewGELUActivation()
              (fc1): Linear(
                (base_layer): Linear(in_features=2560, out_features=10240, bias=True)
                (ia3_l): ParameterDict(  (default): Parameter containing: [torch.FloatTensor of size 1x2560])
              )
              (fc2): Linear(
                (base_layer): Linear(in_features=10240, out_features=2560, bias=True)
                (ia3_l): ParameterDict(  (default): Parameter containing: [torch.FloatTensor of size 1x10240])
              )
            )
            (input_layernorm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
            (resid_dropout): Dropout(p=0.1, inplace=False)
          )
        )
        (final_layernorm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
      )
      (lm_head): Linear(in_features=2560, out_features=51200, bias=True)
    )
  )
)

This is the total number of trainable parameters using the default rank:

trainable params: 573,440 || all params: 2,780,257,280 || trainable%: 0.020625429312786478

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot ! 🚀

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @arnavgarg1, as per the T-few/IA3 paper, only fc2 feedforward layer would be considered. Therefore, left suggestions accordingly. Thank you for adding the target modules when using IA3 for Phi models!

@@ -99,6 +99,7 @@ def starcoder_model_postprocess_past_key_value(past_key_values):
"RefinedWebModel": ["query_key_value", "dense_4h_to_h"],
"RefinedWeb": ["query_key_value", "dense_4h_to_h"],
"falcon": ["query_key_value", "dense_4h_to_h"],
"phi": ["q_proj", "v_proj", "fc1", "fc2"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"phi": ["q_proj", "v_proj", "fc1", "fc2"],
"phi": ["q_proj", "v_proj", "fc2"],

@@ -121,6 +122,7 @@ def starcoder_model_postprocess_past_key_value(past_key_values):
"RefinedWeb": ["dense_4h_to_h"],
"RefinedWebModel": ["dense_4h_to_h"],
"falcon": ["dense_4h_to_h"],
"phi": ["fc1", "fc2"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"phi": ["fc1", "fc2"],
"phi": ["fc2"],

@arnavgarg1 arnavgarg1 requested a review from pacman100 January 30, 2024 10:17
@arnavgarg1
Copy link
Contributor Author

Hi @pacman100! Thanks for the great catch - totally agree that this should only be applied to the fc2 feedforward layer. I just updated my PR!

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@pacman100 pacman100 merged commit 68b90a1 into huggingface:main Jan 30, 2024
14 checks passed
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
* Add IA3 Modules for Phi

* Address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants