-
Notifications
You must be signed in to change notification settings - Fork 625
Add "perfectblend" prebaked dataset and "ultrachat" alias #3060
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
Open
kylesayrs
wants to merge
1
commit into
main
Choose a base branch
from
add-perfectblend-prebaked-dataset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| from copy import deepcopy | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from loguru import logger | ||
|
|
||
| from llmcompressor.transformers.data import TextGenerationDataset | ||
| from llmcompressor.typing import Processor | ||
|
|
||
| if TYPE_CHECKING: | ||
| from llmcompressor.args import DatasetArguments | ||
|
|
||
| ROLE_MAP = {"human": "user", "gpt": "assistant"} | ||
|
|
||
|
|
||
| @TextGenerationDataset.register(name="perfectblend") | ||
| class PerfectBlendDataset(TextGenerationDataset): | ||
| """ | ||
| Child text generation class for the open-perfectblend dataset | ||
|
|
||
| :param dataset_args: configuration settings for dataset loading | ||
| :param split: split from dataset to load, for instance `test` or `train[:5%]` | ||
| :param processor: processor or tokenizer to use on dataset | ||
| """ | ||
|
|
||
| DEFAULT_CHAT_TEMPLATE = ( | ||
| "{% for message in messages %}\n" | ||
| "{% if message['role'] == 'user' %}\n" | ||
| "{{ '<|user|>\n' + message['content'] + eos_token }}\n" | ||
| "{% elif message['role'] == 'system' %}\n" | ||
| "{{ '<|system|>\n' + message['content'] + eos_token }}\n" | ||
| "{% elif message['role'] == 'assistant' %}\n" | ||
| "{{ '<|assistant|>\n' + message['content'] + eos_token }}\n" | ||
| "{% endif %}\n" | ||
| "{% if loop.last and add_generation_prompt %}\n" | ||
| "{{ '<|assistant|>' }}\n{% endif %}\n{% endfor %}" | ||
| ) | ||
|
|
||
| def __init__( | ||
| self, dataset_args: "DatasetArguments", split: str, processor: Processor | ||
| ): | ||
| dataset_args = deepcopy(dataset_args) | ||
| dataset_args.dataset = "mlabonne/open-perfectblend" | ||
| dataset_args.text_column = "conversations" | ||
|
|
||
| super().__init__(dataset_args=dataset_args, split=split, processor=processor) | ||
|
|
||
| if ( | ||
| self.tokenizer is not None | ||
| and getattr(self.tokenizer, "chat_template", None) is None | ||
| ): | ||
| self.tokenizer.chat_template = self.DEFAULT_CHAT_TEMPLATE | ||
| logger.warning( | ||
| "tokenizer.chat_template is not set, using default chat template for " | ||
| f"{self.__class__.__name__}" | ||
| ) | ||
|
|
||
| def dataset_template(self, sample): | ||
| messages = [ | ||
| { | ||
| "role": ROLE_MAP.get(msg["from"], msg["from"]), | ||
| "content": msg["value"], | ||
| } | ||
| for msg in sample["conversations"] | ||
| ] | ||
|
|
||
| return { | ||
| "text": self.processor.apply_chat_template( | ||
| messages, tokenize=False, add_generation_prompt=False | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.