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 15, 2024
1 parent
2f2306f
commit 169907a
Showing
17 changed files
with
173 additions
and
135 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
from .model_name_or_path import ModelNameOrCheckpointPath | ||
from .dataset_config import DatasetConfig | ||
from .model_config import AutoModelConfig | ||
from .quantization_config import QuantizationConfig | ||
from .tokenizer_config import AutoTokenizerConfig | ||
from .trainer_config import TrainerConfig | ||
|
||
__all__ = [ | ||
"ModelNameOrCheckpointPath", | ||
"AutoModelConfig", | ||
"AutoTokenizerConfig", | ||
"DatasetConfig", | ||
"QuantizationConfig", | ||
"TrainerConfig", | ||
] |
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,10 @@ | ||
from flamingo.integrations.wandb import WandbArtifactLink | ||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class DatasetConfig(BaseFlamingoConfig): | ||
"""Settings passed to load a HuggingFace dataset.""" | ||
|
||
artifact: str | WandbArtifactLink | ||
split_size: float | None = None | ||
seed: int | None = 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from pydantic import validator | ||
|
||
from flamingo.integrations.huggingface.utils import is_valid_huggingface_repo_id | ||
from flamingo.integrations.wandb import WandbArtifactLink | ||
from flamingo.types import BaseFlamingoConfig, SerializableTorchDtype | ||
|
||
|
||
class AutoModelConfig(BaseFlamingoConfig): | ||
"""Settings passed to a HuggingFace AutoModel instantiation.""" | ||
|
||
artifact: str | WandbArtifactLink | ||
trust_remote_code: bool = False | ||
torch_dtype: SerializableTorchDtype = None | ||
|
||
@validator("artifact", pre=True, always=True) | ||
def _validate_model_name(cls, v): | ||
if isinstance(v, str) and not is_valid_huggingface_repo_id(v): | ||
raise ValueError(f"{v} is not a valid HuggingFace model name.") | ||
return v |
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,19 @@ | ||
from typing import Any | ||
|
||
from flamingo.types import BaseFlamingoConfig | ||
|
||
|
||
class AutoTokenizerConfig(BaseFlamingoConfig): | ||
"""Settings passed to a HuggingFace AutoTokenizer instantiation.""" | ||
|
||
name: str | ||
trust_remote_code: bool | None = None | ||
use_fast: bool | None = None | ||
|
||
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,41 @@ | ||
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.""" | ||
|
||
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 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
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.
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,6 +1,6 @@ | ||
from .finetuning import run_finetuning | ||
from .lm_harness import run_lm_harness | ||
from .ludwig import run_ludwig | ||
from .simple import run_simple | ||
from .finetuning_job import run_finetuning | ||
from .lm_harness_job import run_lm_harness | ||
from .ludwig_job import run_ludwig | ||
from .simple_job import run_simple | ||
|
||
__all__ = ["run_finetuning", "run_lm_harness", "run_ludwig", "run_simple"] |
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.