Skip to content

feature: Hugging Face Transformers 4.12 for Pt1.9/TF2.5 #2752

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 6 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
149 changes: 145 additions & 4 deletions src/sagemaker/image_uri_config/huggingface.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"4.5": "4.5.0",
"4.6": "4.6.1",
"4.10": "4.10.2",
"4.11": "4.11.0"
"4.11": "4.11.0",
"4.12": "4.12.3"
},
"versions": {
"4.4.2": {
Expand Down Expand Up @@ -416,8 +417,7 @@
"repository": "huggingface-tensorflow-training",
"container_version": {"gpu": "cu112-ubuntu18.04"}
}
}
,
},
"4.11.0": {
"version_aliases": {
"pytorch1.9": "pytorch1.9.0",
Expand Down Expand Up @@ -487,6 +487,76 @@
"repository": "huggingface-tensorflow-training",
"container_version": {"gpu": "cu112-ubuntu18.04"}
}
},
"4.12.3": {
"version_aliases": {
"pytorch1.9": "pytorch1.9.1",
"tensorflow2.5": "tensorflow2.5.1"
},
"pytorch1.9.1": {
"py_versions": ["py38"],
"registries": {
"af-south-1": "626614931356",
"ap-east-1": "871362719292",
"ap-northeast-1": "763104351884",
"ap-northeast-2": "763104351884",
"ap-northeast-3": "364406365360",
"ap-south-1": "763104351884",
"ap-southeast-1": "763104351884",
"ap-southeast-2": "763104351884",
"ca-central-1": "763104351884",
"cn-north-1": "727897471807",
"cn-northwest-1": "727897471807",
"eu-central-1": "763104351884",
"eu-north-1": "763104351884",
"eu-west-1": "763104351884",
"eu-west-2": "763104351884",
"eu-west-3": "763104351884",
"eu-south-1": "692866216735",
"me-south-1": "217643126080",
"sa-east-1": "763104351884",
"us-east-1": "763104351884",
"us-east-2": "763104351884",
"us-gov-west-1": "442386744353",
"us-iso-east-1": "886529160074",
"us-west-1": "763104351884",
"us-west-2": "763104351884"
},
"repository": "huggingface-pytorch-training",
"container_version": {"gpu": "cu111-ubuntu20.04"}
},
"tensorflow2.5.1": {
"py_versions": ["py37"],
"registries": {
"af-south-1": "626614931356",
"ap-east-1": "871362719292",
"ap-northeast-1": "763104351884",
"ap-northeast-2": "763104351884",
"ap-northeast-3": "364406365360",
"ap-south-1": "763104351884",
"ap-southeast-1": "763104351884",
"ap-southeast-2": "763104351884",
"ca-central-1": "763104351884",
"cn-north-1": "727897471807",
"cn-northwest-1": "727897471807",
"eu-central-1": "763104351884",
"eu-north-1": "763104351884",
"eu-south-1": "692866216735",
"eu-west-1": "763104351884",
"eu-west-2": "763104351884",
"eu-west-3": "763104351884",
"me-south-1": "217643126080",
"sa-east-1": "763104351884",
"us-east-1": "763104351884",
"us-east-2": "763104351884",
"us-gov-west-1": "442386744353",
"us-iso-east-1": "886529160074",
"us-west-1": "763104351884",
"us-west-2": "763104351884"
},
"repository": "huggingface-tensorflow-training",
"container_version": {"gpu": "cu112-ubuntu18.04"}
}
}
}
},
Expand All @@ -496,7 +566,8 @@
"version_aliases": {
"4.6": "4.6.1",
"4.10": "4.10.2",
"4.11": "4.11.0"
"4.11": "4.11.0",
"4.12": "4.12.3"
},
"versions": {
"4.6.1": {
Expand Down Expand Up @@ -806,6 +877,76 @@
"repository": "huggingface-tensorflow-inference",
"container_version": {"gpu": "cu112-ubuntu18.04", "cpu": "ubuntu18.04" }
}
},
"4.12.3": {
"version_aliases": {
"pytorch1.9": "pytorch1.9.1",
"tensorflow2.5": "tensorflow2.5.1"
},
"pytorch1.9.1": {
"py_versions": ["py38"],
"registries": {
"af-south-1": "626614931356",
"ap-east-1": "871362719292",
"ap-northeast-1": "763104351884",
"ap-northeast-2": "763104351884",
"ap-northeast-3": "364406365360",
"ap-south-1": "763104351884",
"ap-southeast-1": "763104351884",
"ap-southeast-2": "763104351884",
"ca-central-1": "763104351884",
"cn-north-1": "727897471807",
"cn-northwest-1": "727897471807",
"eu-central-1": "763104351884",
"eu-north-1": "763104351884",
"eu-west-1": "763104351884",
"eu-west-2": "763104351884",
"eu-west-3": "763104351884",
"eu-south-1": "692866216735",
"me-south-1": "217643126080",
"sa-east-1": "763104351884",
"us-east-1": "763104351884",
"us-east-2": "763104351884",
"us-gov-west-1": "442386744353",
"us-iso-east-1": "886529160074",
"us-west-1": "763104351884",
"us-west-2": "763104351884"
},
"repository": "huggingface-pytorch-inference",
"container_version": {"gpu": "cu111-ubuntu20.04", "cpu": "ubuntu20.04" }
},
"tensorflow2.5.1": {
"py_versions": ["py37"],
"registries": {
"af-south-1": "626614931356",
"ap-east-1": "871362719292",
"ap-northeast-1": "763104351884",
"ap-northeast-2": "763104351884",
"ap-northeast-3": "364406365360",
"ap-south-1": "763104351884",
"ap-southeast-1": "763104351884",
"ap-southeast-2": "763104351884",
"ca-central-1": "763104351884",
"cn-north-1": "727897471807",
"cn-northwest-1": "727897471807",
"eu-central-1": "763104351884",
"eu-north-1": "763104351884",
"eu-south-1": "692866216735",
"eu-west-1": "763104351884",
"eu-west-2": "763104351884",
"eu-west-3": "763104351884",
"me-south-1": "217643126080",
"sa-east-1": "763104351884",
"us-east-1": "763104351884",
"us-east-2": "763104351884",
"us-gov-west-1": "442386744353",
"us-iso-east-1": "886529160074",
"us-west-1": "763104351884",
"us-west-2": "763104351884"
},
"repository": "huggingface-tensorflow-inference",
"container_version": {"gpu": "cu112-ubuntu18.04", "cpu": "ubuntu18.04" }
}
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions tests/data/huggingface/run_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@
)
train_dataset.set_format(type="tensorflow", columns=["input_ids", "attention_mask", "label"])

train_features = {
x: train_dataset[x].to_tensor(default_value=0, shape=[None, tokenizer.model_max_length])
for x in ["input_ids", "attention_mask"]
}
train_features = {x: train_dataset[x] for x in ["input_ids", "attention_mask"]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you detail why we are removing the to_tensor call, especially since the shape's tokenizer.model_max_length parameter is something that we gave explicitly in the past? Is this driven by the change in TF version?

Please make this backwards compatible ie. have an original test case with the previous changes, and add a new test case for this requirement where the to_tensor call is not required so that we test both scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been removed in Datasets since we changed the internal structure. it used to return RaggedTensor even when the tensors were normal dense tensors.
And the tokenizer.mode_max_length is already represented in

    train_dataset = train_dataset.map(
        lambda e: tokenizer(e["text"], truncation=True, padding="max_length"), batched=True
    )

which creates already a shape of max_length.

I added a condition to test to check the transformers version and added the old code


tf_train_dataset = tf.data.Dataset.from_tensor_slices(
(train_features, train_dataset["label"])
).batch(args.per_device_train_batch_size)
Expand All @@ -71,10 +69,8 @@
)
test_dataset.set_format(type="tensorflow", columns=["input_ids", "attention_mask", "label"])

test_features = {
x: test_dataset[x].to_tensor(default_value=0, shape=[None, tokenizer.model_max_length])
for x in ["input_ids", "attention_mask"]
}
test_features = {x: test_dataset[x] for x in ["input_ids", "attention_mask"]}

tf_test_dataset = tf.data.Dataset.from_tensor_slices(
(test_features, test_dataset["label"])
).batch(args.per_device_eval_batch_size)
Expand Down
2 changes: 1 addition & 1 deletion tests/integ/test_huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_huggingface_inference(
huggingface_pytorch_latest_inference_py_version,
):
env = {
"HF_MODEL_ID": "sshleifer/tiny-distilbert-base-uncased-finetuned-sst-2-english",
"HF_MODEL_ID": "philschmid/tiny-distilbert-classification",
Copy link
Contributor

Choose a reason for hiding this comment

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

@philschmid Can we please give this a generic name to this model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean by that. That is not a model which will be created it is stored on the hf.co/models hub and used to run tests. I changed it because to a model which we can control. https://huggingface.co/philschmid/tiny-distilbert-classification.

"HF_TASK": "text-classification",
}
endpoint_name = unique_name_from_base("test-hf-inference")
Expand Down