-
Notifications
You must be signed in to change notification settings - Fork 282
feat: Omni dataloader for HF models #2016
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| defaults: | ||
| - sft_vlm_3B.yaml | ||
|
|
||
| sft: | ||
| val_batches: 2 | ||
| val_global_batch_size: 8 | ||
|
|
||
| policy: | ||
| max_total_sequence_length: 32768 | ||
| train_global_batch_size: 8 | ||
| dtensor_cfg: | ||
| tensor_parallel_size: 1 | ||
| dynamic_batching: | ||
| enabled: true | ||
| tokenizer: | ||
| video: | ||
| num_frames: 16 | ||
|
|
||
| data: | ||
| # dataset | ||
| train: | ||
| dataset_name: daily-omni | ||
| split: train | ||
| split_validation_size: 0.05 # use 5% of the training data as validation data | ||
| seed: 42 # seed for train/validation split when split_validation_size > 0 | ||
| validation: null | ||
| # default settings for all datasets | ||
| default: | ||
| prompt_file: null | ||
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
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
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,140 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import os | ||
| from typing import Any | ||
|
|
||
| from huggingface_hub import snapshot_download | ||
|
|
||
| from nemo_rl.data.datasets.raw_dataset import RawDataset | ||
| from nemo_rl.data.datasets.utils import ( | ||
| get_huggingface_cache_path, | ||
| load_dataset_from_path, | ||
| ) | ||
|
|
||
|
|
||
| class DailyOmniDataset(RawDataset): | ||
| """Simple wrapper around the Daily-Omni dataset. | ||
|
|
||
| Args: | ||
| split: Split name for the dataset, default is "train" | ||
| """ | ||
yuki-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| task_name = "daily-omni" | ||
|
|
||
| def __init__( | ||
| self, | ||
| split: str = "train", | ||
| split_validation_size: float = 0, | ||
| seed: int = 42, | ||
| **kwargs, | ||
| ): | ||
| # train, valA, and valB are supported splits. | ||
| SPLIT_TO_HF_NAME = { | ||
| "train": "liarliar/Daily-Omni", | ||
| } | ||
| if split not in SPLIT_TO_HF_NAME: | ||
| raise ValueError(f"Invalid split: {split}. Please use 'train'.") | ||
|
|
||
| self.hf_cache_dir = get_huggingface_cache_path(SPLIT_TO_HF_NAME[split]) | ||
| if not self.hf_cache_dir: | ||
| # download the dataset | ||
| self.hf_cache_dir = snapshot_download( | ||
| repo_id=SPLIT_TO_HF_NAME[split], repo_type="dataset" | ||
| ) | ||
| if not self.hf_cache_dir: | ||
| raise ValueError("Cannot download DailyOmniDataset.") | ||
|
|
||
| json_file = os.path.join(self.hf_cache_dir, "qa.json") | ||
|
|
||
| if not os.path.isfile(json_file): | ||
| raise ValueError(f"{json_file} cannot be found.") | ||
|
|
||
| files_folder = os.path.join(self.hf_cache_dir, "Videos") | ||
| if not os.path.isdir(files_folder): | ||
| # prepare the dataset | ||
| # TODO: move untar, unzip func to utils? | ||
| import tarfile | ||
|
|
||
| archive_filename = os.path.join(self.hf_cache_dir, "Videos.tar") | ||
| if not os.path.isfile(archive_filename): | ||
| raise ValueError(f"{archive_filename} cannot be found.") | ||
| try: | ||
| with tarfile.open(archive_filename, "r:*") as tar: | ||
| # Extract all contents to the specified path | ||
| tar.extractall(path=self.hf_cache_dir) | ||
| if os.path.isdir(files_folder): | ||
| print( | ||
| f"Successfully extracted '{archive_filename}' to '{files_folder}'" | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| f"Cannot find the extracted folder {files_folder}. Extraction failed." | ||
| ) | ||
| except tarfile.ReadError: | ||
| raise tarfile.ReadError( | ||
| "Error: Could not read the tar file. It might be corrupted or not a tar file." | ||
| ) | ||
| except Exception as e: | ||
| raise Exception(f"An unexpected error occurred: {e}") | ||
yuki-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| self.dataset = load_dataset_from_path(json_file) | ||
|
|
||
| # format - disable features to avoid schema conflicts | ||
| self.dataset = self.dataset.add_column( | ||
| "task_name", [self.task_name] * len(self.dataset) | ||
| ) | ||
|
|
||
| self.preprocessor = self.format_data | ||
|
|
||
| # `self.val_dataset` is used (not None) only when current dataset is used for both training and validation | ||
| self.val_dataset = None | ||
| self.split_train_validation(split_validation_size, seed) | ||
|
|
||
| @classmethod | ||
| def get_prompt(cls, data: dict[str, Any]) -> str: | ||
| # WARNING: model could have preference of a different prompt | ||
| prompt = data["Question"] + "\n" + "\n".join(data["Choice"]) | ||
| candidate_answers = [chr(ord("A") + idx) for idx in range(len(data["Choice"]))] | ||
| candidate_answers_all_but_last = ",".join(candidate_answers[:-1]) | ||
| prompt += ( | ||
| "\n" | ||
| + "Your replies must contain only a single letter " | ||
| + f"(either {candidate_answers_all_but_last} or {candidate_answers[-1]})." | ||
| ) | ||
| return prompt | ||
|
|
||
| def format_data(self, data: dict[str, Any]) -> dict[str, Any]: | ||
| user_content = [ | ||
| { | ||
| "type": "video", | ||
| "video": os.path.join( | ||
| self.hf_cache_dir, | ||
| "Videos", | ||
| data["video_id"], | ||
| data["video_id"] + "_video.mp4", | ||
| ), | ||
| }, | ||
| { | ||
| "type": "text", | ||
| "text": self.get_prompt(data), | ||
| }, | ||
| ] | ||
| return { | ||
| "messages": [ | ||
| {"role": "user", "content": user_content}, | ||
| {"role": "assistant", "content": data["Answer"]}, | ||
| ], | ||
| "task_name": self.task_name, | ||
| } | ||
Oops, something went wrong.
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.