sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

ModelTrainer sometimes fails due to race condition when running distributed training

Open erickb336 opened this issue 1 year ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

when running distributed training with Hyperpod recipes with ModelTrainer sometimes see error like below due to race condition:

	
2025-01-31T22:17:45.257Z
	
File "/opt/conda/lib/python3.11/site-packages/sagemaker_training/environment.py", line 189, in <module>
	
2025-01-31T22:17:45.257Z
	
File "/opt/conda/lib/python3.11/site-packages/sagemaker_training/environment.py", line 189, in <module>
	
2025-01-31T22:17:45.257Z
	
_create_code_dir()
	
2025-01-31T22:17:45.257Z
	
_create_code_dir()
	
2025-01-31T22:17:45.257Z
	
File "/opt/conda/lib/python3.11/site-packages/sagemaker_training/environment.py", line 186, in _create_code_dir
	
2025-01-31T22:17:45.257Z
	
File "/opt/conda/lib/python3.11/site-packages/sagemaker_training/environment.py", line 186, in _create_code_dir
	
2025-01-31T22:17:45.257Z
	
os.makedirs(code_dir)
	
2025-01-31T22:17:45.257Z
	
os.makedirs(code_dir)
	
2025-01-31T22:17:45.257Z
	
File "<frozen os>", line 225, in makedirs
	
2025-01-31T22:17:45.257Z
	
FileExistsError: File "<frozen os>", line 225, in makedirs
	
2025-01-31T22:17:45.257Z
	
[Errno 17] File exists: '/opt/ml/code'
	
2025-01-31T22:17:45.257Z
	
FileExistsError: [Errno 17] File exists: '/opt/ml/code'

Seems to come from here - https://github.com/aws/sagemaker-training-toolkit/blob/874f7b055eba3cf3a599b6c5ef74c40396bc9376/src/sagemaker_training/environment.py#L183

To reproduce A clear, step-by-step set of instructions to reproduce the bug. The provided code need to be complete and runnable, if additional data is needed, please include them in the issue.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots or logs If applicable, add screenshots or logs to help explain your problem.

System information A description of your system. Please provide:

  • SageMaker Python SDK version:
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans):
  • Framework version:
  • Python version:
  • CPU or GPU:
  • Custom Docker image (Y/N):

Additional context Add any other context about the problem here.

erickb336 avatar Jan 31 '25 22:01 erickb336

https://github.com/aws/sagemaker-training-toolkit/pull/231

erickb336 avatar Jan 31 '25 22:01 erickb336

Closing since fix was release in toolkit v.4.8.4

erickb336 avatar Feb 03 '25 20:02 erickb336