-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaner argument handling & nlp/common/ folder (#16)
By moving the arguments into their own dataclass (available in Python 3.7), we can group certain types of arguments, such as ModelArguments and SageMakerArguments. This lets us consolidate the sagemaker scripts into a single file, and makes the arguments simpler to pass around in functions. Moves several files to common/. Users will need to set PYTHONPATH=/path/to/deep-learning-models/nlp. Also fixes PYTHONPATH to /opt/ml/... in the SageMaker container, so those jobs should run. Also adds support to log hyperparameters in TensorBoard.
- Loading branch information
1 parent
baae6c0
commit f6f74fb
Showing
17 changed files
with
459 additions
and
362 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 was deleted.
Oops, something went wrong.
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,54 @@ | ||
import argparse | ||
import dataclasses | ||
|
||
from transformers import HfArgumentParser | ||
|
||
from common.arguments import ( | ||
DataTrainingArguments, | ||
LoggingArguments, | ||
ModelArguments, | ||
SageMakerArguments, | ||
TrainingArguments, | ||
) | ||
from common.sagemaker_utils import launch_sagemaker_job | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser = HfArgumentParser( | ||
( | ||
ModelArguments, | ||
DataTrainingArguments, | ||
TrainingArguments, | ||
LoggingArguments, | ||
SageMakerArguments, | ||
) | ||
) | ||
model_args, data_args, train_args, log_args, sm_args = parser.parse_args_into_dataclasses() | ||
|
||
hyperparameters = dict() | ||
for args in [model_args, data_args, train_args, log_args]: | ||
for key, value in dataclasses.asdict(args).items(): | ||
if value is not None: | ||
hyperparameters[key] = value | ||
hyperparameters["fsx_prefix"] = "/opt/ml/input/data/training" | ||
|
||
instance_abbr = { | ||
"ml.p3dn.24xlarge": "p3dn", | ||
"ml.p3.16xlarge": "p316", | ||
"ml.g4dn.12xlarge": "g4dn", | ||
}[sm_args.instance_type] | ||
job_name = f"{sm_args.sm_job_name}-{sm_args.instance_count}x{instance_abbr}" | ||
|
||
launch_sagemaker_job( | ||
hyperparameters=hyperparameters, | ||
job_name=job_name, | ||
source_dir=sm_args.source_dir, | ||
entry_point=sm_args.entry_point, | ||
instance_type=sm_args.instance_type, | ||
instance_count=sm_args.instance_count, | ||
role=sm_args.role, | ||
image_name=sm_args.image_name, | ||
fsx_id=sm_args.fsx_id, | ||
subnet_ids=sm_args.subnet_ids, | ||
security_group_ids=sm_args.security_group_ids, | ||
) |
Oops, something went wrong.