-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[Benchmark][New Dataset]Added benchmark support for Unsloth Vision Datasets #19894
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -832,6 +832,66 @@ | |
return sampled_requests | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
# Unsloth Vision Dataset Implementation | ||
# ----------------------------------------------------------------------------- | ||
|
||
class UnslothVisionDataset(HuggingFaceDataset): | ||
""" | ||
Unsloth Vision Dataset. | ||
""" | ||
|
||
DEFAULT_OUTPUT_LEN = 256 | ||
SUPPORTED_DATASET_PATHS = { | ||
"unsloth/LaTeX_OCR": lambda x: ( | ||
"Write the LaTeX representation for this image.", | ||
x["image"] | ||
), | ||
"unsloth/Radiology_mini": lambda x: ( | ||
"You are an expert radiographer. Describe accurately what you see in this image.", | ||
x["image"] | ||
), | ||
} | ||
IS_MULTIMODAL = True | ||
|
||
def sample( | ||
self, | ||
tokenizer: PreTrainedTokenizerBase, | ||
num_requests: int, | ||
output_len: Optional[int] = None, | ||
enable_multimodal_chat: bool = False, | ||
**kwargs, | ||
) -> list: | ||
output_len = output_len if output_len is not None else self.DEFAULT_OUTPUT_LEN | ||
sampled_requests = [] | ||
|
||
parser_fn = self.SUPPORTED_DATASET_PATHS.get(self.dataset_path) | ||
if parser_fn is None: | ||
raise ValueError(f"Unsupported dataset path: {self.dataset_path}") | ||
|
||
for item in self.data: | ||
if len(sampled_requests) >= num_requests: | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
prompt, mm_content = parser_fn(item) | ||
mm_content = process_image(mm_content) | ||
prompt_len = len(tokenizer(prompt).input_ids) | ||
if enable_multimodal_chat: | ||
# Note: when chat is enabled the request prompt_len is no longer | ||
# accurate and we will be using request output to count the | ||
# actual prompt len | ||
prompt = self.apply_multimodal_chat_transformation( | ||
prompt, mm_content) | ||
sampled_requests.append( | ||
SampleRequest( | ||
prompt=prompt, | ||
prompt_len=prompt_len, | ||
expected_output_len=output_len, | ||
multi_modal_data=mm_content, | ||
)) | ||
self.maybe_oversample_requests(sampled_requests, num_requests) | ||
return sampled_requests | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
# Instruct Coder Dataset Implementation | ||
# ----------------------------------------------------------------------------- | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,6 +25,7 @@ | |||||||||||||||||||||
SampleRequest, | ||||||||||||||||||||||
ShareGPTDataset, | ||||||||||||||||||||||
SonnetDataset, | ||||||||||||||||||||||
UnslothVisionDataset, | ||||||||||||||||||||||
VisionArenaDataset, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json | ||||||||||||||||||||||
|
@@ -373,6 +374,12 @@ def get_requests(args, tokenizer): | |||||||||||||||||||||
dataset_cls = AIMODataset | ||||||||||||||||||||||
common_kwargs["dataset_subset"] = None | ||||||||||||||||||||||
common_kwargs["dataset_split"] = "train" | ||||||||||||||||||||||
elif args.dataset_path in UnslothVisionDataset.SUPPORTED_DATASET_PATHS: | ||||||||||||||||||||||
dataset_cls = UnslothVisionDataset | ||||||||||||||||||||||
common_kwargs['dataset_subset'] = None | ||||||||||||||||||||||
common_kwargs['dataset_split'] = args.hf_split | ||||||||||||||||||||||
sample_kwargs["enable_multimodal_chat"] = True | ||||||||||||||||||||||
Comment on lines
+377
to
+381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure that
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
else: | ||||||||||||||||||||||
raise ValueError(f"Unknown dataset name: {args.dataset_name}") | ||||||||||||||||||||||
# Remove None values | ||||||||||||||||||||||
|
@@ -527,6 +534,7 @@ def validate_args(args): | |||||||||||||||||||||
if args.dataset_path in ( | ||||||||||||||||||||||
VisionArenaDataset.SUPPORTED_DATASET_PATHS.keys() | ||||||||||||||||||||||
| ConversationDataset.SUPPORTED_DATASET_PATHS | ||||||||||||||||||||||
| UnslothVisionDataset.SUPPORTED_DATASET_PATHS.keys() | ||||||||||||||||||||||
): | ||||||||||||||||||||||
Comment on lines
534
to
538
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a check to ensure that VisionArenaDataset.SUPPORTED_DATASET_PATHS.keys()
| ConversationDataset.SUPPORTED_DATASET_PATHS
| (UnslothVisionDataset.SUPPORTED_DATASET_PATHS.keys() if args.dataset_path else set()) |
||||||||||||||||||||||
assert args.backend == "vllm-chat", ( | ||||||||||||||||||||||
f"{args.dataset_path} needs to use vllm-chat as the backend." | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to ensure that the length of
self.data
is greater than 0 before proceeding with the sampling process. This would prevent a potentialIndexError
if the dataset is empty.