-
Notifications
You must be signed in to change notification settings - Fork 779
support export cached_dataset #4992
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
Jintao-Huang
wants to merge
14
commits into
modelscope:main
Choose a base branch
from
Jintao-Huang:support_export_bin_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.
+219
−107
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
afa55a2
update
Jintao-Huang b3e883d
update
Jintao-Huang ae035b5
update
Jintao-Huang 36ec88e
update
Jintao-Huang 3cf578a
Merge branch 'main' into support_export_bin_dataset
Jintao-Huang bc55ba4
update
Jintao-Huang b969c0c
Merge branch 'main' into support_export_bin_dataset
Jintao-Huang 344a83c
update
Jintao-Huang 4b3c2dd
update
Jintao-Huang c884045
Merge branch 'main' into support_export_bin_dataset
Jintao-Huang df2a0cb
update
Jintao-Huang b196d2f
fix
Jintao-Huang d48a02d
update
Jintao-Huang 543e91c
update
Jintao-Huang 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
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,35 @@ | ||
# Copyright (c) Alibaba, Inc. and its affiliates. | ||
import os | ||
from typing import List, Union | ||
|
||
from swift.llm import ExportArguments | ||
from swift.llm.train import SwiftSft | ||
from swift.utils import get_logger | ||
|
||
logger = get_logger() | ||
|
||
|
||
class ExportCachedDataset(SwiftSft): | ||
args_class = ExportArguments | ||
args: args_class | ||
|
||
def __init__(self, args: Union[List[str], ExportArguments, None] = None) -> None: | ||
super(SwiftSft, self).__init__(args) | ||
self.train_msg = {} # dummy | ||
self.processor = None | ||
self._prepare_template() | ||
self._prepare_model_tokenizer(load_model=self.template.use_model) | ||
self.template.init_processor(self.processor) | ||
|
||
def main(self): | ||
train_dataset, val_dataset = self._get_dataset() | ||
train_dataset, val_dataset = self._encode_dataset(train_dataset, val_dataset) | ||
self._show_dataset(train_dataset, val_dataset) | ||
train_dataset.save_to_disk(os.path.join(self.args.output_dir, 'train')) | ||
if val_dataset is not None: | ||
val_dataset.save_to_disk(os.path.join(self.args.output_dir, 'val')) | ||
logger.info(f'Dataset saved to `{self.args.output_dir}`') | ||
|
||
|
||
def export_cached_dataset(args: Union[List[str], ExportArguments, None] = None): | ||
return ExportCachedDataset(args).main() |
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
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.
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.
The use of
super(SwiftSft, self)
bypasses theSwiftSft
parent's__init__
to callSwiftPipeline.__init__
. While functional, this is not idiomatic in Python 3 and can be confusing. For better readability, it's recommended to call the grandparent's__init__
explicitly. This makes the intent of skipping the direct parent's initializer clear. You'll need to addfrom swift.llm import SwiftPipeline
to your imports.