aws / aws/sagemaker-python-sdk
Incorrect type annotation of hyperparameter_ranges argument of HyperparameterTuner constructor
- Ngôn ngữ chính
- Python
- Star
- 2.3k
- Fork
- 1.3k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 35
Mô tả
**Describe the bug**
hyperparameter_ranges argument of HyperparameterTuner constructor is annotated as Dict[str, ParameterRange], however HyperparameterTuner works correctly with PipelineVariable as key of Dict (hyperparam name), so the correct type annotation could be: Dict[str, ParameterRange]
**To reproduce**
That code works properly:
```python
from sagemaker.pytorch import PyTorch
from sagemaker.tuner import HyperparameterTuner, CategoricalParameter
from sagemaker.workflow.parameters import ParameterString
from sagemaker.workflow.steps import TuningStep
from sagemaker.workflow.pipeline import Pipeline
from sagemaker.workflow.pipeline_context import (
PipelineSession
)
if __name__ == "__main__":
pipeline_session = PipelineSession()
estimator = PyTorch(
sagemaker_session=pipeline_session,
instance_type='ml.m5.large',
instance_count=1,
framework_version="2.3",
py_version="py311",
source_dir='source',
entry_point='main.py',
metric_definitions=[
{'Name': 'valid:loss', 'Regex': 'valid_loss=([0-9]+\\.?[0-9]*)'}
]
)
hparam_name = ParameterString("HParamName", default_value='hparam')
tuner = HyperparameterTuner(
estimator=estimator,
objective_metric_name='valid:loss',
objective_type='Minimize',
hyperparameter_ranges={
hparam_name: CategoricalParameter(
[1, 2]
)
},
max_jobs=2,
max_parallel_jobs=1,
base_tuning_job_name='test-tuning',
strategy='Grid',
metric_definitions=estimator.metric_definitions,
)
tuning_step = TuningStep(
name="Tuning",
step_args=tuner.fit(),
)
pipeline = Pipeline(
name="TestTuningPipeline",
parameters=[hparam_name],
steps=[tuning_step],
sagemaker_session=pipeline_session
)
pipeline.upsert()
execution = pipeline.start(
execution_display_name="TuningTest",
)
print(execution)
```
But the type annotation of hyperparameter_ranges is incorrect.
`mypy main.py --follow-untyped-imports` reports:
```
test.py:35: error: Dict entry 0 has incompatible type "ParameterString": "CategoricalParameter"; expected "str": "ParameterRange" [dict-item]
```
**Expected behavior**
Correct type annotation of constructor arguments of HyperparameterTuner
**Screenshots or logs**
-
**System information**
A description of your system. Please provide:
- **SageMaker Python SDK version**: 2.239.3
- **Framework name (eg. PyTorch) or algorithm (eg. KMeans)**: iirelevant
- **Framework version**: iirelevant
- **Python version**: 3.12
- **CPU or GPU**: iirelevant
- **Custom Docker image (Y/N)**: iirelevant
**Additional context**
-
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu từ constructor của HyperparameterTuner và kiểm tra annotation của hyperparameter_ranges, sử dụng ví dụ được cung cấp để truy vết kiểu key được chấp nhận. Chạy mypy main.py --follow-untyped-imports và xác nhận rằng lỗi dict-item được báo cáo đã biến mất, trong khi constructor vẫn được định kiểu chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- aws, python
- Lĩnh vực
- machine-learning
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100