|
| 1 | +# Auto-Tuning for ChatQnA: Optimizing Resource Allocation in Kubernetes |
| 2 | + |
| 3 | +This document describes the Auto-Tuning framework, a tool designed to streamline deployment strategies for resource-intensive services, particularly in ChatQnA environments. It leverages Kubernetes for container orchestration and integrates experimental data with out prior knowledge to fine-tune deployments for optimal performance. |
| 4 | + |
| 5 | +## Key Features |
| 6 | +* Hardware Efficiency: Focuses on adjusting replica counts and maximizing the utilization of CPU and HPU (Habana Processing Unit) resources. |
| 7 | + |
| 8 | +* Theoretical and Experimental Optimization: Integrates theoretical best practices with our prior knowledge to ensure optimal resource allocation for services. |
| 9 | + |
| 10 | +# Usage |
| 11 | + |
| 12 | +To generate the strategy.json configuration file for deployment, use the following command: |
| 13 | + |
| 14 | + |
| 15 | +```bash |
| 16 | +# Kubernetes Deployment |
| 17 | +python3 tuning.py --tuning_config replica_tuning_config.json --hardware_info hardware_info_gaudi.json --service_info chatqna_neuralchat_rerank_latest.yaml |
| 18 | + |
| 19 | +# Note: Add --config_only to output deployment configs only. |
| 20 | +``` |
| 21 | + |
| 22 | +## Configuration Files |
| 23 | +1. hardware_info_gaudi.json: Specifies the hardware details (CPU, HPU, etc.). |
| 24 | + |
| 25 | +2. chatqna_neuralchat_rerank_latest.yaml: Contains service deployment information. |
| 26 | + |
| 27 | +3. tuning_config.json: Customizes tuning parameters for replica counts and granularity. |
| 28 | + |
| 29 | +### Hardrware_info.json |
| 30 | +This file lists only the hardware devices to be used in deployment. |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "device_0": { |
| 35 | + "ip": ["10.239.1.5", "10.239.10.6"], |
| 36 | + "type": "hpu", |
| 37 | + "sockets": 2, |
| 38 | + "cores_per_socket": 64, |
| 39 | + "num_cards": 8 |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | +Please refer to `hardware_info_gaudi.json` for more details. |
| 44 | + |
| 45 | +### chatqna_neuralchat_rerank_latest.yaml |
| 46 | +This file includes all services that will be deployed. |
| 47 | +```yaml |
| 48 | +opea_micro_services: |
| 49 | + data_prep: |
| 50 | + ... ... |
| 51 | + embedding: |
| 52 | + ... ... |
| 53 | + |
| 54 | + reranking: |
| 55 | + ... ... |
| 56 | + |
| 57 | + llm: |
| 58 | + opea/llm-tgi: |
| 59 | + tag: latest |
| 60 | + type: cpu |
| 61 | + dependency: |
| 62 | + ghcr.io/huggingface/tgi-gaudi: |
| 63 | + tag: 2.0.4 |
| 64 | + type: hpu |
| 65 | + requirements: |
| 66 | + model_id: "Intel/neural-chat-7b-v3-3" |
| 67 | + |
| 68 | +opea_mega_service: |
| 69 | + opea/chatqna: |
| 70 | + tag: latest |
| 71 | + type: cpu |
| 72 | +``` |
| 73 | +Please refer to `chatqna_neuralchat_rerank_latest.yaml` for more details. |
| 74 | + |
| 75 | +### Tuning Config Parameters |
| 76 | + |
| 77 | +`embedding_replicas_granularity = 1`: This defines the step size for scaling the number of replicas for the embedding server. |
| 78 | +* Value (1): Each scaling operation increases or decreases the number of replicas by 1 at a time. |
| 79 | + |
| 80 | +`embedding_replicas_min = 1`: This sets the minimum number of replicas allowed for the embedding server. |
| 81 | +* Value (1): The service will always have at least 1 replica running, ensuring that it is available for deployment. |
| 82 | + |
| 83 | +`embedding_replicas_max = 4`: This defines the maximum number of replicas allowed for the embedding server. |
| 84 | +* Value (4): The service can be scaled up to a maximum of 4 replicas, limiting resource consumption and avoiding over-provisioning. |
| 85 | + |
| 86 | +`microservice_replicas_granularity = 1`: This specifies the scaling step size for other microservices (such as retrieval, dataprep, etc.). |
| 87 | +* Value (1): Similar to the embedding_replicas_granularity, the number of replicas for these microservices will scale by 1 replica at a time. |
| 88 | + |
| 89 | +`microservice_replicas_min = 1`: This parameter sets the minimum number of replicas for these microservices. |
| 90 | +* Value (1): Ensures that each microservice always has at least 1 replica running. |
| 91 | + |
| 92 | +`microservice_replicas_max = 4`: This defines the upper limit for scaling replicas for these microservices. |
| 93 | +* Value (4): The maximum number of replicas allowed for the microservices is 4. |
| 94 | + |
| 95 | + |
| 96 | +If you want to adjust the default tuning parameters, just create a replica_tuning_config.json file. For example: |
| 97 | + |
| 98 | +```json |
| 99 | +{ |
| 100 | + "embedding_replicas_granularity": 1, |
| 101 | + "embedding_replicas_min": 1, |
| 102 | + "embedding_replicas_max": 4, |
| 103 | +
|
| 104 | + "microservice_replicas_granularity": 1, |
| 105 | + "microservice_replicas_min": 1, |
| 106 | + "microservice_replicas_max": 4 |
| 107 | +} |
| 108 | +``` |
| 109 | +Please refer to `replica_tuning_config.json` for more details. |
| 110 | + |
| 111 | +## Output |
| 112 | + |
| 113 | +The output of the auto-tuning process includes two key components: |
| 114 | +1. strategy_files: Contains optimized configurations for deploying services, such as replica counts and hardware resource allocations. |
| 115 | + |
| 116 | +2. K8S manifests: Provides the Kubernetes deployment specifications, including pod definitions and resource limits, ready for deployment. |
| 117 | + |
| 118 | +Example of a strategy file: |
| 119 | +```json |
| 120 | +{ |
| 121 | + "embedding-dependency": { |
| 122 | + "type": "cpu", |
| 123 | + "image": "ghcr.io/huggingface/text-embeddings-inference:cpu-1.5", |
| 124 | + "model_id": "BAAI/bge-base-en-v1.5", |
| 125 | + "replica": 1 |
| 126 | + }, |
| 127 | + "llm-microservice": { |
| 128 | + "type": "cpu", |
| 129 | + "image": "opea/llm-tgi:latest", |
| 130 | + "replica": 4 |
| 131 | + }, |
| 132 | +
|
| 133 | + ... ... |
| 134 | + "reranking-dependency": { |
| 135 | + "type": "hpu", |
| 136 | + "image": "opea/tei-gaudi:latest", |
| 137 | + "model_id": "BAAI/bge-reranker-base", |
| 138 | + "replica": 1, |
| 139 | + "cards": 1 |
| 140 | + }, |
| 141 | + "chatqna_mega_service": { |
| 142 | + "image": "opea/chatqna:latest", |
| 143 | + "type": "cpu", |
| 144 | + "replica": 4 |
| 145 | + } |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +Both the K8S manifests and strategy files are generated in the current directory, providing everything needed for deployment. |
| 150 | + |
| 151 | +Deployment methods: simply run `kubectl apply -f` on the newly generated *_run.yaml files and the chatqna_config_map. |
0 commit comments