|
11 | 11 | # ANY KIND, either express or implied. See the License for the specific |
12 | 12 | # language governing permissions and limitations under the License. |
13 | 13 |
|
| 14 | +import copy |
| 15 | +import datetime |
| 16 | +import json |
| 17 | +import os |
14 | 18 | import pytest |
15 | 19 | from unittest.mock import Mock, patch |
16 | 20 | from sagemaker.core.jumpstart.hub.parsers import ( |
@@ -367,3 +371,87 @@ def test_make_model_specs_from_describe_hub_content_response_with_payloads(self) |
367 | 371 | result = make_model_specs_from_describe_hub_content_response(response) |
368 | 372 |
|
369 | 373 | assert result is not None |
| 374 | + |
| 375 | + def test_make_model_specs_preserves_instance_variant_environment_variable_names( |
| 376 | + self, hub_content_document |
| 377 | + ): |
| 378 | + """Environment variable names under HostingInstanceTypeVariants must survive verbatim.""" |
| 379 | + variants = hub_content_document["InferenceConfigComponents"]["tgi"][ |
| 380 | + "HostingInstanceTypeVariants" |
| 381 | + ]["Variants"] |
| 382 | + variants["ml.g5.12xlarge"]["Properties"]["EnvironmentVariables"][ |
| 383 | + "SM_VLLM_MAX_MODEL_LEN" |
| 384 | + ] = "4096" |
| 385 | + variants["g5"]["Properties"]["EnvironmentVariables"] = {"HF_HUB_OFFLINE": "1"} |
| 386 | + |
| 387 | + specs = make_model_specs_from_describe_hub_content_response( |
| 388 | + _describe_hub_content_response(hub_content_document) |
| 389 | + ) |
| 390 | + |
| 391 | + instance_type_variants = specs.hosting_instance_type_variants |
| 392 | + assert instance_type_variants.variants["ml.g5.12xlarge"]["properties"][ |
| 393 | + "environment_variables" |
| 394 | + ] == {"SM_NUM_GPUS": "4", "SM_VLLM_MAX_MODEL_LEN": "4096"} |
| 395 | + assert instance_type_variants.get_instance_specific_environment_variables( |
| 396 | + "ml.g5.12xlarge" |
| 397 | + ) == { |
| 398 | + "HF_HUB_OFFLINE": "1", |
| 399 | + "SM_NUM_GPUS": "4", |
| 400 | + "SM_VLLM_MAX_MODEL_LEN": "4096", |
| 401 | + } |
| 402 | + |
| 403 | + def test_make_model_specs_preserves_top_level_variant_environment_variable_names( |
| 404 | + self, hub_content_document |
| 405 | + ): |
| 406 | + """Top level HostingInstanceTypeVariants go through one more conversion pass than |
| 407 | + inference config components and must also keep environment variable names verbatim.""" |
| 408 | + document = copy.deepcopy(hub_content_document) |
| 409 | + for key in ("InferenceConfigs", "InferenceConfigComponents", "InferenceConfigRankings"): |
| 410 | + document.pop(key, None) |
| 411 | + document["HostingInstanceTypeVariants"] = { |
| 412 | + "Variants": { |
| 413 | + "g5": { |
| 414 | + "Properties": { |
| 415 | + "ImageUri": "image", |
| 416 | + "EnvironmentVariables": {"SM_VLLM_MAX_MODEL_LEN": "131072"}, |
| 417 | + } |
| 418 | + } |
| 419 | + } |
| 420 | + } |
| 421 | + |
| 422 | + specs = make_model_specs_from_describe_hub_content_response( |
| 423 | + _describe_hub_content_response(document) |
| 424 | + ) |
| 425 | + |
| 426 | + instance_type_variants = specs.hosting_instance_type_variants |
| 427 | + assert instance_type_variants.variants["g5"]["properties"]["image_uri"] == "image" |
| 428 | + assert instance_type_variants.get_instance_specific_environment_variables( |
| 429 | + "ml.g5.12xlarge" |
| 430 | + ) == {"SM_VLLM_MAX_MODEL_LEN": "131072"} |
| 431 | + |
| 432 | + |
| 433 | +def _describe_hub_content_response(hub_content_document): |
| 434 | + return DescribeHubContentResponse( |
| 435 | + { |
| 436 | + "CreationTime": datetime.datetime(2024, 1, 1), |
| 437 | + "DocumentSchemaVersion": "2.0.0", |
| 438 | + "HubArn": "arn:aws:sagemaker:us-east-1:123456789012:hub/my-private-hub", |
| 439 | + "HubContentArn": ( |
| 440 | + "arn:aws:sagemaker:us-east-1:123456789012:hub-content/" |
| 441 | + "my-private-hub/Model/meta-textgeneration-llama-2-13b-f/1.0.0" |
| 442 | + ), |
| 443 | + "HubContentName": "meta-textgeneration-llama-2-13b-f", |
| 444 | + "HubContentType": "Model", |
| 445 | + "HubContentVersion": "1.0.0", |
| 446 | + "HubContentStatus": "Available", |
| 447 | + "HubName": "my-private-hub", |
| 448 | + "HubContentDocument": json.dumps(hub_content_document), |
| 449 | + } |
| 450 | + ) |
| 451 | + |
| 452 | + |
| 453 | +@pytest.fixture |
| 454 | +def hub_content_document(): |
| 455 | + path = os.path.join(os.path.dirname(__file__), "..", "hub_content_document.json") |
| 456 | + with open(path, "r") as f: |
| 457 | + return json.load(f) |
0 commit comments