forked from kubeflow/katib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(trial): Add trial and metrics collector (kubeflow#3)
* feat(trial): Add trial and metrics collector Signed-off-by: Ce Gao <gaoce@caicloud.io> * fix: Remove debug statements Signed-off-by: Ce Gao <gaoce@caicloud.io>
- Loading branch information
1 parent
30f0f32
commit cd6d1e8
Showing
18 changed files
with
732 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
controller-tools.k8s.io: "1.0" | ||
name: experiments.kubeflow.org | ||
spec: | ||
group: kubeflow.org | ||
version: v1alpha2 | ||
names: | ||
kind: Experiment | ||
plural: experiments | ||
scope: Namespaced | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
controller-tools.k8s.io: "1.0" | ||
name: suggestions.kubeflow.org | ||
spec: | ||
group: kubeflow.org | ||
version: v1alpha2 | ||
names: | ||
kind: Suggestion | ||
plural: suggestions | ||
scope: Namespaced | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: apiextensions.k8s.io/v1beta1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
controller-tools.k8s.io: "1.0" | ||
name: trials.kubeflow.org | ||
spec: | ||
group: kubeflow.org | ||
version: v1alpha2 | ||
names: | ||
kind: Trial | ||
plural: trials | ||
scope: Namespaced | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apiVersion: kubeflow.org/v1alpha2 | ||
kind: Trial | ||
metadata: | ||
labels: | ||
controller-tools.k8s.io: "1.0" | ||
name: sample | ||
spec: | ||
objective: accuracy | ||
metrics: | ||
- loss | ||
MetricsCollector: general | ||
parameterAssignments: | ||
- name: param1 | ||
value: "1.2345" | ||
runSpec: |- | ||
apiVersion: "kubeflow.org/v1beta1" | ||
kind: "TFJob" | ||
metadata: | ||
name: "dist-mnist-for-e2e-test" | ||
spec: | ||
tfReplicaSpecs: | ||
Worker: | ||
replicas: 1 | ||
restartPolicy: Never | ||
template: | ||
spec: | ||
containers: | ||
- name: tensorflow | ||
image: gaocegege/mnist:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package apis | ||
|
||
import ( | ||
"github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1beta2" | ||
) | ||
|
||
func init() { | ||
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back | ||
AddToSchemes = append(AddToSchemes, v1beta2.SchemeBuilder.AddToScheme) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
pkg/api/operators/apis/trial/v1alpha2/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package clientset | ||
|
||
import ( | ||
"context" | ||
|
||
tfv1beta1 "github.com/kubeflow/tf-operator/pkg/apis/tensorflow/v1beta1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" | ||
|
||
trialv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/trial/v1alpha2" | ||
"github.com/kubeflow/katib/pkg/controller/v1alpha3/recorder" | ||
"github.com/kubeflow/katib/pkg/controller/v1alpha3/util" | ||
) | ||
|
||
const ( | ||
loggerNameTF = "tensorflow-client" | ||
) | ||
|
||
// TensorFlow is the type for tensorflow client. | ||
type TensorFlow interface { | ||
CreateOrUpdateTFJob(t *trialv1alpha2.Trial, tfJob *tfv1beta1.TFJob) error | ||
} | ||
|
||
// GeneralTF is the general client for TensorFlow. | ||
type GeneralTF struct { | ||
client.Client | ||
recorder.Recorder | ||
} | ||
|
||
// CreateOrUpdateTFJob creates or updates the TFJob owned by the trial. | ||
func (g *GeneralTF) CreateOrUpdateTFJob(t *trialv1alpha2.Trial, tfJob *tfv1beta1.TFJob) error { | ||
log := logf.Log.WithName(loggerNameTF) | ||
found := &tfv1beta1.TFJob{} | ||
err := g.Get(context.TODO(), types.NamespacedName{ | ||
Name: tfJob.Name, | ||
Namespace: tfJob.Namespace, | ||
}, found) | ||
if err != nil && errors.IsNotFound(err) { | ||
log.Info("Creating TFJob", "namespace", tfJob.Namespace, "name", tfJob.Name) | ||
err = g.Create(context.TODO(), tfJob) | ||
if err != nil { | ||
return err | ||
} | ||
g.ReportChange(t, util.FlagCreate, util.TypeTFJob) | ||
return nil | ||
} | ||
|
||
// // Update the found object and write the result back if there are any changes. | ||
// if !reflect.DeepEqual(tfJob.Spec, found.Spec) { | ||
// found.Spec = tfJob.Spec | ||
// log.Info("Updating TFJob", "namespace", tfJob.Namespace, "name", tfJob.Name) | ||
// err = g.Update(context.TODO(), tfJob) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// g.ReportChange(t, util.FlagUpdate, util.TypeTFJob) | ||
// } | ||
tfJob.Status = found.Status | ||
return nil | ||
} | ||
|
||
// New creates a new TFJob client. | ||
func NewTF(c client.Client, r recorder.Recorder) TensorFlow { | ||
return &GeneralTF{ | ||
Client: c, | ||
Recorder: r, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package clientset | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" | ||
|
||
trialv1alpha2 "github.com/kubeflow/katib/pkg/api/operators/apis/trial/v1alpha2" | ||
"github.com/kubeflow/katib/pkg/controller/v1alpha3/recorder" | ||
"github.com/kubeflow/katib/pkg/controller/v1alpha3/util" | ||
) | ||
|
||
const ( | ||
loggerNameUnstructured = "unstructured-client" | ||
) | ||
|
||
// Unstructured is the type for unstructured client. | ||
type Unstructured interface { | ||
CreateOrUpdateUnifiedJob(t *trialv1alpha2.Trial, job *unstructured.Unstructured) error | ||
} | ||
|
||
// GeneralUnstructured is the general client for Unstructured. | ||
type GeneralUnstructured struct { | ||
client.Client | ||
recorder.Recorder | ||
} | ||
|
||
// CreateOrUpdateUnifiedJob creates or updates the unified job owned by the trial. | ||
func (g *GeneralUnstructured) CreateOrUpdateUnifiedJob(t *trialv1alpha2.Trial, job *unstructured.Unstructured) error { | ||
typedName := types.NamespacedName{ | ||
Name: job.GetName(), | ||
Namespace: job.GetNamespace(), | ||
} | ||
logger := logf.Log.WithName(typedName.String()) | ||
found := job.DeepCopy() | ||
err := g.Get(context.TODO(), typedName, found) | ||
if err != nil && errors.IsNotFound(err) { | ||
logger.Info("Creating Job", "namespace", job.GetNamespace(), "name", job.GetName()) | ||
err = g.Create(context.TODO(), job) | ||
if err != nil { | ||
return err | ||
} | ||
g.ReportChange(t, util.FlagCreate, util.TypeTFJob) | ||
return nil | ||
} else if err != nil { | ||
return err | ||
} | ||
|
||
// We do not support updating now. | ||
return nil | ||
} | ||
|
||
// NewUnstructured creates a new Unstructured client. | ||
func NewUnstructured(c client.Client, r recorder.Recorder) Unstructured { | ||
return &GeneralUnstructured{ | ||
Client: c, | ||
Recorder: r, | ||
} | ||
} |
Oops, something went wrong.