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

🤏 New models for tests #2287

Merged
merged 73 commits into from
Nov 25, 2024
Merged

🤏 New models for tests #2287

merged 73 commits into from
Nov 25, 2024

Conversation

qgallouedec
Copy link
Member

@qgallouedec qgallouedec commented Oct 27, 2024

What does this PR do?

Fixes #2177

The models currently used for testing lack uniformity and practicality. Specifically:

  • They are sourced from various namespaces (trl-internal-testing, facebook, philschmid, hf-internal-testing, etc.).
  • They are not all small.
  • Their naming conventions are inconsistent (e.g., tiny-random-MistralForCausalLM, dummy-GPT2-correct-vocab, gpt2, pythia-14m).
  • There is no existing script for generating these models.

This PR introduces the following improvements:

  • A script to create tiny models specifically for testing purposes.
  • A uniform naming convention for these models, all placed under a single namespace (trl-internal-testing).

When approved, I'll move every models into trl-internal-testing namespace (instead of qgallouedec). And probably remove all the old testing models in trl-internal-testing.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@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.

@qgallouedec qgallouedec changed the title New models for tests 🤏 New models for tests Nov 10, 2024
Comment on lines -159 to +161
self.assertListEqual(tokenized_dataset["prompt_input_ids"][0], [5377, 11141])
self.assertListEqual(tokenized_dataset["prompt_attention_mask"][0], [1, 1])
self.assertListEqual(tokenized_dataset["answer_input_ids"][0], [318, 1365, 621, 8253, 13])
self.assertListEqual(tokenized_dataset["prompt_input_ids"][0], [31137])
self.assertListEqual(tokenized_dataset["prompt_attention_mask"][0], [1])
self.assertListEqual(tokenized_dataset["answer_input_ids"][0], [374, 2664, 1091, 16965, 13])
Copy link
Member Author

Choose a reason for hiding this comment

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

The tokenizer has changed, so these value have also changed.

Comment on lines -199 to +205
self.assertListEqual(processed_dataset["prompt_input_ids"][0], [50256, 5377, 11141])
self.assertListEqual(processed_dataset["prompt_attention_mask"][0], [1, 1, 1])
self.assertListEqual(processed_dataset["prompt_input_ids"][0], [31137])
self.assertListEqual(processed_dataset["prompt_attention_mask"][0], [1])
self.assertListEqual(
processed_dataset["completion_input_ids"][0], [50256, 5377, 11141, 318, 1365, 621, 8253, 13, 50256]
)
self.assertListEqual(processed_dataset["completion_attention_mask"][0], [1, 1, 1, 1, 1, 1, 1, 1, 1])
self.assertListEqual(
processed_dataset["completion_labels"][0], [-100, -100, -100, 318, 1365, 621, 8253, 13, 50256]
processed_dataset["completion_input_ids"][0], [31137, 374, 2664, 1091, 16965, 13, 151645]
)
self.assertListEqual(processed_dataset["completion_attention_mask"][0], [1, 1, 1, 1, 1, 1, 1])
self.assertListEqual(processed_dataset["completion_labels"][0], [-100, 374, 2664, 1091, 16965, 13, 151645])
Copy link
Member Author

Choose a reason for hiding this comment

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

The tokenizer has changed, so this value has also changed.

Comment on lines 41 to 47
"trl-internal-testing/tiny-random-BartForConditionalGeneration",
"trl-internal-testing/tiny-random-BigBirdPegasusForConditionalGeneration",
"trl-internal-testing/tiny-random-BlenderbotForConditionalGeneration",
"trl-internal-testing/tiny-random-BlenderbotSmallForConditionalGeneration",
"trl-internal-testing/tiny-random-FSMTForConditionalGeneration",
"trl-internal-testing/tiny-random-LEDForConditionalGeneration",
"trl-internal-testing/tiny-random-LongT5ForConditionalGeneration",
"trl-internal-testing/tiny-random-M2M100ForConditionalGeneration",
"trl-internal-testing/tiny-random-MarianMTModel",
"trl-internal-testing/tiny-random-MBartForConditionalGeneration",
"trl-internal-testing/tiny-random-MT5ForConditionalGeneration",
"trl-internal-testing/tiny-random-MvpForConditionalGeneration",
"trl-internal-testing/tiny-random-PegasusForConditionalGeneration",
"trl-internal-testing/tiny-random-PegasusXForConditionalGeneration",
"trl-internal-testing/tiny-random-PLBartForConditionalGeneration",
"trl-internal-testing/tiny-random-ProphetNetForConditionalGeneration",
"trl-internal-testing/tiny-random-SwitchTransformersForConditionalGeneration",
"trl-internal-testing/tiny-random-T5ForConditionalGeneration",
"qgallouedec/tiny-T5ForConditionalGeneration",
"qgallouedec/tiny-BartModel",
Copy link
Member Author

@qgallouedec qgallouedec Nov 20, 2024

Choose a reason for hiding this comment

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

Only use the two most popular enc-dec models

self.model = AutoModelForCausalLM.from_pretrained(self.model_id)
self.ref_model = AutoModelForCausalLM.from_pretrained(self.model_id)
self.reward_model = AutoModelForSequenceClassification.from_pretrained("EleutherAI/pythia-14m", num_labels=1)
self.reward_tokenizer = AutoTokenizer.from_pretrained("EleutherAI/pythia-14m")
self.reward_tokenizer.chat_template = SIMPLE_CHAT_TEMPLATE
Copy link
Member Author

Choose a reason for hiding this comment

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

The model already have a chat template

self.t5_model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
self.t5_tokenizer = AutoTokenizer.from_pretrained(model_id)
self.t5_tokenizer.chat_template = SIMPLE_CHAT_TEMPLATE
Copy link
Member Author

Choose a reason for hiding this comment

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

T5 doesn't have a chat template

self.tokenizer = AutoTokenizer.from_pretrained(self.model_id)
self.tokenizer.chat_template = "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
Copy link
Member Author

@qgallouedec qgallouedec Nov 20, 2024

Choose a reason for hiding this comment

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

The model already has a chat template

self.model = AutoModelForSequenceClassification.from_pretrained(self.model_id)
self.model.config.pad_token_id = self.tokenizer.pad_token_id
Copy link
Member Author

@qgallouedec qgallouedec Nov 20, 2024

Choose a reason for hiding this comment

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

needed for batched forward in the model

@@ -205,6 +205,7 @@ def setUp(self):
ignore_index=self.ignore_index,
)

@unittest.skip("This test must be updated.")
Copy link
Member Author

Choose a reason for hiding this comment

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

This test seems very related to the way the codellama/CodeLlama-7b-Instruct-hf tokenizer works (especially on BOS and EOS) and is not general. It should be rewritten in the future.

Copy link
Member

Choose a reason for hiding this comment

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

That model is largely outdated in any case, so I would be fine to replace it with something more recent / standard like StarCoder2 or QwenCoder / DeepSeekCoder

["trl-internal-testing/tiny-random-paligemma"],
["trl-internal-testing/tiny-random-llava-1.5"],
("qgallouedec/tiny-Idefics2ForConditionalGeneration",),
# ("qgallouedec/tiny-PaliGemmaForConditionalGeneration",),
Copy link
Member Author

@qgallouedec qgallouedec Nov 20, 2024

Choose a reason for hiding this comment

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

paligemma doesn't have a chat template (not meant for chat). We've to find a way to test it. Dedicated method? We can do it in the future

@qgallouedec qgallouedec marked this pull request as ready for review November 20, 2024 23:31
@qgallouedec qgallouedec requested review from lewtun and kashif November 20, 2024 23:32
Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

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

Excellent refactor and massive QoL improvements to the tests @qgallouedec! LGTM with a minor question about whether you want to distinguish between tiny base and instruct models

Copy link
Member

Choose a reason for hiding this comment

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

For reference, we have a similar script in transformers in case you want to see the generic case: https://github.com/huggingface/transformers/blob/a0f4f3174f4aee87dd88ffda95579f7450934fc8/utils/create_dummy_models.py#L1403


# Decoder models
for model_id, config_class, model_class, suffix in [
("bigscience/bloomz-560m", BloomConfig, BloomForCausalLM, None),
Copy link
Member

Choose a reason for hiding this comment

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

After this PR is merged, I would be in favour of just relying on a small, curated set of popular architectures for our tests (e.g. Qwen / Mistral / Llama / Gemma) and remove all the rest where appropriate

Copy link
Member

Choose a reason for hiding this comment

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

Also, is this script supposed to be re-run whenever we add a model to the list? If so, I recommend adding a note either at the top of this script or in our contributor guide

Copy link
Member Author

Choose a reason for hiding this comment

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

of just relying on a small, curated set of popular architectures

Would you remove any model from this list?

supposed to be re-run whenever we add a model

Yes.

adding a note

I added a note in the script in c851842



def push_to_hub(model, tokenizer, suffix=None):
model_class_name = model.__class__.__name__
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it matters much, but this won't make a distinction between base and instruct models as they share the same class. If we don't care about this difference in our tests, no need to change it

Copy link
Member Author

@qgallouedec qgallouedec Nov 25, 2024

Choose a reason for hiding this comment

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

Yes, I wasn't sure what to do about that. Most of our tests are based on Qwen2.5 in its instruct version. So I don't know how compatible the trainers are to non-instruct versions. Let's keep it like this for the moment.

@@ -205,6 +205,7 @@ def setUp(self):
ignore_index=self.ignore_index,
)

@unittest.skip("This test must be updated.")
Copy link
Member

Choose a reason for hiding this comment

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

That model is largely outdated in any case, so I would be fine to replace it with something more recent / standard like StarCoder2 or QwenCoder / DeepSeekCoder

@qgallouedec qgallouedec merged commit 453db5c into main Nov 25, 2024
14 checks passed
@qgallouedec qgallouedec deleted the tiny-models-for-testing branch November 25, 2024 15:31
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.

Drop GPT2 in our test in favour of a more recent instruct model
4 participants