Updated on 2024-08-14 GMT+08:00

Obtaining Resources

Before creating a job phase, perform the following operations to obtain supported training flavors and engines:

  • Import packages.
    from modelarts.session import Session
    from modelarts.estimatorV2 import TrainingJob
    from modelarts.workflow.client.job_client import JobClient
  • Initialize a session.
    # If you develop a workflow in a local IDEA, initialize a session as follows:
    # Hardcoded or plaintext AK/SK is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.
    # In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
    __AK = os.environ["HUAWEICLOUD_SDK_AK"]
    __SK = os.environ["HUAWEICLOUD_SDK_SK"]
    # Decrypt the information if it is encrypted.
    session = Session(
        access_key=__AK, # AK information of your account
        secret_key=__SK, # SK information of your account
        region_name="***", # Region to which your account belongs
        project_id="***" # Project ID of your account
    )
    
    # If you develop a workflow in a notebook environment, initialize a session as follows:
    session = Session()
  • Obtain public resource pools.
    # Obtain the specification list of public resource pools.
    spec_list = TrainingJob(session).get_train_instance_types(session) # A list is returned. You can download it.
    print(spec_list)
  • Obtain dedicated resource pools.
    # Obtain the list of running dedicated resource pools.
    pool_list = JobClient(session).get_pool_list() # A list of dedicated resource pools is returned.
    pool_id_list = JobClient(session).get_pool_id_list() # An ID list of dedicated resource pools is returned.
    The following lists the flavor IDs of dedicated resource pools. Select one as required.
        modelarts.pool.visual.xlarge (1 card)
        modelarts.pool.visual.2xlarge (2 cards)
        modelarts.pool.visual.4xlarge (4 cards)
        modelarts.pool.visual.8xlarge (8 cards)
  • Obtain engine types.
    # Obtain engine types.
    engine_dict = TrainingJob(session).get_engine_list(session) # A dictionary is returned. You can download it.
    print(engine_dict)