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

Fix bert example so it is runnable #123

Merged
merged 1 commit into from
Apr 16, 2022
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
2 changes: 2 additions & 0 deletions examples/bert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ python3 examples/bert/run_pretraining.py \
--input_files $OUTPUT_DIR/pretraining-data/ \
--vocab_file $OUTPUT_DIR/bert_vocab_uncased.txt \
--bert_config_file examples/bert/configs/bert_tiny.json \
--num_warmup_steps 20 \
--num_train_steps 200 \
--saved_model_output $OUTPUT_DIR/model/

# Run finetuning.
Expand Down
17 changes: 10 additions & 7 deletions examples/bert/run_pretraining.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@

flags.DEFINE_integer(
"num_warmup_steps",
1e4,
10000,
"The number of warmup steps during which the learning rate will increase "
"till a threshold.",
)

flags.DEFINE_integer(
"num_train_steps",
1e6,
1000000,
"The total fixed number of steps till which the model will train.",
)

Expand Down Expand Up @@ -326,11 +326,14 @@ def __call__(self, step):
is_warmup = step < warmup

# Linear Warmup will be implemented if current step is less than
# `num_warmup_steps`.
if is_warmup:
return peak_lr * (step / warmup)
# else Linear Decay will be implemented
return max(0.0, peak_lr * (training - step) / (training - warmup))
# `num_warmup_steps` else Linear Decay will be implemented.
return tf.cond(
is_warmup,
lambda: peak_lr * (step / warmup),
lambda: tf.math.maximum(
0.0, peak_lr * (training - step) / (training - warmup)
),
)


def decode_record(record):
Expand Down