当前位置: 首页>>代码示例>>Python>>正文


Python sagemaker.Session方法代码示例

本文整理汇总了Python中sagemaker.Session方法的典型用法代码示例。如果您正苦于以下问题:Python sagemaker.Session方法的具体用法?Python sagemaker.Session怎么用?Python sagemaker.Session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sagemaker的用法示例。


在下文中一共展示了sagemaker.Session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def __init__(self, endpoint, sagemaker_session=None):
        """Initializes a SparkMLPredictor which should be used with SparkMLModel
        to perform predictions against SparkML models serialized via MLeap. The
        response is returned in text/csv format which is the default response
        format for SparkML Serving container.

        Args:
            endpoint (str): The name of the endpoint to perform inference on.
            sagemaker_session (sagemaker.session.Session): Session object which
                manages interactions with Amazon SageMaker APIs and any other
                AWS services needed. If not specified, the estimator creates one
                using the default AWS configuration chain.
        """
        sagemaker_session = sagemaker_session or Session()
        super(SparkMLPredictor, self).__init__(
            endpoint=endpoint,
            sagemaker_session=sagemaker_session,
            serializer=csv_serializer,
            content_type=CONTENT_TYPE_CSV,
        ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:22,代码来源:model.py

示例2: _is_marketplace

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def _is_marketplace(self):
        """Placeholder docstring"""
        model_package_name = self.model_package_arn or self._created_model_package_name
        if model_package_name is None:
            return True

        # Models can lazy-init sagemaker_session until deploy() is called to support
        # LocalMode so we must make sure we have an actual session to describe the model package.
        sagemaker_session = self.sagemaker_session or sagemaker.Session()

        model_package_desc = sagemaker_session.sagemaker_client.describe_model_package(
            ModelPackageName=model_package_name
        )
        for container in model_package_desc["InferenceSpecification"]["Containers"]:
            if "ProductId" in container:
                return True
        return False 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:19,代码来源:model.py

示例3: __init__

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def __init__(self, args):
        """
        Args:
            args:
        """
        self.job_name = args.job_name
        self.bucket = args.bucket_name  # may be None
        self.role_name = args.role_name
        self.python = args.python
        self.data = args.data
        self.script = args.script
        self.instance_type = args.instance_type
        self.instance_count = args.instance_count
        self.hyperparameters = self.load_hyperparameters(args.hyperparameters)

        self.session = sagemaker.Session() 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:18,代码来源:common.py

示例4: sagemaker_session_with_custom_bucket

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session_with_custom_bucket(
    boto_session, sagemaker_client_config, sagemaker_runtime_config, custom_bucket_name
):
    sagemaker_client_config.setdefault("config", Config(retries=dict(max_attempts=10)))
    sagemaker_client = (
        boto_session.client("sagemaker", **sagemaker_client_config)
        if sagemaker_client_config
        else None
    )
    runtime_client = (
        boto_session.client("sagemaker-runtime", **sagemaker_runtime_config)
        if sagemaker_runtime_config
        else None
    )

    return Session(
        boto_session=boto_session,
        sagemaker_client=sagemaker_client,
        sagemaker_runtime_client=runtime_client,
        default_bucket=custom_bucket_name,
    ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:23,代码来源:test_processing.py

示例5: sagemaker_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session(sagemaker_client_config, sagemaker_runtime_config, boto_session):
    sagemaker_client_config.setdefault("config", Config(retries=dict(max_attempts=10)))
    sagemaker_client = (
        boto_session.client("sagemaker", **sagemaker_client_config)
        if sagemaker_client_config
        else None
    )
    runtime_client = (
        boto_session.client("sagemaker-runtime", **sagemaker_runtime_config)
        if sagemaker_runtime_config
        else None
    )

    return Session(
        boto_session=boto_session,
        sagemaker_client=sagemaker_client,
        sagemaker_runtime_client=runtime_client,
    ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:20,代码来源:conftest.py

示例6: sagemaker_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session():
    boto_mock = Mock(name="boto_session", region_name=REGION)
    ims = sagemaker.Session(sagemaker_client=Mock(name="sagemaker_client"), boto_session=boto_mock)
    ims.sagemaker_client.describe_model = Mock(
        name="describe_model", side_effect=_raise_does_not_exist_client_error
    )
    ims.sagemaker_client.describe_endpoint_config = Mock(
        name="describe_endpoint_config", side_effect=_raise_does_not_exist_client_error
    )
    ims.sagemaker_client.describe_endpoint = Mock(
        name="describe_endpoint", side_effect=_raise_does_not_exist_client_error
    )
    ims.create_model = Mock(name="create_model")
    ims.create_endpoint_config = Mock(name="create_endpoint_config")
    ims.create_endpoint = Mock(name="create_endpoint")
    return ims 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:18,代码来源:test_endpoint_from_model_data.py

示例7: test_user_agent_injected_with_nbi

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def test_user_agent_injected_with_nbi(boto_session):
    assert (
        "AWS-SageMaker-Python-SDK" not in boto_session.client("sagemaker")._client_config.user_agent
    )

    with patch("six.moves.builtins.open", mock_open(read_data="120.0-0")) as mo:
        sess = Session(boto_session)

        mo.assert_called_with("/etc/opt/ml/sagemaker-notebook-instance-version.txt")

    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_client._client_config.user_agent
    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_runtime_client._client_config.user_agent
    assert "AWS-SageMaker-Notebook-Instance" in sess.sagemaker_client._client_config.user_agent
    assert (
        "AWS-SageMaker-Notebook-Instance" in sess.sagemaker_runtime_client._client_config.user_agent
    ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:18,代码来源:test_session.py

示例8: test_user_agent_injected_with_nbi_ioerror

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def test_user_agent_injected_with_nbi_ioerror(boto_session):
    assert (
        "AWS-SageMaker-Python-SDK" not in boto_session.client("sagemaker")._client_config.user_agent
    )

    with patch("six.moves.builtins.open", MagicMock(side_effect=IOError("File not found"))) as mo:
        sess = Session(boto_session)

        mo.assert_called_with("/etc/opt/ml/sagemaker-notebook-instance-version.txt")

    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_client._client_config.user_agent
    assert "AWS-SageMaker-Python-SDK" in sess.sagemaker_runtime_client._client_config.user_agent
    assert "AWS-SageMaker-Notebook-Instance" not in sess.sagemaker_client._client_config.user_agent
    assert (
        "AWS-SageMaker-Notebook-Instance"
        not in sess.sagemaker_runtime_client._client_config.user_agent
    ) 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:19,代码来源:test_session.py

示例9: sagemaker_session_ready_lifecycle

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session_ready_lifecycle():
    boto_mock = Mock(name="boto_session")
    boto_mock.client("logs").describe_log_streams.return_value = DEFAULT_LOG_STREAMS
    boto_mock.client("logs").get_log_events.side_effect = STREAM_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.side_effect = [
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        COMPLETED_DESCRIBE_JOB_RESULT,
    ]
    ims.sagemaker_client.describe_transform_job.side_effect = [
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        COMPLETED_DESCRIBE_TRANSFORM_JOB_RESULT,
    ]
    return ims 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:18,代码来源:test_session.py

示例10: sagemaker_session_full_lifecycle

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session_full_lifecycle():
    boto_mock = Mock(name="boto_session")
    boto_mock.client("logs").describe_log_streams.side_effect = LIFECYCLE_LOG_STREAMS
    boto_mock.client("logs").get_log_events.side_effect = STREAM_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.side_effect = [
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_JOB_RESULT,
        COMPLETED_DESCRIBE_JOB_RESULT,
    ]
    ims.sagemaker_client.describe_transform_job.side_effect = [
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        IN_PROGRESS_DESCRIBE_TRANSFORM_JOB_RESULT,
        COMPLETED_DESCRIBE_TRANSFORM_JOB_RESULT,
    ]
    return ims 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:18,代码来源:test_session.py

示例11: test_download_folder_points_to_single_file

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def test_download_folder_points_to_single_file(makedirs):
    boto_mock = Mock(name="boto_session")
    boto_mock.client("sts").get_caller_identity.return_value = {"Account": "123"}

    session = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())

    train_data = Mock()

    train_data.bucket_name.return_value = BUCKET_NAME
    train_data.key = "prefix/train/train_data.csv"

    s3_files = [train_data]
    boto_mock.resource("s3").Bucket(BUCKET_NAME).objects.filter.return_value = s3_files

    obj_mock = Mock()
    boto_mock.resource("s3").Object.return_value = obj_mock

    # all the S3 mocks are set, the test itself begins now.
    sagemaker.utils.download_folder(BUCKET_NAME, "/prefix/train/train_data.csv", "/tmp", session)

    obj_mock.download_file.assert_called()
    calls = [call(os.path.join("/tmp", "train_data.csv"))]
    obj_mock.download_file.assert_has_calls(calls)
    boto_mock.resource("s3").Bucket(BUCKET_NAME).objects.filter.assert_not_called()
    obj_mock.reset_mock() 
开发者ID:aws,项目名称:sagemaker-python-sdk,代码行数:27,代码来源:test_utils.py

示例12: fixture_sagemaker_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def fixture_sagemaker_session(region):
    return Session(boto_session=boto3.Session(region_name=region)) 
开发者ID:aws,项目名称:sagemaker-xgboost-container,代码行数:4,代码来源:conftest.py

示例13: fixture_sagemaker_local_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def fixture_sagemaker_local_session(region):
    return LocalSession(boto_session=boto3.Session(region_name=region)) 
开发者ID:aws,项目名称:sagemaker-pytorch-training-toolkit,代码行数:4,代码来源:conftest.py

示例14: sagemaker_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_session(region):
    return Session(boto_session=boto3.Session(region_name=region)) 
开发者ID:aws,项目名称:sagemaker-mxnet-inference-toolkit,代码行数:4,代码来源:conftest.py

示例15: sagemaker_local_session

# 需要导入模块: import sagemaker [as 别名]
# 或者: from sagemaker import Session [as 别名]
def sagemaker_local_session(region):
    return LocalSession(boto_session=boto3.Session(region_name=region)) 
开发者ID:aws,项目名称:sagemaker-mxnet-inference-toolkit,代码行数:4,代码来源:conftest.py


注:本文中的sagemaker.Session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。