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

P-tuning refactor Part 3/N #6106

Merged
merged 46 commits into from
Feb 24, 2023
Merged

P-tuning refactor Part 3/N #6106

merged 46 commits into from
Feb 24, 2023

Conversation

arendu
Copy link
Collaborator

@arendu arendu commented Feb 24, 2023

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

Signed-off-by: arendu <[email protected]>
@github-actions github-actions bot added the NLP label Feb 24, 2023
@arendu arendu changed the title Adithyare/refac ptuning part3.2 Prompt tuning refactor Part 3/N Feb 24, 2023
@arendu arendu changed the title Prompt tuning refactor Part 3/N P-tuning refactor Part 3/N Feb 24, 2023
@@ -291,7 +291,7 @@ def get_prompt_token_labels_for_megatron_gpt(self, input_ids, num_prompt_tokens)

def get_virtual_prompt_ids_for_megatron_gpt(self, input_ids):
if (
self.cfg.virtual_prompt_style == VirtualPromptStyle.PROMPT_TUNING
self.cfg.virtual_prompt_style == VirtualPromptStyle.P_TUNING
Copy link
Collaborator

Choose a reason for hiding this comment

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

VirtualPromptStyle.PROMPT_TUNING is removed from the enum?

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay. saw it. NVM

total_virtual_tokens=total_virtual_tokens,
token_dim=self.hidden_size,
hidden_size=self.cfg.p_tuning.get("encoder_hidden", 2048),
hidden_size=self.cfg.p_tuning.get("encoder_hidden", self.hidden_size // 2),
Copy link
Collaborator

Choose a reason for hiding this comment

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

is self.hidden_size // 2 a good number to use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a better default, for when the base model has different hidden sizes.

@@ -62,7 +64,7 @@
__all__ = ['MegatronGPTPromptLearningModel']


class MegatronGPTPromptLearningModel(MegatronBaseModel, TextGeneration):
class MegatronGPTPromptLearningModel(MegatronBasePromptLearningModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

why drop the TextGeneration interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The base model containers it now!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The base class now has TextGenetation.

Copy link
Collaborator

@Zhilin123 Zhilin123 left a comment

Choose a reason for hiding this comment

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

LGTM, Great to see a lot of redundant code removed from this PR. Minor stylistic changes, but ok to merge, if you can address them in the next PR

@@ -59,7 +58,9 @@ class MegatronBasePromptLearningModel(MegatronBaseModel, TextGeneration):

def __init__(self, cfg: DictConfig, trainer: Trainer):
super().__init__(cfg, trainer)
self.init_model(cfg, trainer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see here (in the lines above) that you have imports you don't use - maybe remove them in the refactor 4/n ? vscode should be able to identify them

Copy link
Collaborator

Choose a reason for hiding this comment

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

There's quite a few in other files as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed! will do!

raise ValueError(
f"\nvirtual prompt style '{cfg.virtual_prompt_style}' not recognized, please use one of 'prompt-tuning' or 'p-tuning'"
)
raise ValueError(f"\nvirtual prompt style '{cfg.virtual_prompt_style}'")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please indicate what they should use instead. e.g please use p-tuning

@@ -211,68 +170,25 @@ def init_prompt_encoder(self):
new_task = self.new_tasks[0]
total_virtual_tokens = self.task_templates[new_task]["total_virtual_tokens"]

encoder_type = PromptEncoderType(self.cfg.p_tuning.get("encoder_type", "mlp").lower())
encoder_type = PromptEncoderType(self.cfg.p_tuning.get("encoder_type", "tpmlp").lower())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why default was changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No reason, it was during my copy based from the child model.

self.prompt_encoder.load_state_dict(state_dict_, strict)

def embed_input_train(self, input_ids: Tensor, taskname_ids: Tensor):
raise ValueError("invalid virtual prompt source")
Copy link
Collaborator

Choose a reason for hiding this comment

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

please indicate what is the correct config. E.g. please set this cfg.... to p_tuning

@arendu arendu merged commit dabd8b8 into main Feb 24, 2023
@arendu arendu deleted the adithyare/refac_ptuning_part3.2 branch February 24, 2023 21:36
titu1994 pushed a commit to titu1994/NeMo that referenced this pull request Mar 24, 2023
* patch to allow using tokenizers without additional_special_tokens_ids attribute

Signed-off-by: arendu <[email protected]>

* steps to inheret gpt from base

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* steps to inheret gpt from base

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix in pred step

Signed-off-by: arendu <[email protected]>

* moved to base model

Signed-off-by: arendu <[email protected]>

* removing prompt table class moved into prompt encoder class

Signed-off-by: arendu <[email protected]>

* minor fix

Signed-off-by: arendu <[email protected]>

* minor fix

Signed-off-by: arendu <[email protected]>

* changes in dialogue models

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* minor updates to classifications

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: arendu <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
hsiehjackson pushed a commit to hsiehjackson/NeMo that referenced this pull request Jun 2, 2023
* patch to allow using tokenizers without additional_special_tokens_ids attribute

Signed-off-by: arendu <[email protected]>

* steps to inheret gpt from base

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* steps to inheret gpt from base

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix in pred step

Signed-off-by: arendu <[email protected]>

* moved to base model

Signed-off-by: arendu <[email protected]>

* removing prompt table class moved into prompt encoder class

Signed-off-by: arendu <[email protected]>

* minor fix

Signed-off-by: arendu <[email protected]>

* minor fix

Signed-off-by: arendu <[email protected]>

* changes in dialogue models

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* minor updates to classifications

Signed-off-by: arendu <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: arendu <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: hsiehjackson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants