Skip to content

Commit a6b4840

Browse files
fix(sdk): resolve errors in deserialization (kubeflow#2457)
* fix(sdk): import kubernetes.client & make type conversion in swagger.json. Signed-off-by: Electronic-Waste <[email protected]> * fix(sdk): change Union[int, str] to object. Signed-off-by: Electronic-Waste <[email protected]> --------- Signed-off-by: Electronic-Waste <[email protected]>
1 parent 352c795 commit a6b4840

9 files changed

+18
-14
lines changed

hack/python-sdk/gen-sdk.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ else
6666
fi
6767

6868
# Kubeflow models must have Kubernetes models to perform serialization.
69-
printf "\n# Import JobSet models for the serialization. It imports the Kubernetes models.\n" >>${SDK_OUTPUT_PATH}/kubeflow/trainer/models/__init__.py
69+
printf "\n# Import Kubernetes and JobSet models for the serialization. \n" >>${SDK_OUTPUT_PATH}/kubeflow/trainer/models/__init__.py
70+
printf "from kubernetes.client import *\n" >>${SDK_OUTPUT_PATH}/kubeflow/trainer/models/__init__.py
7071
printf "from jobset.models import *\n" >>${SDK_OUTPUT_PATH}/kubeflow/trainer/models/__init__.py

hack/python-sdk/swagger_config.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"packageName": "kubeflow.trainer",
33
"typeMappings": {
4+
"K8sIoApiAutoscalingV2MetricSpec": "V2MetricSpec",
5+
"K8sIoApimachineryPkgUtilIntstrIntOrString": "object",
46
"V1Time": "datetime"
57
}
68
}

sdk/docs/TrainerV1alpha1TorchElasticPolicy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**max_nodes** | **int** | Upper limit for the number of nodes to which training job can scale up. | [optional]
88
**max_restarts** | **int** | How many times the training job can be restarted. This value is inserted into the &#x60;--max-restarts&#x60; argument of the &#x60;torchrun&#x60; CLI and the &#x60;.spec.failurePolicy.maxRestarts&#x60; parameter of the training Job. | [optional]
9-
**metrics** | [**list[K8sIoApiAutoscalingV2MetricSpec]**](K8sIoApiAutoscalingV2MetricSpec.md) | Specification which are used to calculate the desired number of nodes. See the individual metric source types for more information about how each type of metric must respond. The HPA will be created to perform auto-scaling. | [optional]
9+
**metrics** | [**list[V2MetricSpec]**](K8sIoApiAutoscalingV2MetricSpec.md) | Specification which are used to calculate the desired number of nodes. See the individual metric source types for more information about how each type of metric must respond. The HPA will be created to perform auto-scaling. | [optional]
1010
**min_nodes** | **int** | Lower limit for the number of nodes to which training job can scale down. | [optional]
1111

1212
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

sdk/docs/TrainerV1alpha1TorchMLPolicySource.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TorchMLPolicySource represents a PyTorch runtime configuration.
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**elastic_policy** | [**TrainerV1alpha1TorchElasticPolicy**](TrainerV1alpha1TorchElasticPolicy.md) | | [optional]
8-
**num_proc_per_node** | [**K8sIoApimachineryPkgUtilIntstrIntOrString**](K8sIoApimachineryPkgUtilIntstrIntOrString.md) | | [optional]
8+
**num_proc_per_node** | [**object**](K8sIoApimachineryPkgUtilIntstrIntOrString.md) | | [optional]
99

1010
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1111

sdk/docs/TrainerV1alpha1Trainer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Name | Type | Description | Notes
99
**env** | [**list[V1EnvVar]**](V1EnvVar.md) | List of environment variables to set in the training container. These values will be merged with the TrainingRuntime&#39;s trainer environments. | [optional]
1010
**image** | **str** | Docker image for the training container. | [optional]
1111
**num_nodes** | **int** | Number of training nodes. | [optional]
12-
**num_proc_per_node** | [**K8sIoApimachineryPkgUtilIntstrIntOrString**](K8sIoApimachineryPkgUtilIntstrIntOrString.md) | | [optional]
12+
**num_proc_per_node** | [**object**](K8sIoApimachineryPkgUtilIntstrIntOrString.md) | | [optional]
1313
**resources_per_node** | [**V1ResourceRequirements**](V1ResourceRequirements.md) | | [optional]
1414

1515
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

sdk/kubeflow/trainer/models/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
from kubeflow.trainer.models.trainer_v1alpha1_training_runtime_list import TrainerV1alpha1TrainingRuntimeList
4444
from kubeflow.trainer.models.trainer_v1alpha1_training_runtime_spec import TrainerV1alpha1TrainingRuntimeSpec
4545

46-
# Import JobSet models for the serialization. It imports the Kubernetes models.
46+
# Import Kubernetes and JobSet models for the serialization.
47+
from kubernetes.client import *
4748
from jobset.models import *

sdk/kubeflow/trainer/models/trainer_v1alpha1_torch_elastic_policy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TrainerV1alpha1TorchElasticPolicy(object):
3535
openapi_types = {
3636
'max_nodes': 'int',
3737
'max_restarts': 'int',
38-
'metrics': 'list[K8sIoApiAutoscalingV2MetricSpec]',
38+
'metrics': 'list[V2MetricSpec]',
3939
'min_nodes': 'int'
4040
}
4141

@@ -120,7 +120,7 @@ def metrics(self):
120120
Specification which are used to calculate the desired number of nodes. See the individual metric source types for more information about how each type of metric must respond. The HPA will be created to perform auto-scaling. # noqa: E501
121121
122122
:return: The metrics of this TrainerV1alpha1TorchElasticPolicy. # noqa: E501
123-
:rtype: list[K8sIoApiAutoscalingV2MetricSpec]
123+
:rtype: list[V2MetricSpec]
124124
"""
125125
return self._metrics
126126

@@ -131,7 +131,7 @@ def metrics(self, metrics):
131131
Specification which are used to calculate the desired number of nodes. See the individual metric source types for more information about how each type of metric must respond. The HPA will be created to perform auto-scaling. # noqa: E501
132132
133133
:param metrics: The metrics of this TrainerV1alpha1TorchElasticPolicy. # noqa: E501
134-
:type: list[K8sIoApiAutoscalingV2MetricSpec]
134+
:type: list[V2MetricSpec]
135135
"""
136136

137137
self._metrics = metrics

sdk/kubeflow/trainer/models/trainer_v1alpha1_torch_ml_policy_source.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TrainerV1alpha1TorchMLPolicySource(object):
3434
"""
3535
openapi_types = {
3636
'elastic_policy': 'TrainerV1alpha1TorchElasticPolicy',
37-
'num_proc_per_node': 'K8sIoApimachineryPkgUtilIntstrIntOrString'
37+
'num_proc_per_node': 'object'
3838
}
3939

4040
attribute_map = {
@@ -84,7 +84,7 @@ def num_proc_per_node(self):
8484
8585
8686
:return: The num_proc_per_node of this TrainerV1alpha1TorchMLPolicySource. # noqa: E501
87-
:rtype: K8sIoApimachineryPkgUtilIntstrIntOrString
87+
:rtype: object
8888
"""
8989
return self._num_proc_per_node
9090

@@ -94,7 +94,7 @@ def num_proc_per_node(self, num_proc_per_node):
9494
9595
9696
:param num_proc_per_node: The num_proc_per_node of this TrainerV1alpha1TorchMLPolicySource. # noqa: E501
97-
:type: K8sIoApimachineryPkgUtilIntstrIntOrString
97+
:type: object
9898
"""
9999

100100
self._num_proc_per_node = num_proc_per_node

sdk/kubeflow/trainer/models/trainer_v1alpha1_trainer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class TrainerV1alpha1Trainer(object):
3838
'env': 'list[V1EnvVar]',
3939
'image': 'str',
4040
'num_nodes': 'int',
41-
'num_proc_per_node': 'K8sIoApimachineryPkgUtilIntstrIntOrString',
41+
'num_proc_per_node': 'object',
4242
'resources_per_node': 'V1ResourceRequirements'
4343
}
4444

@@ -203,7 +203,7 @@ def num_proc_per_node(self):
203203
204204
205205
:return: The num_proc_per_node of this TrainerV1alpha1Trainer. # noqa: E501
206-
:rtype: K8sIoApimachineryPkgUtilIntstrIntOrString
206+
:rtype: object
207207
"""
208208
return self._num_proc_per_node
209209

@@ -213,7 +213,7 @@ def num_proc_per_node(self, num_proc_per_node):
213213
214214
215215
:param num_proc_per_node: The num_proc_per_node of this TrainerV1alpha1Trainer. # noqa: E501
216-
:type: K8sIoApimachineryPkgUtilIntstrIntOrString
216+
:type: object
217217
"""
218218

219219
self._num_proc_per_node = num_proc_per_node

0 commit comments

Comments
 (0)