-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support LLM augmentation ops and support vllm (#338)
* support GenerateInstructionMapper * fix EmptyFormatter * fix extract qa * add op optimize_instruction_mapper and support vllm * fix model infer * update param tensor_parallel_size * add param sampling_params for extract QA op * add param sampling_params * add arg for vllm * add _accelerator * add num_proc=1 for data aug op * optimize codes * update mapper init * fix unittest bug * fix unittest
- Loading branch information
Showing
21 changed files
with
833 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -14,3 +14,4 @@ dist | |
.idea/ | ||
wandb/ | ||
__pycache__ | ||
.vscode/ |
This file contains 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 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 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 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 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 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,84 @@ | ||
from typing import List | ||
|
||
import pandas as pd | ||
import ray | ||
from datasets import Dataset, Features, Value | ||
|
||
from .formatter import FORMATTERS, BaseFormatter | ||
|
||
|
||
@FORMATTERS.register_module() | ||
class EmptyFormatter(BaseFormatter): | ||
""" | ||
The class is used to create empty data. | ||
""" | ||
SUFFIXES = [] | ||
|
||
def __init__(self, length, feature_keys: List[str] = [], *args, **kwargs): | ||
""" | ||
Initialization method. | ||
:param length: The empty dataset length. | ||
:param feature_keys: feature key name list. | ||
""" | ||
self.length = length | ||
self.feature_keys = feature_keys | ||
if isinstance(self.feature_keys, str): | ||
self.feature_keys = [self.feature_keys] | ||
|
||
@property | ||
def null_value(self): | ||
return None | ||
|
||
def load_dataset(self, *args, **kwargs): | ||
data_dict = {} | ||
features = Features() | ||
|
||
for key in self.feature_keys: | ||
features.update({key: Value('string')}) | ||
data_dict.update( | ||
{key: [self.null_value for _ in range(self.length)]}) | ||
|
||
empty_dataset = Dataset.from_dict(data_dict, features=features) | ||
|
||
from data_juicer.core.data import NestedDataset | ||
empty_dataset = NestedDataset(empty_dataset) | ||
|
||
return empty_dataset | ||
|
||
|
||
@FORMATTERS.register_module() | ||
class RayEmptyFormatter(BaseFormatter): | ||
""" | ||
The class is used to create empty data for ray. | ||
""" | ||
SUFFIXES = [] | ||
|
||
def __init__(self, length, feature_keys: List[str] = [], *args, **kwargs): | ||
""" | ||
Initialization method. | ||
:param length: The empty dataset length. | ||
:param feature_keys: feature key name list. | ||
""" | ||
self.length = length | ||
self.feature_keys = feature_keys | ||
if isinstance(self.feature_keys, str): | ||
self.feature_keys = [self.feature_keys] | ||
|
||
@property | ||
def null_value(self): | ||
return {} | ||
|
||
def load_dataset(self, *args, **kwargs): | ||
if len(self.feature_keys): | ||
df = pd.DataFrame({ | ||
col: [self.null_value for _ in range(self.length)] | ||
for col in self.feature_keys | ||
}) | ||
else: | ||
df = pd.DataFrame([self.null_value for _ in range(self.length)]) | ||
|
||
empty_dataset = ray.data.from_pandas(df) | ||
|
||
return empty_dataset |
This file contains 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 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.