otcbot[bot] 2d9d363ec9
Update content (#29)
Changes to ma_umn from doc-exports#1


This is an automatically created Pull Request for changes to ma_umn in opentelekomcloud-docs/doc-exports#1.
Please do not edit it manually, since update to the original PR will overwrite local changes.
Original patch file, as well as complete rst archive,  can be found in the artifacts of the opentelekomcloud-docs/doc-exports#1

Reviewed-by: kucerakk <kucerakk@gmail.com>
2022-05-09 12:59:46 +00:00

7.1 KiB

original_name

modelarts_23_0335.html

Using ModelArts SDKs

In notebook instances, you can use ModelArts SDKs to manage OBS, training jobs, models, and real-time services.

For details about how to use ModelArts SDKs, see ModelArts SDK Reference.

Notebooks carry the authentication (AK/SK) and region information about login users. Therefore, SDK session authentication can be completed without entering parameters.

Example Code

  • Creating a training job

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    from modelarts.session import Session
    from modelarts.estimator import Estimator
    session = Session()
    estimator = Estimator(
                          modelarts_session=session,
                          framework_type='PyTorch',                                     # AI engine name
                           framework_version='PyTorch-1.0.0-python3.6',                  # AI engine version
                          code_dir='/obs-bucket-name/src/',                                      # Training script directory
                          boot_file='/obs-bucket-name/src/pytorch_sentiment.py',                 # Training startup script directory
                          log_url='/obs-bucket-name/log/',                                       # Training log directory
                          hyperparameters=[
                                           {"label":"classes",
                                            "value": "10"},
                                           {"label":"lr",
                                            "value": "0.001"}
                                           ],
                          output_path='/obs-bucket-name/output/',                                # Training output directory
                          train_instance_type='modelarts.vm.gpu.p100',                  # Training environment specifications
                          train_instance_count=1,                                       # Number of training nodes
                          job_description='pytorch-sentiment with ModelArts SDK')       # Training job description
    job_instance = estimator.fit(inputs='/obs-bucket-name/data/train/', wait=False, job_name='my_training_job')
  • Querying a model list

    1
    2
    3
    4
    from modelarts.session import Session
    from modelarts.model import Model
    session = Session()
    model_list_resp = Model.get_model_list(session, model_status="published", model_name="digit", order="desc")
  • Querying service details

    1
    2
    3
    4
    5
    from modelarts.session import Session
    from modelarts.model import Predictor
    session = Session()
    predictor_instance = Predictor(session, service_id="input your service_id")
    predictor_info_resp = predictor_instance.get_service_info()