Skip to content

[Sagemaker] sagemaker distributed features in Trainer broken since Transformers 4.29 #23390

Description

@JingyaHuang

System Info

  • transformers: 4.29.1
  • datasets: 2.12.0
  • evaluate: 0.4.0
  • accelerate: 0.19.0
  • torch: 2.0.0
  • diffusers: 0.16.1

Who can help?

@philschmid @sgugger

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

The issue is found while I update AWS Sagemaker deep learning container for Transformers-PyTorch. Sagemaker's distributed data parallel and model parallel features are broken since Transformers 4.29.* .

AttributeError: 'TrainingArguments' object has no attribute 'distributed_state'
More detailed error log
``` _____________________________ test_smmp_gpu[gloo] ______________________________

ecr_image = '669063966089.dkr.ecr.us-west-2.amazonaws.com/pr-huggingface-pytorch-training:2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48'
sagemaker_regions = ['us-west-2', 'us-east-1', 'eu-west-1']
instance_type = 'ml.p3.8xlarge', framework_version = '2.0.0', py_version = 'py3'
dist_gpu_backend = 'gloo'

@pytest.mark.processor("gpu")
@pytest.mark.integration("smmp")
@pytest.mark.model("hf_qa_smmp")
@pytest.mark.skip_cpu
@pytest.mark.skip_py2_containers
@pytest.mark.skip_trcomp_containers
def test_smmp_gpu(
    ecr_image, sagemaker_regions, instance_type, framework_version, py_version, dist_gpu_backend
):
  invoke_sm_helper_function(ecr_image, sagemaker_regions, _test_smmp_gpu_function, py_version, 1)

integration/sagemaker/test_smmp.py:76:


../../init.py:119: in invoke_sm_helper_function
raise e
../../init.py:113: in invoke_sm_helper_function
test_function(tested_ecr_image, sagemaker_session, *test_function_args)
integration/sagemaker/test_smmp.py:117: in _test_smmp_gpu_function
huggingface_estimator.fit(job_name=sagemaker.utils.unique_name_from_base("test-hf-pt-qa-smmp"))
2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48/lib/python3.8/site-packages/sagemaker/workflow/pipeline_context.py:272: in wrapper
return run_func(*args, **kwargs)
2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48/lib/python3.8/site-packages/sagemaker/estimator.py:1156: in fit
self.latest_training_job.wait(logs=logs)
2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48/lib/python3.8/site-packages/sagemaker/estimator.py:2297: in wait
self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48/lib/python3.8/site-packages/sagemaker/session.py:4216: in logs_for_job
self._check_job_status(job_name, description, "TrainingJobStatus")


self = <sagemaker.session.Session object at 0x7f466ef3fc40>
job = 'test-hf-pt-qa-smmp-1684001017-f81e'
desc = {'AlgorithmSpecification': {'EnableSageMakerMetricsTimeSeries': True, 'TrainingImage': '669063966089.dkr.ecr.us-west-2...)), 'DebugHookConfig': {'CollectionConfigurations': [], 'S3OutputPath': 's3://sagemaker-us-west-2-669063966089/'}, ...}
status_key_name = 'TrainingJobStatus'

    def _check_job_status(self, job, desc, status_key_name):
        """Check to see if the job completed successfully.

        If not, construct and raise a exceptions. (UnexpectedStatusException).

        Args:
            job (str): The name of the job to check.
            desc (dict[str, str]): The result of ``describe_training_job()``.
            status_key_name (str): Status key name to check for.

        Raises:
            exceptions.CapacityError: If the training job fails with CapacityError.
            exceptions.UnexpectedStatusException: If the training job fails.
        """
        status = desc[status_key_name]
        # If the status is capital case, then convert it to Camel case
        status = _STATUS_CODE_TABLE.get(status, status)

        if status == "Stopped":
            LOGGER.warning(
                "Job ended with status 'Stopped' rather than 'Completed'. "
                "This could mean the job timed out or stopped early for some other reason: "
                "Consider checking whether it completed as you expect."
            )
        elif status != "Completed":
            reason = desc.get("FailureReason", "(No reason provided)")
            job_type = status_key_name.replace("JobStatus", " job")
            message = "Error for {job_type} {job_name}: {status}. Reason: {reason}".format(
                job_type=job_type, job_name=job, status=status, reason=reason
            )
            if "CapacityError" in str(reason):
                raise exceptions.CapacityError(
                    message=message,
                    allowed_statuses=["Completed", "Stopped"],
                    actual_status=status,
                )
>           raise exceptions.UnexpectedStatusException(
                message=message,
                allowed_statuses=["Completed", "Stopped"],
                actual_status=status,
            )
E           sagemaker.exceptions.UnexpectedStatusException: Error for Training job test-hf-pt-qa-smmp-1684001017-f81e: Failed. Reason: AlgorithmError: ExecuteUserScriptError:
E           ExitCode 1
E           ErrorMessage "AttributeError: 'TrainingArguments' object has no attribute 'distributed_state'
E            ╭───────────────────── Traceback (most recent call last) ──────────────────────╮
E            │ /opt/conda/lib/python3.10/runpy.py:196 in _run_module_as_main                │
E            │                                                                              │
E            │   193 │   main_globals = sys.modules["__main__"].__dict__                    │
E            │   194 │   if alter_argv:                                                     │
E            │   195 │   │   sys.argv[0] = mod_spec.origin                                  │
E            │ ❱ 196 │   return _run_code(code, main_globals, None,                         │
E            │   197 │   │   │   │   │    "__main__", mod_spec)                             │
E            │   198                                                                        │
E            │   199 de, exit code: 1

2.0.0-transformers4.29.1-gpu-py310-cu118-ubuntu20.04-pr-2993-2023-05-13-17-25-48/lib/python3.8/site-packages/sagemaker/session.py:3749: UnexpectedStatusException

Expected behavior

Find either what to adapt from the sagemaker side or from our side to make sure distributed features work, so that we would be update transformers to higher versions the next time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions