示例#1
0
    def __init__(self,
                 model_data,
                 role,
                 entry_point,
                 framework_version,
                 image_uri=None,
                 py_version="py3",
                 predictor_cls=XGBoostPredictor,
                 model_server_workers=None,
                 **kwargs):
        """Initialize an XGBoostModel.

        Args:
            model_data (str): The S3 location of a SageMaker model data ``.tar.gz`` file.
            role (str): An AWS IAM role (either name or full ARN). The Amazon SageMaker training
                jobs and APIs that create Amazon SageMaker endpoints use this role to access
                training data and model artifacts. After the endpoint is created, the inference
                code might use the IAM role, if it needs to access an AWS resource.
            entry_point (str): Path (absolute or relative) to the Python source file which should
                be executed  as the entry point to model hosting. If ``source_dir`` is specified,
                then ``entry_point`` must point to a file located at the root of ``source_dir``.
            image_uri (str): A Docker image URI (default: None). If not specified, a default image
                for XGBoost is be used.
            py_version (str): Python version you want to use for executing your model training code
                (default: 'py3').
            framework_version (str): XGBoost version you want to use for executing your model
                training code.
            predictor_cls (callable[str, sagemaker.session.Session]): A function to call to create
                a predictor with an endpoint name and SageMaker ``Session``.
                If specified, ``deploy()`` returns the result of invoking this function on the
                created endpoint name.
            model_server_workers (int): Optional. The number of worker processes used by the
                inference server. If None, server will use one worker per vCPU.
            **kwargs: Keyword arguments passed to the superclass
                :class:`~sagemaker.model.FrameworkModel` and, subsequently, its
                superclass :class:`~sagemaker.model.Model`.

        .. tip::

            You can find additional parameters for initializing this class at
            :class:`~sagemaker.model.FrameworkModel` and
            :class:`~sagemaker.model.Model`.
        """
        super(XGBoostModel, self).__init__(model_data,
                                           image_uri,
                                           role,
                                           entry_point,
                                           predictor_cls=predictor_cls,
                                           **kwargs)

        self.py_version = py_version
        self.framework_version = framework_version
        self.model_server_workers = model_server_workers

        validate_py_version(py_version)
        validate_framework_version(framework_version)
示例#2
0
    def __init__(self,
                 entry_point,
                 framework_version,
                 source_dir=None,
                 hyperparameters=None,
                 py_version="py3",
                 image_uri=None,
                 **kwargs):
        """An estimator that executes an XGBoost-based SageMaker Training Job.

        The managed XGBoost environment is an Amazon-built Docker container thatexecutes functions
        defined in the supplied ``entry_point`` Python script.

        Training is started by calling :meth:`~sagemaker.amazon.estimator.Framework.fit` on this
        Estimator. After training is complete, calling
        :meth:`~sagemaker.amazon.estimator.Framework.deploy` creates a hosted SageMaker endpoint
        and returns an :class:`~sagemaker.amazon.xgboost.model.XGBoostPredictor` instance that
        can be used to perform inference against the hosted model.

        Technical documentation on preparing XGBoost scripts for SageMaker training and using the
        XGBoost Estimator is available on the project home-page:
        https://github.com/aws/sagemaker-python-sdk

        Args:
            entry_point (str): Path (absolute or relative) to the Python source file which should
                be executed as the entry point to training.  If ``source_dir`` is specified,
                then ``entry_point`` must point to a file located at the root of ``source_dir``.
            framework_version (str): XGBoost version you want to use for executing your model
                training code.
            source_dir (str): Path (absolute, relative or an S3 URI) to a directory
                with any other training source code dependencies aside from the entry
                point file (default: None). If ``source_dir`` is an S3 URI, it must
                point to a tar.gz file. Structure within this directory are preserved
                when training on Amazon SageMaker.
            hyperparameters (dict): Hyperparameters that will be used for training (default: None).
                The hyperparameters are made accessible as a dict[str, str] to the training code
                on SageMaker. For convenience, this accepts other types for keys and values, but
                ``str()`` will be called to convert them before training.
            py_version (str): Python version you want to use for executing your model
                training code (default: 'py3').
            image_uri (str): If specified, the estimator will use this image for training and
                hosting, instead of selecting the appropriate SageMaker official image
                based on framework_version and py_version. It can be an ECR url or
                dockerhub image and tag.
                Examples:
                    123.dkr.ecr.us-west-2.amazonaws.com/my-custom-image:1.0
                    custom-image:latest.
            **kwargs: Additional kwargs passed to the
                :class:`~sagemaker.estimator.Framework` constructor.

        .. tip::

            You can find additional parameters for initializing this class at
            :class:`~sagemaker.estimator.Framework` and
            :class:`~sagemaker.estimator.EstimatorBase`.
        """
        instance_type = renamed_kwargs("train_instance_type", "instance_type",
                                       kwargs.get("instance_type"), kwargs)
        super(XGBoost, self).__init__(entry_point,
                                      source_dir,
                                      hyperparameters,
                                      image_uri=image_uri,
                                      **kwargs)

        self.py_version = py_version
        self.framework_version = framework_version

        validate_py_version(py_version)
        validate_framework_version(framework_version)

        if image_uri is None:
            self.image_uri = image_uris.retrieve(
                self._framework_name,
                self.sagemaker_session.boto_region_name,
                version=framework_version,
                py_version=self.py_version,
                instance_type=instance_type,
                image_scope="training",
            )