如何使用 SageMaker AutoGluon-Tabular - Amazon SageMaker

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

如何使用 SageMaker AutoGluon-Tabular

您可以使用 AutoGluon-Tabular 作为亚马逊的 SageMaker 内置算法。下一节介绍如何在 Python SageMaker 中使用 AutoGluon-Tabular。SDK有关如何在 Amazon SageMaker Studio Classic 用户界面中使用 AutoGluon-Tabular 的信息,请参阅。SageMaker JumpStart 预训练模型

  • 使用 AutoGluon-Tabular 作为内置算法

    使用 AutoGluon-Tabular 内置算法构建 AutoGluon-Tabular 训练容器,如以下代码示例所示。你可以使用 SageMaker image_uris.retrieveAPI(或者get_image_uriAPI如果URI使用 Amaz on Pyth SageMaker on SDK 版本 2)自动发现 AutoGluon-Tabular 内置算法图像。

    指定 AutoGluon-Tabular 图像后URI,您可以使用 AutoGluon-Tabular 容器使用估算器构造估计器并启动训练作 SageMaker 业。API AutoGluon-Tabular 内置算法在脚本模式下运行,但训练脚本是为你提供的,无需替换。如果您在使用脚本模式创建 SageMaker 训练作业方面有丰富的经验,则可以合并自己的 AutoGluon-Tabular 训练脚本。

    from sagemaker import image_uris, model_uris, script_uris train_model_id, train_model_version, train_scope = "autogluon-classification-ensemble", "*", "training" training_instance_type = "ml.p3.2xlarge" # Retrieve the docker image train_image_uri = image_uris.retrieve( region=None, framework=None, model_id=train_model_id, model_version=train_model_version, image_scope=train_scope, instance_type=training_instance_type ) # Retrieve the training script train_source_uri = script_uris.retrieve( model_id=train_model_id, model_version=train_model_version, script_scope=train_scope ) train_model_uri = model_uris.retrieve( model_id=train_model_id, model_version=train_model_version, model_scope=train_scope ) # Sample training data is available in this bucket training_data_bucket = f"jumpstart-cache-prod-{aws_region}" training_data_prefix = "training-datasets/tabular_binary/" training_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}/train" validation_dataset_s3_path = f"s3://{training_data_bucket}/{training_data_prefix}/validation" output_bucket = sess.default_bucket() output_prefix = "jumpstart-example-tabular-training" s3_output_location = f"s3://{output_bucket}/{output_prefix}/output" from sagemaker import hyperparameters # Retrieve the default hyperparameters for training the model hyperparameters = hyperparameters.retrieve_default( model_id=train_model_id, model_version=train_model_version ) # [Optional] Override default hyperparameters with custom values hyperparameters[ "auto_stack" ] = "True" print(hyperparameters) from sagemaker.estimator import Estimator from sagemaker.utils import name_from_base training_job_name = name_from_base(f"built-in-algo-{train_model_id}-training") # Create SageMaker Estimator instance tabular_estimator = Estimator( role=aws_role, image_uri=train_image_uri, source_dir=train_source_uri, model_uri=train_model_uri, entry_point="transfer_learning.py", instance_count=1, instance_type=training_instance_type, max_run=360000, hyperparameters=hyperparameters, output_path=s3_output_location ) # Launch a SageMaker Training job by passing the S3 path of the training data tabular_estimator.fit( { "training": training_dataset_s3_path, "validation": validation_dataset_s3_path, }, logs=True, job_name=training_job_name )

    有关如何将 AutoGluon-Tabular 设置为内置算法的更多信息,请参阅以下笔记本示例。这些示例中使用的任何 S3 存储桶都必须与用于运行它们的笔记本实例位于同一 AWS 区域。