|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! |
| 25 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 26 | + |
| 27 | +// Represent a job's status |
| 28 | +// +kubebuilder:validation:Enum=New;Scheduled;Running;Complete;Cancelled |
| 29 | +type JobState string |
| 30 | + |
| 31 | +const ( |
| 32 | + // The job is just created |
| 33 | + NewJobState JobState = "New" |
| 34 | + // The job is scheduled and waiting for available resources to run it |
| 35 | + ScheduledJobState JobState = "Scheduled" |
| 36 | + // The job is running |
| 37 | + RunningJobState JobState = "Running" |
| 38 | + // The job is complete |
| 39 | + CompleteJobState JobState = "Complete" |
| 40 | + // The job is cancelled |
| 41 | + CancelledJobState JobState = "Cancelled" |
| 42 | +) |
| 43 | + |
| 44 | +// +kubebuilder:validation:Enum=NoReason;Succeeded;Failed;Cancelled |
| 45 | +type Reason string |
| 46 | + |
| 47 | +const ( |
| 48 | + // Job is still running and no final result yet |
| 49 | + NoReason Reason = "NoReason" |
| 50 | + // Job finished successfully |
| 51 | + SucceedReason Reason = "Succeeded" |
| 52 | + // Job failed |
| 53 | + FailedReason Reason = "Failed" |
| 54 | + // Job is cancelled |
| 55 | + CancelledReason Reason = "Cancelled" |
| 56 | +) |
| 57 | + |
| 58 | +type Arg struct { |
| 59 | + Name string `json:"name"` |
| 60 | + Value string `json:"value,omitempty"` |
| 61 | +} |
| 62 | + |
| 63 | +type EnvSecret struct { |
| 64 | + // Environment's name |
| 65 | + Env string `json:"env"` |
| 66 | + // The secret is from a secret object |
| 67 | + // +optional |
| 68 | + SecretRef *corev1.SecretKeySelector `json:"secretRef,omitempty"` |
| 69 | + // The secret is from a plain text |
| 70 | + // +optional |
| 71 | + Secret *string `json:"secret,omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +// LMEvalJobSpec defines the desired state of LMEvalJob |
| 75 | +type LMEvalJobSpec struct { |
| 76 | + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster |
| 77 | + // Important: Run "make" to regenerate code after modifying this file |
| 78 | + |
| 79 | + // Model name |
| 80 | + Model string `json:"model"` |
| 81 | + // Args for the model |
| 82 | + // +optional |
| 83 | + ModelArgs []Arg `json:"modelArgs,omitempty"` |
| 84 | + // Evaluation tasks |
| 85 | + Tasks []string `json:"tasks"` |
| 86 | + // Sets the number of few-shot examples to place in context |
| 87 | + // +optional |
| 88 | + NumFewShot *int `json:"numFewShot,omitempty"` |
| 89 | + // Accepts an integer, or a float between 0.0 and 1.0 . If passed, will limit |
| 90 | + // the number of documents to evaluate to the first X documents (if an integer) |
| 91 | + // per task or first X% of documents per task |
| 92 | + // +optional |
| 93 | + Limit string `json:"limit,omitempty"` |
| 94 | + // Map to `--gen_kwargs` parameter for the underlying library. |
| 95 | + // +optional |
| 96 | + GenArgs []Arg `json:"genArgs,omitempty"` |
| 97 | + // If this flag is passed, then the model's outputs, and the text fed into the |
| 98 | + // model, will be saved at per-document granularity |
| 99 | + // +optional |
| 100 | + LogSamples *bool `json:"logSamples,omitempty"` |
| 101 | + // Assign secrets to the environment variables |
| 102 | + // +optional |
| 103 | + EnvSecrets []EnvSecret `json:"envSecrets,omitempty"` |
| 104 | +} |
| 105 | + |
| 106 | +// LMEvalJobStatus defines the observed state of LMEvalJob |
| 107 | +type LMEvalJobStatus struct { |
| 108 | + // Important: Run "make" to regenerate code after modifying this file |
| 109 | + |
| 110 | + // The name of the Pod that runs the evaluation job |
| 111 | + // +optional |
| 112 | + PodName string `json:"podName,omitempty"` |
| 113 | + // State of the job |
| 114 | + // +optional |
| 115 | + State JobState `json:"state,omitempty"` |
| 116 | + // Final result of the job |
| 117 | + // +optional |
| 118 | + Reason Reason `json:"reason,omitempty"` |
| 119 | + // Message about the current/final status |
| 120 | + // +optional |
| 121 | + Message string `json:"message,omitempty"` |
| 122 | + // Information when was the last time the job was successfully scheduled. |
| 123 | + // +optional |
| 124 | + LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` |
| 125 | + // Information when the job's state changes to Complete. |
| 126 | + // +optional |
| 127 | + CompleteTime *metav1.Time `json:"completeTime,omitempty"` |
| 128 | + // Evaluation results |
| 129 | + // +optional |
| 130 | + Results string `json:"results,omitempty"` |
| 131 | +} |
| 132 | + |
| 133 | +// +kubebuilder:object:root=true |
| 134 | +// +kubebuilder:subresource:status |
| 135 | + |
| 136 | +// LMEvalJob is the Schema for the lmevaljobs API |
| 137 | +type LMEvalJob struct { |
| 138 | + metav1.TypeMeta `json:",inline"` |
| 139 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 140 | + |
| 141 | + Spec LMEvalJobSpec `json:"spec,omitempty"` |
| 142 | + Status LMEvalJobStatus `json:"status,omitempty"` |
| 143 | +} |
| 144 | + |
| 145 | +// +kubebuilder:object:root=true |
| 146 | + |
| 147 | +// LMEvalJobList contains a list of LMEvalJob |
| 148 | +type LMEvalJobList struct { |
| 149 | + metav1.TypeMeta `json:",inline"` |
| 150 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 151 | + Items []LMEvalJob `json:"items"` |
| 152 | +} |
| 153 | + |
| 154 | +func init() { |
| 155 | + SchemeBuilder.Register(&LMEvalJob{}, &LMEvalJobList{}) |
| 156 | +} |
0 commit comments