|
| 1 | +## Run llm test on k8s |
| 2 | + |
| 3 | +This document describes how to run the llm test on a Kubernetes cluster. |
| 4 | + |
| 5 | +### Tokenize the prompt file |
| 6 | + |
| 7 | +Suppose you have a [prompt file](./prompt-samples.txt) that contains the conversation info between the user and the chatbot. You can tokenize the prompt file by running the following command: |
| 8 | + |
| 9 | +```bash |
| 10 | +$ python tokenize_prompt.py --prompt-file prompt-samples.txt --file-num 1 |
| 11 | +``` |
| 12 | + |
| 13 | +After running the command, you will get a tokenized prompt file named `tokens_0` under the `small_files` directory. |
| 14 | + |
| 15 | +```bash |
| 16 | +$ ls small_files |
| 17 | +prompts_0.txt tokens_0 |
| 18 | +``` |
| 19 | + |
| 20 | +Also, you could set the `--file-num` to the number of files you want to split the prompt file into. If the prompt file is too large, you can split it into multiple files. Each file will be processed in parallel. |
| 21 | + |
| 22 | +``` |
| 23 | +$ python tokenize_prompt.py --prompt-file prompt-samples.txt --file-num 2 |
| 24 | +$ ls small_files |
| 25 | +prompts_0.txt prompts_1.txt tokens_0 tokens_1 |
| 26 | +``` |
| 27 | + |
| 28 | +At this point, you can put these token files to the OSS bucket or NAS refer to the [ossutil upload files](https://help.aliyun.com/zh/oss/user-guide/upload-objects-to-oss/?spm=a2c4g.11186623.0.0.4b471c22sHG1EG) or [nas mount](https://help.aliyun.com/zh/nas/user-guide/mount-an-nfs-file-system-on-a-linux-ecs-instance?spm=a2c4g.11186623.0.0.15713eedDgiEYF). |
| 29 | + |
| 30 | +### Build the master and worker images |
| 31 | + |
| 32 | +Before building the master and worker images, you need to build the vineyard-python-dev image first, as we need the llm-cache pypi package. |
| 33 | + |
| 34 | +```bash |
| 35 | +$ cd v6d && make -C docker vineyard-python-dev |
| 36 | +``` |
| 37 | + |
| 38 | +Then, you can build the master and worker images by running the following command: |
| 39 | + |
| 40 | +> Make sure the image registry is set correctly. |
| 41 | +
|
| 42 | +```bash |
| 43 | +$ cd modules/llm-cache/tests/k8s-test |
| 44 | +$ make build-images |
| 45 | +``` |
| 46 | + |
| 47 | +Next, push the images to the registry: |
| 48 | + |
| 49 | +```bash |
| 50 | +$ make push-images |
| 51 | +``` |
| 52 | + |
| 53 | +### Deploy on the k8s cluster |
| 54 | + |
| 55 | +#### Create the OSS volume |
| 56 | + |
| 57 | +Assume we have put the token files to the OSS bucket, we need to [create the oss secret and oss volume](https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/mount-statically-provisioned-oss-volumes#title-hos-c75-12q) first. |
| 58 | + |
| 59 | +#### Create the Distributed FileSystem Volume |
| 60 | + |
| 61 | +The DFS could be NAS or CPFS, you could refer to the [Mount Nas Volume on ACK](https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/mount-statically-provisioned-nas-volumes?spm=a2c4g.11186623.0.0.b7c130b7eJHcnf) or [Mount CPFS Volume on ACK](https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/statically-provisioned-cpfs-2-0-volumes-1?spm=a2c4g.11186623.0.0.399a22dbapWWsP) to create the volume. |
| 62 | + |
| 63 | +#### Deploy the worker |
| 64 | + |
| 65 | +After preparing the OSS volume, and DFS volume, you need change the NFS volume name `nas-csi-pvc` to the DFS volume you created before. |
| 66 | + |
| 67 | +> ** Note: ** The CPU resources is important for the performance of worker, you could adjust the `resources.requests.cpu` to get better performance. |
| 68 | +
|
| 69 | +Then deploy the worker by running the following command: |
| 70 | + |
| 71 | +```bash |
| 72 | +$ kubectl apply -f yamls/worker.yaml |
| 73 | +``` |
| 74 | + |
| 75 | +#### Deploy the master |
| 76 | + |
| 77 | +After deploying the worker, you need to change `TOKENS_FILE_NUM` environment variable in the `yamls/master.yaml` file to the number of token files you put in the OSS bucket. Also, the OSS VolumeClaimName `oss-pvc` should be set to the OSS volume you created. |
| 78 | + |
| 79 | +Then deploy the master by running the following command: |
| 80 | + |
| 81 | +```bash |
| 82 | +$ kubectl apply -f yamls/master.yaml |
| 83 | +``` |
| 84 | + |
| 85 | +### Show the result |
| 86 | + |
| 87 | +After running the llm test, you can check the result by running the following command: |
| 88 | + |
| 89 | +```bash |
| 90 | +$ python show_result.py --kubeconfig-path /your/kubeconfig --label-selector your_label_key=your_label_value |
| 91 | +``` |
0 commit comments