Skip to content

fix: Handle instance support for Hugging Face tests #3729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,16 @@ def gpu_instance_type(sagemaker_session, request):

@pytest.fixture()
def gpu_pytorch_instance_type(sagemaker_session, request):
if "pytorch_inference_version" in request.fixturenames:
fw_version = request.getfixturevalue("pytorch_inference_version")
else:
fw_version = None
for pytorch_version_fixture in [
"pytorch_inference_version",
"huggingface_training_pytorch_latest_version",
"huggingface_inference_pytorch_latest_version",
]:
if pytorch_version_fixture in request.fixturenames:
fw_version = request.getfixturevalue(pytorch_version_fixture)
if fw_version is None:
fw_version = request.param

region = sagemaker_session.boto_session.region_name
if region in NO_P3_REGIONS:
if Version(fw_version) >= Version("1.13"):
Expand Down
36 changes: 8 additions & 28 deletions tests/integ/test_huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@
from sagemaker.huggingface import HuggingFace, HuggingFaceProcessor
from sagemaker.huggingface.model import HuggingFaceModel, HuggingFacePredictor
from sagemaker.utils import unique_name_from_base
from tests import integ
from tests.integ.utils import gpu_list, retry_with_instance_list
from tests.integ import DATA_DIR, TRAINING_DEFAULT_TIMEOUT_MINUTES
from tests.integ.timeout import timeout, timeout_and_delete_endpoint_by_name

ROLE = "SageMakerRole"


@pytest.mark.release
@pytest.mark.skipif(
integ.test_region() in integ.TRAINING_NO_P2_REGIONS
and integ.test_region() in integ.TRAINING_NO_P3_REGIONS,
reason="no ml.p2 or ml.p3 instances in this region",
)
@retry_with_instance_list(gpu_list(integ.test_region()))
def test_framework_processing_job_with_deps(
sagemaker_session,
huggingface_training_latest_version,
huggingface_training_pytorch_latest_version,
huggingface_pytorch_latest_training_py_version,
**kwargs,
gpu_pytorch_instance_type,
):
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
code_path = os.path.join(DATA_DIR, "dummy_code_bundle_with_reqs")
Expand All @@ -51,7 +43,7 @@ def test_framework_processing_job_with_deps(
py_version=huggingface_pytorch_latest_training_py_version,
role=ROLE,
instance_count=1,
instance_type=kwargs["instance_type"],
instance_type=gpu_pytorch_instance_type,
sagemaker_session=sagemaker_session,
base_job_name="test-huggingface",
)
Expand All @@ -64,18 +56,12 @@ def test_framework_processing_job_with_deps(


@pytest.mark.release
@pytest.mark.skipif(
integ.test_region() in integ.TRAINING_NO_P2_REGIONS
and integ.test_region() in integ.TRAINING_NO_P3_REGIONS,
reason="no ml.p2 or ml.p3 instances in this region",
)
@retry_with_instance_list(gpu_list(integ.test_region()))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this retry so that it does not pickup p2 instance during retry

def test_huggingface_training(
sagemaker_session,
huggingface_training_latest_version,
huggingface_training_pytorch_latest_version,
huggingface_pytorch_latest_training_py_version,
**kwargs,
gpu_pytorch_instance_type,
):
with timeout(minutes=TRAINING_DEFAULT_TIMEOUT_MINUTES):
data_path = os.path.join(DATA_DIR, "huggingface")
Expand All @@ -87,7 +73,7 @@ def test_huggingface_training(
transformers_version=huggingface_training_latest_version,
pytorch_version=huggingface_training_pytorch_latest_version,
instance_count=1,
instance_type=kwargs["instance_type"],
instance_type=gpu_pytorch_instance_type,
hyperparameters={
"model_name_or_path": "distilbert-base-cased",
"task_name": "wnli",
Expand All @@ -111,14 +97,6 @@ def test_huggingface_training(


@pytest.mark.release
@pytest.mark.skipif(
integ.test_region() in integ.TRAINING_NO_P2_REGIONS
and integ.test_region() in integ.TRAINING_NO_P3_REGIONS,
reason="no ml.p2 or ml.p3 instances in this region",
)
@pytest.mark.skip(
reason="need to re enable it later t.corp:V609860141",
)
def test_huggingface_training_tf(
sagemaker_session,
gpu_instance_type,
Expand Down Expand Up @@ -161,7 +139,7 @@ def test_huggingface_training_tf(
)
def test_huggingface_inference(
sagemaker_session,
gpu_instance_type,
gpu_pytorch_instance_type,
huggingface_inference_latest_version,
huggingface_inference_pytorch_latest_version,
huggingface_pytorch_latest_inference_py_version,
Expand All @@ -182,7 +160,9 @@ def test_huggingface_inference(
)
with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
model.deploy(
instance_type=gpu_instance_type, initial_instance_count=1, endpoint_name=endpoint_name
instance_type=gpu_pytorch_instance_type,
initial_instance_count=1,
endpoint_name=endpoint_name,
)

predictor = HuggingFacePredictor(endpoint_name=endpoint_name)
Expand Down