UnexpectedStatusException: Error for Training job sagemaker-pytorch-Failed. Reason: AlgorithmError: framework error:
whenever I try to train my model by creating Jupyter notebook instance in Sagemaker my training jobs gets failed and I get below error. The hyperparameters passed to training script is as follows:
from sagemaker.pytorch import PyTorch
estimator = PyTorch(entry_point="train.py",
source_dir="train",
role=role,
framework_version='0.4.0',
train_instance_count=1,
train_instance_type='ml.p2.xlarge',
hyperparameters={
'epochs': 10,
'hidden_dim': 200,
})
Error:
UnexpectedStatusException: Error for Training job sagemaker-pytorch-2020-05-18-15-06-40-726: Failed. Reason: AlgorithmError: framework error:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/sagemaker_containers/_trainer.py", line 76, in train
entrypoint()
File "/usr/local/lib/python3.6/dist-packages/sagemaker_pytorch_container/training.py", line 98, in main
train(framework.training_env())
File "/usr/local/lib/python3.6/dist-packages/sagemaker_pytorch_container/training.py", line 52, in train
capture_error=True)
File "/usr/local/lib/python3.6/dist-packages/sagemaker_containers/_modules.py", line 274, in run_module
files.download_and_extract(uri, env.code_dir)
File "/usr/local/lib/python3.6/dist-packages/sagemaker_containers/_files.py", line 124, in download_and_extract
s3_download(uri, dst)
File "/usr/local/lib/python3.6/dist-packages/sagemaker_containers/_files.py", line 159, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/usr/local/lib/python3.6/dist-packages/boto3/s3/inject.py", line 246, in bucket_download_file
ExtraArgs=
hi @Vertika09, could you include your full stacktrace and error message? From what you've provided, it looks like something went wrong with downloading from S3, but there's no way to tell what happened beyond that based on the information you've provided.
@laurenyu hi pls find the stacktrace and error below.
2020-05-27 12:11:57 Starting - Starting the training job...
2020-05-27 12:11:59 Starting - Launching requested ML instances.........
2020-05-27 12:13:40 Starting - Preparing the instances for training.........
2020-05-27 12:15:10 Downloading - Downloading input data...
2020-05-27 12:15:52 Training - Downloading the training image...........bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
2020-05-27 12:17:39,277 sagemaker-containers INFO Imported framework sagemaker_pytorch_container.training
2020-05-27 12:17:39,304 sagemaker_pytorch_container.training INFO Block until all host DNS lookups succeed.
2020-05-27 12:17:39,308 sagemaker_pytorch_container.training INFO Invoking user training script.
2020-05-27 12:17:39,523 sagemaker-containers ERROR Reporting training FAILURE
2020-05-27 12:17:39,523 sagemaker-containers ERROR framework error:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train
entrypoint()
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main
train(framework.training_env())
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
framework.modules.download_and_install(training_environment.module_dir)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_modules.py", line 159, in download_and_install
_files.download_and_extract(uri, module_path)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 129, in download_and_extract
s3_download(uri, dst)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 165, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 246, in bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/opt/conda/lib/python3.6/site-packages/s3transfer/tasks.py", line 255, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/s3transfer/download.py", line 343, in _submit
**transfer_future.meta.call_args.extra_args
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 599, in _make_api_call
api_params, operation_model, context=request_context)
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 647, in _convert_to_request_dict
api_params, operation_model)
File "/opt/conda/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
2020-05-27 12:17:50 Uploading - Uploading generated training model
2020-05-27 12:17:50 Failed - Training job failed
---------------------------------------------------------------------------
UnexpectedStatusException Traceback (most recent call last)
<ipython-input-2-09d7144431c1> in <module>()
----> 1 estimator.fit({'training': 's3://lum-ver/'})
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name, experiment_config)
475 self.jobs.append(self.latest_training_job)
476 if wait:
--> 477 self.latest_training_job.wait(logs=logs)
478
479 def _compilation_job_name(self):
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/estimator.py in wait(self, logs)
1084 # If logs are requested, call logs_for_jobs.
1085 if logs != "None":
-> 1086 self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
1087 else:
1088 self.sagemaker_session.wait_for_job(self.job_name)
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/session.py in logs_for_job(self, job_name, wait, poll, log_type)
3042
3043 if wait:
-> 3044 self._check_job_status(job_name, description, "TrainingJobStatus")
3045 if dot:
3046 print()
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/session.py in _check_job_status(self, job, desc, status_key_name)
2636 ),
2637 allowed_statuses=["Completed", "Stopped"],
-> 2638 actual_status=status,
2639 )
2640
UnexpectedStatusException: Error for Training job pytorch-training-2020-05-27-12-11-56-533: Failed. Reason: AlgorithmError: framework error:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train
entrypoint()
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main
train(framework.training_env())
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
framework.modules.download_and_install(training_environment.module_dir)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_modules.py", line 159, in download_and_install
_files.download_and_extract(uri, module_path)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 129, in download_and_extract
s3_download(uri, dst)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 165, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/
​
The actual error message is still cut off.
Do you need to use 0.4.0 version of PyTorch? This image has been released 2 years ago and we had numerous iterations since then. I would recommend switching to a new PyTorch version and as a result a newer image if possible.
@nadiaya Thanks for the response....as you mentioned I have tried using other framework versions as well....but nothing seems to works
Actually i missed part with the error:
File "/opt/conda/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
Seems there are issues with getting source code from the s3. What is the python SDK version are you using? What region are you using? How big is your train folder?
Hi, Region is US East (N. Virginia) Am not sure about python sdk version. If you can suggest how to get more info in this...it will be helpful. Train folder is 22.9 MB. hope I provided the details correct.
Hi @Vertika09 , to find out the sagemaker version:
print(sagemaker.__version__) or in your terminal pip freeze | grep sagemaker.
The latest sagemaker version is 1.61.0: https://pypi.org/project/sagemaker/
If you found your sagemaker version out of date, please re-install the latest version.
Hi @ChuyangDeng, thanks for the solution. I was able to re-install the latest version. Still, I get the following same error:
2020-06-12 06:40:03 Starting - Starting the training job...
2020-06-12 06:40:06 Starting - Launching requested ML instances.........
2020-06-12 06:41:48 Starting - Preparing the instances for training.........
2020-06-12 06:43:24 Downloading - Downloading input data...
2020-06-12 06:43:39 Training - Downloading the training image............
2020-06-12 06:46:02 Uploading - Uploading generated training modelbash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
2020-06-12 06:45:57,916 sagemaker-containers INFO Imported framework sagemaker_pytorch_container.training
2020-06-12 06:45:57,942 sagemaker_pytorch_container.training INFO Block until all host DNS lookups succeed.
2020-06-12 06:45:58,158 sagemaker_pytorch_container.training INFO Invoking user training script.
2020-06-12 06:45:58,388 sagemaker-containers ERROR Reporting training FAILURE
2020-06-12 06:45:58,388 sagemaker-containers ERROR framework error:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train
entrypoint()
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main
train(framework.training_env())
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
framework.modules.download_and_install(training_environment.module_dir)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_modules.py", line 159, in download_and_install
_files.download_and_extract(uri, module_path)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 129, in download_and_extract
s3_download(uri, dst)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 165, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 246, in bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/opt/conda/lib/python3.6/site-packages/s3transfer/tasks.py", line 255, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/s3transfer/download.py", line 343, in _submit
**transfer_future.meta.call_args.extra_args
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 599, in _make_api_call
api_params, operation_model, context=request_context)
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 647, in _convert_to_request_dict
api_params, operation_model)
File "/opt/conda/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
Parameter validation failed:
Invalid length for parameter Key, value: 0, valid range: 1-inf
2020-06-12 06:46:09 Failed - Training job failed
---------------------------------------------------------------------------
UnexpectedStatusException Traceback (most recent call last)
<ipython-input-14-9c47ff4dccae> in <module>()
----> 1 estimator.fit({'training': 's3://lumus-sagemaker/train.csv'})
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name, experiment_config)
475 self.jobs.append(self.latest_training_job)
476 if wait:
--> 477 self.latest_training_job.wait(logs=logs)
478
479 def _compilation_job_name(self):
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/estimator.py in wait(self, logs)
1084 # If logs are requested, call logs_for_jobs.
1085 if logs != "None":
-> 1086 self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
1087 else:
1088 self.sagemaker_session.wait_for_job(self.job_name)
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/session.py in logs_for_job(self, job_name, wait, poll, log_type)
3042
3043 if wait:
-> 3044 self._check_job_status(job_name, description, "TrainingJobStatus")
3045 if dot:
3046 print()
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/sagemaker/session.py in _check_job_status(self, job, desc, status_key_name)
2636 ),
2637 allowed_statuses=["Completed", "Stopped"],
-> 2638 actual_status=status,
2639 )
2640
UnexpectedStatusException: Error for Training job pytorch-training-2020-06-12-06-40-02-950: Failed. Reason: AlgorithmError: framework error:
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train
entrypoint()
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main
train(framework.training_env())
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
framework.modules.download_and_install(training_environment.module_dir)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_modules.py", line 159, in download_and_install
_files.download_and_extract(uri, module_path)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 129, in download_and_extract
s3_download(uri, dst)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 165, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/
@Vertika09 could you share the code used to start the training job? (i.e. fit())
in addition, could you share the hyperparameters you see in the AWS console from the failed training job?
Hi @laurenyu, the code for training job is:
from sagemaker.pytorch import PyTorch
estimator = PyTorch(entry_point="train.py",
source_dir="s3://lum-sagemaker/train",
role=role,
framework_version='1.5.0',
train_instance_count=1,
train_instance_type='ml.p2.xlarge',
hyperparameters={
'epochs': 10,
'hidden_dim': 200,
})
estimator.fit({'training': 's3://lum-sagemaker/train.csv'})
Am unable to find hyperparameters from failed training job. Is the below log any helpful?
ï„¿
14:22:23
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
ï„¿
14:22:23
bash: no job control in this shell
bash: no job control in this shell
ï„¿
14:22:23
2020-06-15 14:22:23,486 sagemaker-containers INFO Imported framework sagemaker_pytorch_container.training
2020-06-15 14:22:23,486 sagemaker-containers INFO Imported framework sagemaker_pytorch_container.training
ï„¿
14:22:23
2020-06-15 14:22:23,511 sagemaker_pytorch_container.training INFO Block until all host DNS lookups succeed.
2020-06-15 14:22:23,511 sagemaker_pytorch_container.training INFO Block until all host DNS lookups succeed.
ï„¿
14:22:26
2020-06-15 14:22:26,543 sagemaker_pytorch_container.training INFO Invoking user training script.
2020-06-15 14:22:26,543 sagemaker_pytorch_container.training INFO Invoking user training script.
ï„¿
14:22:26
2020-06-15 14:22:26,875 sagemaker-containers ERROR Reporting training FAILURE
2020-06-15 14:22:26,875 sagemaker-containers ERROR Reporting training FAILURE
ï„¿
14:22:26
2020-06-15 14:22:26,875 sagemaker-containers ERROR framework error:
2020-06-15 14:22:26,875 sagemaker-containers ERROR framework error:
ï„¿
14:22:26
Traceback (most recent call last): File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train entrypoint() File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main train(framework.training_env()) File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_trainer.py", line 84, in train
entrypoint()
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 99, in main
train(framework.training_env())
File "/opt/conda/lib/python3.6/site-packages/sagemaker_pytorch_container/training.py", line 50, in train
framework.modules.download_and_install(training_environment.module_dir)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_modules.py", line 159, in download_and_install
_files.download_and_extract(uri, module_path)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 129, in download_and_extract
s3_download(uri, dst)
File "/opt/conda/lib/python3.6/site-packages/sagemaker_containers/_files.py", line 165, in s3_download
s3.Bucket(bucket).download_file(key, dst)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 246, in bucket_download_file
ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/inject.py", line 172, in download_file
extra_args=ExtraArgs, callback=Callback)
File "/opt/conda/lib/python3.6/site-packages/boto3/s3/transfer.py", line 307, in download_file
future.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
return self._coordinator.result()
File "/opt/conda/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
raise self._exception
File "/opt/conda/lib/python3.6/site-packages/s3transfer/tasks.py", line 255, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/s3transfer/download.py", line 343, in _submit
**transfer_future.meta.call_args.extra_args
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/opt/conda/lib/python3.6/site-packages/botocore/client.py", line 626, in _make_api_call
raise error_class(parsed_response, operation_name)
ï„¿
14:22:26
botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
botocore.exceptions.ClientError: An error occurred (404) when calling the HeadObject operation: Not Found
ï„¿
14:22:26
An error occurred (404) when calling the HeadObject operation: Not Found
An error occurred (404) when calling the HeadObject operation: Not Found
Am unable to find hyperparameters from failed training job.
did you check in the AWS console or via the CLI? Are there more logs you can share from the beginning of the training job?
@laurenyu, I checked in the AWS console. These were the only training logs.
If I open a training job in the AWS console and scroll down, I see a section that lists the hyperparameters for the training job, e.g.

Based on the code you shared earlier, I'd expect your training job to have a handful of hyperparameters set: epochs and hidden_dim because you defined them above, as well as the sagemaker_* ones that are in the screenshot above. Can you show me what you see in the AWS console?
Hi @laurenyu, pls find the hyperparameters details below:
Hyperparameters Key Value epochs 5 hidden_dim 20 sagemaker_container_log_level 20 sagemaker_enable_cloudwatch_metrics false sagemaker_job_name "pytorch-training-2020-06-15-14-16-41-348" sagemaker_program "train.py" sagemaker_region "us-east-1" sagemaker_submit_directory "s3://sagemaker-us-east-1-082814126327/sagemaker/sentiment_rnn/Train"
I hope I provided the correct details that u asked for.
@Vertika09 thanks. The last stacktrace and the training code you posted don't match the other stacktraces you've shared here - is this comment the error you're currently dealing with?
In addition, the sagemaker_submit_directory hyperparameter value doesn't seem to match what the expected behavior of the estimator. If you check s3://sagemaker-us-east-1-082814126327/sagemaker/sentiment_rnn/Train, is your training script there?
@laurenyu I have been trying multiple ways to see if works, that's why the difference. Yes, the recent comment you mentioned is where I am still stuck.
Hyperparameters Key Value epochs 10 hidden_dim 200 sagemaker_container_log_level 20 sagemaker_enable_cloudwatch_metrics false sagemaker_job_name "pytorch-training-2020-05-27-12-49-51-805" sagemaker_program "train.py" sagemaker_region "us-east-1" sagemaker_submit_directory "s3://lum-ver"
sagemaker_submit_directory "s3://lum-ver" is more along what I was expecting with your first stacktrace/error message.
my best guess based on what you've shared is that your source_dir has been set incorrectly. Since you're using an S3 path for source_dir, can you try using an S3 path that points to a .tar.gz file with your source code?
it's harder to tell what could be causing what when we're mixing and matching code, hyperparameters, and log output. Could you share that info for a single failed job?
@laurenyu I tried .tar.gz file path as well for source_dir but the error remained the same. I tried running this multiple times before posting and I made sure every time to set the correct path.
Hyperparameters Key Value epochs 10 hidden_dim 200 sagemaker_container_log_level 20 sagemaker_enable_cloudwatch_metrics false sagemaker_job_name "pytorch-training-2020-06-12-04-44-05-085" sagemaker_program "train.py" sagemaker_region "us-east-1" sagemaker_submit_directory "s3://lum-sagemaker/model.tar.gz"
sorry if I wasn't clear earlier. The .tar.gz file that sagemaker_submit_directory points to should contain your train.py file.
If you have train.py saved locally and not in S3, then your code should look like:
PyTorch(entry_point='train.py', ...)
If it is already saved in S3, then your code should look like:
PyTorch(entry_point='train.py', source_dir='s3://bucket/path/sourcedir.tar.gz', ...)
where sourcedir.tar.gz looks like:
sourcedir.tar.gz
|- train.py
If your train.py is saved locally and you want it saved in a specific S3 location, then your code should look like:
PyTorch(entry_point='train.py', code_location='s3://bucket/path', ...)
Hi @laurenyu, I have tried uploading the train.py file in tar.gz in S3 bucket and gave the reference path in source_dir. It didn't work either.