generated from allenai/python-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add adam training * fix tests for new decoding api
- Loading branch information
Showing
14 changed files
with
149 additions
and
33 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
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,24 @@ | ||
# T5.1.1 Base model. | ||
from __gin__ import dynamic_registration | ||
|
||
from t5x import adafactor | ||
from t5x import optimizers | ||
from hyper_task_descriptions import utils as hyper_utils | ||
|
||
# gin that allows partial training based on regex matching. | ||
|
||
# ------------------- Partial loading ------------------------------------------------ | ||
OPTIMIZER = @optimizers.MultiOptimizer() | ||
# note you can add more traversals if you want different optimizer settings | ||
# for dfferent parts of the model. | ||
# See https://github.com/google-research/t5x/blob/main/docs/usage/gin.md#scoping | ||
# for how to create multiple specialised instances of the same class. | ||
optimizers.MultiOptimizer: | ||
traversals_and_optimizers = ((@optim.ModelParamTraversal(), | ||
@adafactor.Adafactor()),) | ||
optim.ModelParamTraversal: | ||
filter_fn = @hyper_utils.match_any() | ||
# MultiOptimizer will match any parameter with a flattened name that | ||
# matches *any* of the regular expressions in the list. | ||
PROMPT_REGEX = [".*/hyper/.*"] | ||
hyper_utils.match_any.regexes = %PROMPT_REGEX |
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,38 @@ | ||
from __gin__ import dynamic_registration | ||
|
||
import optax | ||
from t5x import utils | ||
|
||
from hyper_task_descriptions import utils as hyper_utils | ||
|
||
|
||
# multi optimizer - we map anything that matches param_labels to adamw, others dont train | ||
# note we use optaxs way of doing things here - the t5x multoptimizer didnt work for some | ||
# reason. | ||
OPTIMIZER = @hyper_utils.multi_transform() | ||
hyper_utils.multi_transform: | ||
transforms = {"train": @optax.adam(), "freeze": @optax.set_to_zero()} | ||
param_labels = @hyper_utils.match_any_optax() | ||
|
||
# we only train params that match this regex | ||
hyper_utils.match_any_optax.regexes = [".*hyper.*"] | ||
|
||
optax.adam: | ||
learning_rate = @utils.create_learning_rate_scheduler() | ||
# adamw params below. See https://optax.readthedocs.io/en/latest/api.html#optax.adamw | ||
# weight_decay = 0 | ||
# mask = @hyper_utils.match_any_optax_inverse() | ||
|
||
# for adamw, a common case is not applying wd to layer norms and biases (but no bias in t5) | ||
#hyper_utils.match_any_optax_inverse.regexes = [".*/LayerNorm/.*"] | ||
|
||
|
||
# WARNING: t5x will log starting from the pretrained model step, | ||
# but optax calls this starting from 0. So ignore the tensorboard | ||
# learning rate logging. | ||
utils.create_learning_rate_scheduler: | ||
factors = 'constant * linear_warmup' | ||
base_learning_rate = 1e-5 | ||
warmup_steps = 1000 | ||
step_offset = 0 # our steps start at 0 no matter what with optax. | ||
|
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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# name of experiment folder | ||
EXPERIMENT_NAME=$1 | ||
|
||
# where model will be saved | ||
MODEL_DIR="gs://hamishi-us-bucket/${EXPERIMENT_NAME}/model" | ||
|
||
# we go offline to avoid constant calls to get basic info (happens even when cached) | ||
# for your first run, you will probably need to run all these calls :( | ||
HF_DATASETS_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python3 -m t5x.train \ | ||
--gin_search_paths=gins \ | ||
--gin_file="hyper_xl.gin" \ | ||
--gin_file="t0_train.gin" \ | ||
--gin_file="partial_train_adam.gin" \ | ||
--gin.MODEL_DIR=\"${MODEL_DIR}\" \ | ||
--gin.TRAIN_STEPS=1212200 \ | ||
--gin.partitioning.PjitPartitioner.num_partitions=8 \ | ||
--gin.INITIAL_CHECKPOINT_PATH=\"gs://t5-data/pretrained_models/t5x/t5_1_1_lm100k_xl/checkpoint_1100000\" \ | ||
--tfds_data_dir="gs://hamishi-us-bucket/t0_data/data" |
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