Skip to content

Commit

Permalink
fix CodeReview comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pitt-liang committed Jun 27, 2024
1 parent b4b4fa5 commit b83a5db
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PAI Python SDK是阿里云 [机器学习平台 PAI(Platform for Artificial Intel

## 🔧 安装

使用以下命令安装PAI Python SDK(支持Python版本 \>= 3.6,建议使用Python版本 \>= 3.8):
使用以下命令安装PAI Python SDK(支持Python版本 \>= 3.8):

```shell
python -m pip install alipai
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The PAI Python SDK is provided by Alibaba Cloud\'s [Platform for Artificial Inte

## Installation 🔧

Install the PAI Python SDK using the following command, which supports Python versions \>= 3.6 (it is recommended to use Python \>= 3.8):
Install the PAI Python SDK using the following command, which supports Python versions \>= 3.8 :

```shell
python -m pip install alipai
Expand Down
2 changes: 1 addition & 1 deletion docs/source/quick-tour/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
安装
------

请通过以下命令安装PAI Python SDK(请使用Python>=3.6)。
请通过以下命令安装PAI Python SDK(请使用Python>=3.8)。

.. parsed-literal::
Expand Down
2 changes: 1 addition & 1 deletion pai/job/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Alibaba, Inc. or its affiliates.
# Copyright 2024 Alibaba, Inc. or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion pai/job/_local_training_job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Alibaba, Inc. or its affiliates.
# Copyright 2024 Alibaba, Inc. or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
26 changes: 19 additions & 7 deletions pai/job/_training_job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Alibaba, Inc. or its affiliates.
# Copyright 2024 Alibaba, Inc. or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
import os
import posixpath
import time
import typing
from concurrent.futures import ThreadPoolExecutor
from typing import Any, Dict, List, Optional, Union

Expand All @@ -39,6 +40,9 @@
from ..exception import UnexpectedStatusException
from ..session import Session, get_default_session

if typing.TYPE_CHECKING:
from ..estimator import FileSystemInputBase

logger = get_logger(__name__)


Expand Down Expand Up @@ -128,9 +132,6 @@ class ExperimentConfig(BaseAPIModel):
description="Specifies the ID of the experiment that training job instance belongs to.",
)

def __init__(self, experiment_id):
super().__init__(experiment_id=experiment_id)


class OssLocation(BaseAPIModel):
"""OSS location."""
Expand Down Expand Up @@ -243,6 +244,14 @@ class SchedulerConfig(BaseAPIModel):
max_running_time_in_seconds: Optional[int] = None


class MetricDefinition(BaseAPIModel):
description: Optional[str] = Field(None, description="Description of the metric.")
name: str = Field(..., description="Name of the metric.")
regex: str = Field(
..., description="Regular expression used for capturing the metric."
)


class AlgorithmSpec(BaseAPIModel):
"""Algorithm Specification."""

Expand All @@ -261,7 +270,9 @@ class AlgorithmSpec(BaseAPIModel):
supported_instance_types: Optional[List[str]] = Field(
None, description="Supported instance types."
)
metric_definitions: Optional[List] = Field(None, description="Metric definitions.")
metric_definitions: Optional[List[MetricDefinition]] = Field(
None, description="Metric definitions."
)
hyperparameter_definitions: List[HyperParameterDefinition] = Field(
default_factory=list,
alias="HyperParameter",
Expand Down Expand Up @@ -742,7 +753,6 @@ def _submit(
output_channels=outputs,
algorithm_spec=algorithm_spec.model_dump() if algorithm_spec else None,
requirements=requirements,
# experiment_config=
user_vpc_config=user_vpc_config,
labels=labels,
environments=environments,
Expand All @@ -756,7 +766,9 @@ def _submit(
training_job.wait(show_logs=show_logs)

@classmethod
def _get_input_config(cls, name: str, item: str):
def _get_input_config(
cls, name: str, item: Union[str, "FileSystemInputBase", DatasetConfig]
):
"""Get input uri for training_job from given input."""
from pai.estimator import FileSystemInputBase

Expand Down
5 changes: 1 addition & 4 deletions pai/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,10 +2145,7 @@ def get_evaluation_inputs(self) -> Dict[str, Any]:
res = {}

for item in inputs:
if isinstance(item, UriInput):
res[item.name] = item.input_uri
else:
res[item.name] = item
res[item.name] = item.input_uri if isinstance(item, UriInput) else item
return res

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions pai/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ def run(
outputs=outputs,
algorithm_spec=algo_spec,
user_vpc_config=(
self.user_vpc_config.to_dict() if self.user_vpc_config else None
self.user_vpc_config.model_dump() if self.user_vpc_config else None
),
experiment_config=(
self.experiment_config.to_dict() if self.experiment_config else None
self.experiment_config.model_dump() if self.experiment_config else None
),
labels=self.labels,
wait=wait,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def read_requirements():

setup(
name="alipai",
python_requires=">=3.6",
python_requires=">=3.8",
version=version,
setup_requires=["setuptools_scm"],
description="Alibaba Cloud PAI Python SDK",
Expand Down

0 comments on commit b83a5db

Please sign in to comment.