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

Minor usability improvements to tinyllama pretraining script #749

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions pretrain/tinyllama.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

global_batch_size = 512
learning_rate = 4e-4
micro_batch_size = 8
max_steps = 715256 * 2
max_tokens = int(3 * 1e12)
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
awaelchli marked this conversation as resolved.
Show resolved Hide resolved
warmup_steps = 2000
log_step_interval = 2
eval_iters = 100
Expand Down Expand Up @@ -67,9 +66,9 @@

def setup(resume: Union[bool, Path] = False):
if use_wandb:
logger = WandbLogger(project="tinyllama", name="training", resume=(resume is not False))
logger = WandbLogger(project="tinyllama", name=name, resume=(resume is not False))
else:
logger = CSVLogger(root_dir="logs", name="tinyllama")
logger = CSVLogger(root_dir="logs", name=name)

if devices > 1:
strategy = FSDPStrategy(
Expand All @@ -78,6 +77,7 @@ def setup(resume: Union[bool, Path] = False):
state_dict_type="full",
limit_all_gathers=True,
cpu_offload=False,
sharding_strategy="HYBRID_SHARD",
)
else:
strategy = "auto"
Expand Down Expand Up @@ -155,6 +155,11 @@ def train(fabric, state, train_dataloader, val_dataloader, resume):
curr_iter = 0

for train_data in train_dataloader:

total_tokens = state["iter_num"] * micro_batch_size * model.config.block_size * fabric.world_size
if state["iter_num"] >= max_iters > 0 or total_tokens >= max_tokens > 0:
break

# resume data loader state by fast-forwarding through all seen batches
# drop this once streaming dataset supports proper resuming
if resume:
Expand All @@ -170,9 +175,6 @@ def train(fabric, state, train_dataloader, val_dataloader, resume):
f"Took {time.perf_counter() - total_t0:.1f} seconds to reach iteration {initial_iter}."
)

if state["iter_num"] >= max_iters:
break

# determine and set the learning rate for this iteration
lr = get_lr(state["iter_num"]) if decay_lr else learning_rate
for param_group in optimizer.param_groups:
Expand Down Expand Up @@ -215,7 +217,7 @@ def train(fabric, state, train_dataloader, val_dataloader, resume):
(t1 - total_t0) / (state["iter_num"] - initial_iter) * (max_iters - state["iter_num"])
),
"tokens": state["iter_num"] * micro_batch_size * model.config.block_size,
"total_tokens": state["iter_num"] * micro_batch_size * model.config.block_size * fabric.world_size,
"total_tokens": total_tokens,
}

fabric.print(
Expand Down
Loading