-
Notifications
You must be signed in to change notification settings - Fork 80
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
allow mixture components to override cache_dir #754
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 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 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 |
---|---|---|
|
@@ -524,13 +524,18 @@ def fsspec_expand_glob(url): | |
return urls | ||
|
||
|
||
@dataclass | ||
class LMDatasetMixtureComponentConfig(LMDatasetSourceConfig): | ||
cache_dir: Optional[str] = None # Optionally override the cache dir for this component | ||
|
||
|
||
@dataclass | ||
class LMTaskConfig(abc.ABC): | ||
tokenizer: str = "gpt2" | ||
vocab_size: Optional[int] = None # if using the passthrough tokenizer, this is required | ||
|
||
# config related to caching | ||
cache_dir: str = "cache/" | ||
cache_dir: Optional[str] = "cache/" | ||
cache_options: CacheOptions = field(default_factory=CacheOptions) | ||
enforce_eos: bool = True # whether to append eos even if the tokenizer doesn't | ||
|
||
|
@@ -560,7 +565,7 @@ def validation_sets( | |
|
||
@property | ||
@abc.abstractmethod | ||
def sources(self) -> dict[str, LMDatasetSourceConfig]: | ||
def sources(self) -> Mapping[str, LMDatasetSourceConfig]: | ||
pass | ||
|
||
def tagged_eval_sets( | ||
|
@@ -605,7 +610,7 @@ def validation_sets( | |
return {} | ||
|
||
@property | ||
def sources(self) -> dict[str, LMDatasetSourceConfig]: | ||
def sources(self) -> Mapping[str, LMDatasetSourceConfig]: | ||
return {"": self} | ||
|
||
@cached_property | ||
|
@@ -634,6 +639,9 @@ def token_seq_dataset( | |
def build_or_load_cache( | ||
self, split: str, monitors: Union[bool, List[MetricsMonitor]] = True, logger_name: Optional[str] = None | ||
) -> Optional[TreeCache[BatchEncoding]]: | ||
if self.cache_dir is None: | ||
raise ValueError("cache_dir cannot be None") | ||
|
||
split_cache_dir = os.path.join(self.cache_dir, split) | ||
name = logger_name or os.path.basename(self.cache_dir) | ||
|
||
|
@@ -702,7 +710,7 @@ class LMMixtureDatasetConfig(LMTaskConfig): | |
"""This class represents a mixture of datasets with their associated weights.""" | ||
|
||
# data source configs and weights | ||
configs: Dict[str, LMDatasetSourceConfig] = field(default_factory=dict) | ||
configs: Dict[str, LMDatasetMixtureComponentConfig] = field(default_factory=dict) | ||
""" configuration of each dataset source (urls, hf dataset id, etc.) """ | ||
train_weights: Dict[str, float] = field(default_factory=dict) | ||
""" weights for each dataset source. They will be normalized to sum to 1. """ | ||
|
@@ -788,10 +796,23 @@ def build_caches( | |
if weight == 0 and split == "train": | ||
continue | ||
|
||
source_config_dict = source_config.__dict__ | ||
source_config_dict = dict(**source_config.__dict__) | ||
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. Add comment on why we need to delete it - to make the LMDatasetMixtureComponentConfig act like a LMDatasetSourceConfig? 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. more or less. i also cleaned this part up a bit |
||
if "cache_dir" in source_config_dict: | ||
del source_config_dict["cache_dir"] | ||
|
||
if source_config.cache_dir is not None: | ||
cache_dir = source_config.cache_dir | ||
else: | ||
if self.cache_dir is None: | ||
raise ValueError( | ||
"If the 'main' cache_dir is None, then all component cache_dirs must be non-None, but" | ||
f"{name}'s cache_dir is None." | ||
) | ||
|
||
cache_dir = os.path.join(self.cache_dir, name) | ||
|
||
dataset = LMDatasetConfig( | ||
cache_dir=os.path.join(self.cache_dir, name), | ||
cache_dir=cache_dir, | ||
**source_config_dict, | ||
**task_config_dict, | ||
) | ||
|
@@ -813,5 +834,5 @@ def build_caches( | |
return caches | ||
|
||
@property | ||
def sources(self) -> dict[str, LMDatasetSourceConfig]: | ||
def sources(self) -> Mapping[str, LMDatasetSourceConfig]: | ||
return self.configs |
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.
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 only thing different between the base and derived class is cache_dir? Seems weird since this on the surface doesn't seem to relate to mixtures...
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.
yeah i can just put it in the base i guess