Skip to content

Commit

Permalink
Another one
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerzr committed Aug 15, 2023
1 parent 8c599b6 commit 3e3e1ee
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/pytorch/image-pretraining/run_mae.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ class CustomTrainingArguments(TrainingArguments):
default=1e-3, metadata={"help": "Base learning rate: absolute_lr = base_lr * total_batch_size / 256."}
)

def __post_init__(self):
# Compute absolute learning rate while args are mutable
if self.base_learning_rate is not None:
total_train_batch_size = self.train_batch_size * self.gradient_accumulation_steps * self.world_size
self.learning_rate = self.base_learning_rate * total_train_batch_size / 256
super().__post_init__()


def collate_fn(examples):
pixel_values = torch.stack([example["pixel_values"] for example in examples])
Expand Down Expand Up @@ -353,13 +360,6 @@ def preprocess_images(examples):
# Set the validation transforms
ds["validation"].set_transform(preprocess_images)

# Compute absolute learning rate
total_train_batch_size = (
training_args.train_batch_size * training_args.gradient_accumulation_steps * training_args.world_size
)
if training_args.base_learning_rate is not None:
training_args.learning_rate = training_args.base_learning_rate * total_train_batch_size / 256

# Initialize our trainer
trainer = Trainer(
model=model,
Expand Down

0 comments on commit 3e3e1ee

Please sign in to comment.