This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sean Friedowitz
committed
Jan 17, 2024
1 parent
7200af9
commit d726bfc
Showing
19 changed files
with
275 additions
and
172 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from pydantic import validator | ||
|
||
from flamingo.integrations.huggingface.utils import repo_id_validator | ||
from flamingo.integrations.wandb import WandbArtifactLink | ||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class DatasetConfig(BaseFlamingoConfig): | ||
"""Settings passed to load a HuggingFace dataset.""" | ||
|
||
path: str | WandbArtifactLink | ||
split: str | None = None | ||
test_size: float | None = None | ||
seed: int | None = None | ||
|
||
_path_validator = validator("path", allow_reuse=True, pre=True)(repo_id_validator) |
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,19 @@ | ||
from pydantic import validator | ||
|
||
from flamingo.integrations.huggingface.utils import repo_id_validator | ||
from flamingo.integrations.wandb import WandbArtifactLink | ||
from flamingo.types import BaseFlamingoConfig, SerializableTorchDtype | ||
|
||
|
||
class AutoModelConfig(BaseFlamingoConfig): | ||
"""Settings passed to a HuggingFace AutoModel instantiation. | ||
The model path can either be a string corresponding to a HuggingFace repo ID, | ||
or an artifact link to a reference artifact on W&B. | ||
""" | ||
|
||
path: str | WandbArtifactLink | ||
trust_remote_code: bool = False | ||
torch_dtype: SerializableTorchDtype = None | ||
|
||
_path_validator = validator("path", allow_reuse=True, pre=True)(repo_id_validator) |
34 changes: 0 additions & 34 deletions
34
src/flamingo/integrations/huggingface/model_name_or_path.py
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
from typing import Any | ||
|
||
from pydantic import validator | ||
|
||
from flamingo.integrations.huggingface.utils import repo_id_validator | ||
from flamingo.integrations.wandb import WandbArtifactLink | ||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class AutoTokenizerConfig(BaseFlamingoConfig): | ||
"""Settings passed to a HuggingFace AutoTokenizer instantiation.""" | ||
|
||
path: str | WandbArtifactLink | ||
trust_remote_code: bool | None = None | ||
use_fast: bool | None = None | ||
|
||
_path_validator = validator("path", allow_reuse=True, pre=True)(repo_id_validator) | ||
|
||
def get_tokenizer_args(self) -> dict[str, Any]: | ||
args = dict( | ||
trust_remote_code=self.trust_remote_code, | ||
use_fast=self.use_fast, | ||
) | ||
# Only return non-None values so we get HuggingFace defaults when not specified | ||
return {k: v for k, v in args.items() if v is not None} |
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 |
---|---|---|
@@ -1,21 +1,45 @@ | ||
from flamingo.types import BaseFlamingoConfig, SerializableTorchDtype | ||
from typing import Any | ||
|
||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class TrainerConfig(BaseFlamingoConfig): | ||
"""Configuration for a HuggingFace trainer/training arguments.""" | ||
"""Configuration for a HuggingFace trainer/training arguments. | ||
This mainly encompasses arguments passed to the HuggingFace `TrainingArguments` class, | ||
but also contains some additional parameters for the `Trainer` or `SFTTrainer` classes. | ||
""" | ||
|
||
max_seq_length: int | None = None | ||
num_train_epochs: int = 1 | ||
batch_size: int = 16 | ||
learning_rate: float = 1e-5 | ||
weight_decay: float = 1e-3 | ||
gradient_accumulation_steps: int = 1 | ||
gradient_checkpointing: bool = False | ||
trust_remote_code: bool = False | ||
torch_dtype: SerializableTorchDtype = None | ||
evaluation_strategy: str = "epoch" | ||
num_train_epochs: int | None = None | ||
per_device_train_batch_size: int | None = None | ||
per_device_eval_batch_size: int | None = None | ||
learning_rate: float | None = None | ||
weight_decay: float | None = None | ||
gradient_accumulation_steps: int | None = None | ||
gradient_checkpointing: bool | None = None | ||
evaluation_strategy: str | None = None | ||
eval_steps: float | None = None | ||
logging_strategy: str = "steps" | ||
logging_steps: float = 100 | ||
save_strategy: str = "steps" | ||
save_steps: int = 500 | ||
logging_strategy: str | None = None | ||
logging_steps: float | None = None | ||
save_strategy: str | None = None | ||
save_steps: int | None = None | ||
|
||
def get_training_args(self) -> dict[str, Any]: | ||
args = dict( | ||
num_train_epochs=self.num_train_epochs, | ||
learning_rate=self.learning_rate, | ||
per_device_train_batch_size=self.per_device_train_batch_size, | ||
per_device_eval_batch_size=self.per_device_eval_batch_size, | ||
gradient_accumulation_steps=self.gradient_accumulation_steps, | ||
gradient_checkpointing=self.gradient_checkpointing, | ||
weight_decay=self.weight_decay, | ||
evaluation_strategy=self.evaluation_strategy, | ||
eval_steps=self.eval_steps, | ||
logging_strategy=self.logging_strategy, | ||
logging_steps=self.logging_steps, | ||
save_strategy=self.save_strategy, | ||
save_steps=self.save_steps, | ||
) | ||
# Only return non-None values so we use the HuggingFace defaults when not specified | ||
return {k: v for k, v in args.items() if v is not None} |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from .wandb_environment import WandbEnvironment # noqa: I001 | ||
from .artifact_link import WandbArtifactLink | ||
from .run_link import WandbRunLink | ||
from .utils import get_wandb_summary, update_wandb_summary | ||
|
||
__all__ = [ | ||
"WandbEnvironment", | ||
"WandbArtifactLink", | ||
"WandbRunLink", | ||
"get_wandb_summary", | ||
"update_wandb_summary", | ||
] |
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,17 @@ | ||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class WandbArtifactLink(BaseFlamingoConfig): | ||
"""Data required to retrieve an artifact from W&B.""" | ||
|
||
name: str | ||
version: str = "latest" | ||
project: str | None = None | ||
entity: str | None = None | ||
|
||
@property | ||
def wandb_path(self) -> str: | ||
"""String identifier for the asset on the W&B platform.""" | ||
path = "/".join(x for x in [self.entity, self.project, self.name] if x is not None) | ||
path = f"{path}:{self.version}" | ||
return path |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.