|
| 1 | +/* |
| 2 | +Copyright 2023. |
| 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 odh |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + . "github.com/onsi/gomega" |
| 23 | + . "github.com/project-codeflare/codeflare-common/support" |
| 24 | + rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" |
| 25 | +) |
| 26 | + |
| 27 | +func TestRayFinetuneDemo(t *testing.T) { |
| 28 | + mnistRayLlmFinetune(t, 1) |
| 29 | +} |
| 30 | + |
| 31 | +func mnistRayLlmFinetune(t *testing.T, numGpus int) { |
| 32 | + test := With(t) |
| 33 | + |
| 34 | + // Create a namespace |
| 35 | + namespace := test.NewTestNamespace() |
| 36 | + |
| 37 | + // Test configuration |
| 38 | + jupyterNotebookConfigMapFileName := "ray_finetune_llm_deepspeed.ipynb" |
| 39 | + |
| 40 | + // Test configuration |
| 41 | + configMap := map[string][]byte{ |
| 42 | + // MNIST Ray Notebook |
| 43 | + jupyterNotebookConfigMapFileName: ReadFile(test, "resources/ray_finetune_demo/ray_finetune_llm_deepspeed.ipynb"), |
| 44 | + "ray_finetune_llm_deepspeed.py": ReadFile(test, "resources/ray_finetune_demo/ray_finetune_llm_deepspeed.py"), |
| 45 | + "ray_finetune_requirements.txt": ReadRayFinetuneRequirementsTxt(test), |
| 46 | + "create_dataset.py": ReadFile(test, "resources/ray_finetune_demo/create_dataset.py"), |
| 47 | + "lora.json": ReadFile(test, "resources/ray_finetune_demo/lora.json"), |
| 48 | + "zero_3_llama_2_7b.json": ReadFile(test, "resources/ray_finetune_demo/zero_3_llama_2_7b.json"), |
| 49 | + "utils.py": ReadFile(test, "resources/ray_finetune_demo/utils.py"), |
| 50 | + } |
| 51 | + |
| 52 | + config := CreateConfigMap(test, namespace.Name, configMap) |
| 53 | + |
| 54 | + // Define the regular(non-admin) user |
| 55 | + userName := GetNotebookUserName(test) |
| 56 | + userToken := GetNotebookUserToken(test) |
| 57 | + |
| 58 | + // Create role binding with Namespace specific admin cluster role |
| 59 | + CreateUserRoleBindingWithClusterRole(test, userName, namespace.Name, "admin") |
| 60 | + |
| 61 | + // Create Notebook CR |
| 62 | + createNotebook(test, namespace, userToken, config.Name, jupyterNotebookConfigMapFileName, numGpus) |
| 63 | + |
| 64 | + // Gracefully cleanup Notebook |
| 65 | + defer func() { |
| 66 | + deleteNotebook(test, namespace) |
| 67 | + test.Eventually(listNotebooks(test, namespace), TestTimeoutGpuProvisioning).Should(HaveLen(0)) |
| 68 | + }() |
| 69 | + |
| 70 | + // Make sure the RayCluster is created and running |
| 71 | + test.Eventually(RayClusters(test, namespace.Name), TestTimeoutGpuProvisioning). |
| 72 | + Should( |
| 73 | + And( |
| 74 | + HaveLen(1), |
| 75 | + ContainElement(WithTransform(RayClusterState, Equal(rayv1.Ready))), |
| 76 | + ), |
| 77 | + ) |
| 78 | + |
| 79 | + // Make sure the RayCluster finishes and is deleted |
| 80 | + test.Eventually(RayClusters(test, namespace.Name), TestTimeoutGpuProvisioning). |
| 81 | + Should(HaveLen(0)) |
| 82 | +} |
| 83 | + |
| 84 | +func ReadRayFinetuneRequirementsTxt(test Test) []byte { |
| 85 | + // Read the requirements.txt from resources and perform replacements for custom values using go template |
| 86 | + props := struct { |
| 87 | + PipIndexUrl string |
| 88 | + PipTrustedHost string |
| 89 | + }{ |
| 90 | + PipIndexUrl: "--index " + string(GetPipIndexURL()), |
| 91 | + } |
| 92 | + |
| 93 | + // Provide trusted host only if defined |
| 94 | + if len(GetPipTrustedHost()) > 0 { |
| 95 | + props.PipTrustedHost = "--trusted-host " + GetPipTrustedHost() |
| 96 | + } |
| 97 | + |
| 98 | + template, err := files.ReadFile("resources/ray_finetune_demo/ray_finetune_requirements.txt") |
| 99 | + test.Expect(err).NotTo(HaveOccurred()) |
| 100 | + |
| 101 | + return ParseTemplate(test, template, props) |
| 102 | +} |
0 commit comments