Skip to content

Commit

Permalink
edit estimator from PyTorch to HuggingFace
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Zhang committed Sep 10, 2022
1 parent da266d9 commit 952b68e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"source": [
"### Installation\n",
"\n",
"This example notebook requires the **SageMaker Python SDK v2.70.0** and **transformers v4.11.0**."
"This example notebook requires the **SageMaker Python SDK v2.108.0** and **transformers v4.21**."
]
},
{
Expand All @@ -67,7 +67,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install sagemaker botocore boto3 awscli s3fs typing-extensions --upgrade"
"!pip install \"sagemaker>=2.108.0\" botocore boto3 awscli s3fs typing-extensions --upgrade"
]
},
{
Expand All @@ -76,7 +76,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install transformers datasets --upgrade"
"!pip install \"transformers==4.21\" datasets --upgrade"
]
},
{
Expand Down Expand Up @@ -563,11 +563,11 @@
"source": [
"## SageMaker Training Job\n",
"\n",
"To create a SageMaker training job, we use a `PyTorch` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"To create a SageMaker training job, we use a `HuggingFace`/`PyTorch` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"\n",
"When a SageMaker training job starts, SageMaker takes care of starting and managing all the required machine learning instances, picks up the `PyTorch` Deep Learning Container, uploads your training script, and downloads the data from `sagemaker_session_bucket` into the container at `/opt/ml/input/data`.\n",
"When a SageMaker training job starts, SageMaker takes care of starting and managing all the required machine learning instances, picks up the `HuggingFace` Deep Learning Container, uploads your training script, and downloads the data from `sagemaker_session_bucket` into the container at `/opt/ml/input/data`.\n",
"\n",
"In the following section, you learn how to set up two versions of the SageMaker `PyTorch` estimator, a native one without the compiler and an optimized one with the compiler."
"In the following section, you learn how to set up two versions of the SageMaker `HuggingFace`/`PyTorch` estimator, a native one without the compiler and an optimized one with the compiler."
]
},
{
Expand Down Expand Up @@ -668,8 +668,7 @@
"metadata": {},
"outputs": [],
"source": [
"from sagemaker.pytorch import PyTorch\n",
"from sagemaker.training_compiler.config import TrainingCompilerConfig\n",
"from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig\n",
"# an updated max batch size that can fit into GPU memory with compiler\n",
"batch_size = 52\n",
"\n",
Expand Down Expand Up @@ -697,7 +696,7 @@
"metadata": {},
"outputs": [],
"source": [
"compile_estimator = PyTorch(\n",
"compile_estimator = HuggingFace(\n",
" entry_point=\"qa_trainer_huggingface.py\",\n",
" compiler_config=TrainingCompilerConfig(),\n",
" source_dir=\"./scripts\",\n",
Expand All @@ -706,7 +705,7 @@
" role=role,\n",
" py_version=\"py38\",\n",
" transformers_version=\"4.21.1\",\n",
" framework_version=\"1.11.0\",\n",
" pytorch_version=\"1.11.0\",\n",
" volume_size=volume_size,\n",
" hyperparameters=hyperparameters,\n",
" disable_profiler=True,\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
transformers == 4.21.1
accelerate
torch >= 1.3
datasets >= 1.8.0
sentencepiece != 0.1.92
protobuf
evaluate
datasets == 1.18.4
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"source": [
"### Installation\n",
"\n",
"This example notebook requires the **SageMaker Python SDK v2.70.0** and **transformers v4.11.0**."
"This example notebook requires the **SageMaker Python SDK v2.108.0** and **transformers v4.21**."
]
},
{
Expand All @@ -81,7 +81,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install sagemaker botocore boto3 awscli s3fs typing-extensions --upgrade"
"!pip install \"sagemaker>=2.108.0\" botocore boto3 awscli s3fs typing-extensions --upgrade"
]
},
{
Expand All @@ -90,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install transformers datasets --upgrade"
"!pip install \"transformers==4.21\" datasets --upgrade"
]
},
{
Expand Down Expand Up @@ -375,11 +375,11 @@
"source": [
"## SageMaker Training Job\n",
"\n",
"To create a SageMaker training job, we use a `HuggingFace` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"To create a SageMaker training job, we use a `HuggingFace/PyTorch` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"\n",
"When a SageMaker training job starts, SageMaker takes care of starting and managing all the required machine learning instances, picks up the `HuggingFace` Deep Learning Container, uploads your training script, and downloads the data from `sagemaker_session_bucket` into the container at `/opt/ml/input/data`.\n",
"\n",
"In the following section, you learn how to set up two versions of the SageMaker `HuggingFace` estimator, a native one without the compiler and an optimized one with the compiler."
"In the following section, you learn how to set up two versions of the SageMaker `HuggingFace/PyTorch` estimator, a native one without the compiler and an optimized one with the compiler."
]
},
{
Expand Down Expand Up @@ -472,8 +472,7 @@
"metadata": {},
"outputs": [],
"source": [
"from sagemaker.pytorch import PyTorch\n",
"from sagemaker.training_compiler.config import TrainingCompilerConfig\n",
"from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig\n",
"\n",
"hyperparameters = {\n",
" \"epochs\": 5,\n",
Expand All @@ -500,7 +499,7 @@
"\n",
"# Importantly, the TrainingCompilerConfig() is passed below to enable the SageMaker Training Compiler\n",
"\n",
"sm_training_compiler_estimator = PyTorch(\n",
"sm_training_compiler_estimator = HuggingFace(\n",
" entry_point=\"train.py\",\n",
" source_dir=\"./scripts\",\n",
" instance_type=\"ml.p3.2xlarge\",\n",
Expand All @@ -510,7 +509,7 @@
" base_job_name=\"sm-compiled-sst-bert-base-cased-p3-2x-pytorch-190\",\n",
" volume_size=volume_size,\n",
" transformers_version=\"4.21.1\",\n",
" framework_version=\"1.11.0\",\n",
" pytorch_version=\"1.11.0\",\n",
" compiler_config=TrainingCompilerConfig(),\n",
" hyperparameters=hyperparameters,\n",
" disable_profiler=True,\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
transformers == 4.21.1
accelerate
torch >= 1.3
datasets >= 1.8.0
sentencepiece != 0.1.92
protobuf
evaluate
datasets == 1.18.4
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"source": [
"### Installation\n",
"\n",
"This example notebook requires the **SageMaker Python SDK v2.70.0** and **transformers v4.11.0**."
"This example notebook requires the **SageMaker Python SDK v2.108.0** and **transformers v4.21**."
]
},
{
Expand All @@ -67,7 +67,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install sagemaker botocore boto3 awscli --upgrade"
"!pip install \"sagemaker>=2.108.0\" botocore boto3 awscli --upgrade"
]
},
{
Expand All @@ -76,7 +76,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install -U transformers datasets --upgrade"
"!pip install -U \"transformers==4.21.1\" datasets --upgrade"
]
},
{
Expand Down Expand Up @@ -284,11 +284,11 @@
"source": [
"## SageMaker Training Job\n",
"\n",
"To create a SageMaker training job, we use a `HuggingFace` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"To create a SageMaker training job, we use a `HuggingFace/PyTorch` estimator. Using the estimator, you can define which fine-tuning script should SageMaker use through `entry_point`, which `instance_type` to use for training, which `hyperparameters` to pass, and so on.\n",
"\n",
"When a SageMaker training job starts, SageMaker takes care of starting and managing all the required machine learning instances, picks up the `HuggingFace` Deep Learning Container, uploads your training script, and downloads the data from `sagemaker_session_bucket` into the container at `/opt/ml/input/data`.\n",
"\n",
"In the following section, you learn how to set up two versions of the SageMaker `HuggingFace` estimator, a native one without the compiler and an optimized one with the compiler."
"In the following section, you learn how to set up two versions of the SageMaker `HuggingFace/PyTorch` estimator, a native one without the compiler and an optimized one with the compiler."
]
},
{
Expand Down Expand Up @@ -349,7 +349,6 @@
"metadata": {},
"outputs": [],
"source": [
"#from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig\n",
"from sagemaker.pytorch import PyTorch\n",
"\n",
"# hyperparameters, which are passed into the training job\n",
Expand Down Expand Up @@ -420,9 +419,7 @@
"# If checkpointing is enabled with higher epoch numbers, your disk requirements will increase as well\n",
"volume_size = 60 + 2 * hyperparameters[\"epochs\"]\n",
"\n",
"from sagemaker.training_compiler.config import TrainingCompilerConfig\n",
"\n",
"hyperparameters[TrainingCompilerConfig.HP_ENABLE_COMPILER] = True"
"from sagemaker.huggingface import HuggingFace, TrainingCompilerConfig"
]
},
{
Expand All @@ -431,24 +428,21 @@
"metadata": {},
"outputs": [],
"source": [
"TRCOMP_IMAGE_URI = '669063966089.dkr.ecr.us-west-2.amazonaws.com/pr-huggingface-pytorch-trcomp-training:1.11.0-transformers4.21.1-gpu-py38-cu113-ubuntu20.04-pr-2032'\n",
"\n",
"# configure the training job\n",
"optimized_estimator = PyTorch(\n",
"optimized_estimator = HuggingFace(\n",
" entry_point=TRAINING_SCRIPT,\n",
" #compiler_config=TrainingCompilerConfig(),\n",
" compiler_config=TrainingCompilerConfig(),\n",
" source_dir=\"./scripts\",\n",
" instance_type=INSTANCE_TYPE,\n",
" instance_count=1,\n",
" role=role,\n",
" py_version=\"py38\",\n",
" transformers_version=\"4.21.1\",\n",
" framework_version=\"1.11.0\",\n",
" pytorch_version=\"1.11.0\",\n",
" volume_size=volume_size,\n",
" hyperparameters=hyperparameters,\n",
" disable_profiler=True,\n",
" debugger_hook_config=False,\n",
" image_uri=TRCOMP_IMAGE_URI,\n",
")\n",
"\n",
"# start training with our uploaded datasets as input\n",
Expand Down Expand Up @@ -841,6 +835,13 @@
"source": [
"Also, to find instructions on cleaning up resources, see [Clean Up](https://docs.aws.amazon.com/sagemaker/latest/dg/ex1-cleanup.html) in the *Amazon SageMaker Developer Guide*."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
transformers == 4.21.1
accelerate
torch >= 1.3
datasets >= 1.8.0
sentencepiece != 0.1.92
protobuf
evaluate
datasets == 1.18.4

0 comments on commit 952b68e

Please sign in to comment.