Skip to content
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

Precomputation folder name based on model name #196

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions finetrainers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ def collate_fn(batch):
batched_text_conditions[key] = [x[key] for x in text_conditions][0]
return {"latent_conditions": batched_latent_conditions, "text_conditions": batched_text_conditions}

should_precompute = should_perform_precomputation(self.args.data_root)
cleaned_model_id = string_to_filename(self.args.pretrained_model_name_or_path)
precomputation_dir = (
Path(self.args.data_root) / f"{self.args.model_name}_{cleaned_model_id}_{PRECOMPUTED_DIR_NAME}"
)
should_precompute = should_perform_precomputation(precomputation_dir)
if not should_precompute:
logger.info("Precomputed conditions and latents found. Loading precomputed data.")
self.dataloader = torch.utils.data.DataLoader(
Expand Down Expand Up @@ -252,8 +256,8 @@ def collate_fn(batch):
"Caption dropout is not supported with precomputation yet. This will be supported in the future."
)

conditions_dir = Path(self.args.data_root) / PRECOMPUTED_DIR_NAME / PRECOMPUTED_CONDITIONS_DIR_NAME
latents_dir = Path(self.args.data_root) / PRECOMPUTED_DIR_NAME / PRECOMPUTED_LATENTS_DIR_NAME
conditions_dir = precomputation_dir / PRECOMPUTED_CONDITIONS_DIR_NAME
latents_dir = precomputation_dir / PRECOMPUTED_LATENTS_DIR_NAME
conditions_dir.mkdir(parents=True, exist_ok=True)
latents_dir.mkdir(parents=True, exist_ok=True)

Expand Down
12 changes: 6 additions & 6 deletions finetrainers/utils/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

from accelerate.logging import get_logger

from ..constants import PRECOMPUTED_CONDITIONS_DIR_NAME, PRECOMPUTED_DIR_NAME, PRECOMPUTED_LATENTS_DIR_NAME
from ..constants import PRECOMPUTED_CONDITIONS_DIR_NAME, PRECOMPUTED_LATENTS_DIR_NAME


logger = get_logger("finetrainers")


def should_perform_precomputation(data_root: Union[str, Path]) -> bool:
if isinstance(data_root, str):
data_root = Path(data_root)
conditions_dir = data_root / PRECOMPUTED_DIR_NAME / PRECOMPUTED_CONDITIONS_DIR_NAME
latents_dir = data_root / PRECOMPUTED_DIR_NAME / PRECOMPUTED_LATENTS_DIR_NAME
def should_perform_precomputation(precomputation_dir: Union[str, Path]) -> bool:
if isinstance(precomputation_dir, str):
precomputation_dir = Path(precomputation_dir)
conditions_dir = precomputation_dir / PRECOMPUTED_CONDITIONS_DIR_NAME
latents_dir = precomputation_dir / PRECOMPUTED_LATENTS_DIR_NAME
if conditions_dir.exists() and latents_dir.exists():
num_files_conditions = len(list(conditions_dir.glob("*.pt")))
num_files_latents = len(list(latents_dir.glob("*.pt")))
Expand Down