|
| 1 | +# LLM Performance Comparator - Technical Documentation |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | +- [Prerequisites](#prerequisites) |
| 5 | +- [Installation](#installation) |
| 6 | +- [Configuration](#configuration) |
| 7 | +- [Dataset Preparation](#dataset-preparation) |
| 8 | +- [Usage Instructions](#usage-instructions) |
| 9 | +- [Architecture](#architecture) |
| 10 | +- [File Structure](#file-structure) |
| 11 | +- [Supported Models](#supported-models) |
| 12 | +- [Troubleshooting](#troubleshooting) |
| 13 | + |
| 14 | +## Prerequisites |
| 15 | + |
| 16 | +- **Oracle Cloud Infrastructure Account** with Generative AI service access |
| 17 | +- **Python 3.8+** environment |
| 18 | +- **OCI CLI** configured with proper authentication |
| 19 | +- **Required Python packages**: Available in `requirements.txt` |
| 20 | +- **API Key authentication** set up for OCI services |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +1. **Clone the repository** |
| 25 | + ```bash |
| 26 | + git clone <repository-url> |
| 27 | + cd llm-performance-comparator |
| 28 | + ``` |
| 29 | + |
| 30 | +2. **Install dependencies** |
| 31 | + ```bash |
| 32 | + pip install -r requirements.txt |
| 33 | + ``` |
| 34 | + |
| 35 | +3. **Set up OCI authentication** |
| 36 | + - Configure your `~/.oci/config` file |
| 37 | + - Ensure API keys are properly set up |
| 38 | + - Verify compartment access permissions |
| 39 | + |
| 40 | +## Configuration |
| 41 | + |
| 42 | +### OCI Configuration (`backend/config.py`) |
| 43 | + |
| 44 | +Update the following variables with your OCI details: |
| 45 | + |
| 46 | +```python |
| 47 | +# Common Configuration |
| 48 | +COMPARTMENT_ID = "ocid1.compartment.oc1..your-compartment-id" |
| 49 | +AUTH_TYPE = "your_auth_type" |
| 50 | +CONFIG_PROFILE = "your_profile" |
| 51 | + |
| 52 | +# Regional Endpoint |
| 53 | +ENDPOINT = "your_endpoint_url" |
| 54 | + |
| 55 | +# Model OCIDs |
| 56 | +VANILLA_MODEL = "ocid1.your_model_id" # add here your base model ocid id |
| 57 | +FT_MODEL = "ocid1.your_model_id" # add here your Host DAC endpoint ocid id |
| 58 | +``` |
| 59 | + |
| 60 | +### Fine-tuned Model Configuration |
| 61 | + |
| 62 | +Users need to copy the fine-tuned model parameters from the OCI Console to configure available models in the application. |
| 63 | + |
| 64 | +#### Steps to Configure Fine-tuned Models: |
| 65 | + |
| 66 | +1. **Access OCI Console** |
| 67 | + - Navigate to "_Analytics & AI / Generative AI_" service |
| 68 | + - Go to "_Custom Models_" section |
| 69 | + - Select your fine-tuned model |
| 70 | + |
| 71 | +2. **Copy Model Parameters** |
| 72 | + - Note the training parameters used during fine-tuning |
| 73 | + - Record the base model and training method |
| 74 | + |
| 75 | +3. **Update Configuration** |
| 76 | + - Add the model configuration to `FINETUNED_MODELS` dictionary in `config.py` |
| 77 | + - Include all relevant training parameters from the console |
| 78 | + |
| 79 | +#### Example Configuration from OCI Console: |
| 80 | + |
| 81 | +**Finance Fine-tuning (LoRA)** |
| 82 | +```python |
| 83 | +"finance-fine-tuning": { |
| 84 | + "ft_model": FT_MODEL, # From OCI Console |
| 85 | + "training_method": "LoRA", # From Console Details |
| 86 | + "dataset": "gbharti/finance-alpaca", # From Console Details |
| 87 | + "training_epochs": 3, # From Console Parameters |
| 88 | + "batch_size": 32, # From Console Parameters |
| 89 | + "stopping_patience": 30, # From Console Parameters |
| 90 | + "stopping_threshold": 0.0001, # From Console Parameters |
| 91 | + "interval": 10, # From Console Parameters |
| 92 | + "lora_r": 32, # From Console Parameters |
| 93 | + "lora_alpha": 32, # From Console Parameters |
| 94 | + "lora_dropout": 0.1, # From Console Parameters |
| 95 | + "learning_rate": 0.0002 # From Console Parameters |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +**Domain Expert (T-Few)** |
| 100 | +```python |
| 101 | +"cohere.command-r-08-2024-domain-expert": { |
| 102 | + "ft_model": "ocid1.generativeaiendpoint.oc1.your-model-ocid", # From OCI Console |
| 103 | + "training_method": "T-Few", # From Console Details |
| 104 | + "dataset": "oracle-domain-expert-v2", # From Console Details |
| 105 | + "training_epochs": 1, # From Console Parameters |
| 106 | + "batch_size": 16, # From Console Parameters |
| 107 | + "stopping_patience": 10, # From Console Parameters |
| 108 | + "stopping_threshold": 0.001, # From Console Parameters |
| 109 | + "interval": 1, # From Console Parameters |
| 110 | + "learning_rate": 0.01 # From Console Parameters |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +- **Required Parameters from OCI Console**: |
| 115 | + - **Model OCID**: The fine-tuned endpoint identifier |
| 116 | + - **Training Method**: LoRA, T-Few, or other supported methods |
| 117 | + - **Dataset**: Training dataset name or identifier |
| 118 | + - **Hyperparameters**: All training parameters used during fine-tuning |
| 119 | + - **LoRA Parameters** (if applicable): rank (r), alpha, dropout values |
| 120 | + |
| 121 | +## Dataset Preparation |
| 122 | + |
| 123 | +The project includes a utility script for converting datasets to OCI Generative AI Service format. This is essential for preparing training data before fine-tuning models. |
| 124 | + |
| 125 | +### Dataset Format Conversion (`format_dataset\dataset_to_oci_format.py`) |
| 126 | + |
| 127 | +**Purpose**: Converts standard instruction-following datasets to OCI-compatible JSONL format. |
| 128 | + |
| 129 | +**Input Format** (e.g., `finance_data.json`): |
| 130 | +```json |
| 131 | +[ |
| 132 | + { |
| 133 | + "instruction": "What is compound interest?", |
| 134 | + "output": "Compound interest is the interest calculated on the initial principal..." |
| 135 | + } |
| 136 | +] |
| 137 | +``` |
| 138 | + |
| 139 | +**Output Format** (OCI-compatible JSONL): |
| 140 | +```json |
| 141 | +{"prompt": "What is compound interest?", "completion": "Compound interest is the interest calculated on the initial principal..."} |
| 142 | +{"prompt": "How do I calculate ROI?", "completion": "Return on Investment (ROI) is calculated by..."} |
| 143 | +``` |
| 144 | + |
| 145 | +### Using the Dataset Converter |
| 146 | + |
| 147 | +1. **Prepare your source dataset** |
| 148 | + - Place your dataset file in the `data/` directory |
| 149 | + - Ensure it follows the instruction-output format |
| 150 | + |
| 151 | +2. **Run the conversion script** |
| 152 | + ```bash |
| 153 | + python dataset_to_oci_format.py |
| 154 | + ``` |
| 155 | + |
| 156 | +3. **Upload to OCI** |
| 157 | + - Use the generated `output.jsonl` file for fine-tuning |
| 158 | + - Upload to OCI Object Storage |
| 159 | + - Reference in your fine-tuning job configuration |
| 160 | + |
| 161 | +#### Script Features |
| 162 | + |
| 163 | +- **Format Standardization**: Converts various dataset formats to OCI requirements |
| 164 | +- **Character Encoding**: Handles UTF-8 encoding and filters problematic characters |
| 165 | +- **Error Handling**: Skips entries with encoding issues to maintain dataset integrity |
| 166 | +- **Quote Normalization**: Removes problematic quote characters that may interfere with JSON parsing |
| 167 | + |
| 168 | + |
| 169 | +## Usage Instructions |
| 170 | + |
| 171 | +### Starting the Application |
| 172 | + |
| 173 | +```bash |
| 174 | +streamlit run app.py |
| 175 | +``` |
| 176 | + |
| 177 | +The application will be available at `http://localhost:8501` |
| 178 | + |
| 179 | +### Workflow |
| 180 | + |
| 181 | +1. **Model Selection** |
| 182 | + - Choose base model from sidebar dropdown |
| 183 | + - Select fine-tuned model variant |
| 184 | + - Review displayed fine-tuning parameters |
| 185 | + |
| 186 | +2. **Prompt Testing** |
| 187 | + - Enter test prompt in the main text area |
| 188 | + - Click "Generate Comparison" button |
| 189 | + - Wait for responses from both models |
| 190 | + |
| 191 | +3. **Results Analysis** |
| 192 | + - Compare response quality side-by-side |
| 193 | + - Review inference time metrics |
| 194 | + - Analyze performance improvements |
| 195 | + |
| 196 | +## Architecture |
| 197 | + |
| 198 | +### Application Structure |
| 199 | + |
| 200 | +``` |
| 201 | +app.py # Main Streamlit application |
| 202 | +├── backend/ |
| 203 | +│ ├── backend.py # Model interaction logic |
| 204 | +│ └── config.py # Configuration settings |
| 205 | +├── format_dataset/ |
| 206 | +│ └──dataset_to_oci_format.py # Dataset conversion utility |
| 207 | +└── static/ |
| 208 | + ├── oracle.png # Oracle logo |
| 209 | + └── styles.css # Custom CSS styling |
| 210 | +``` |
| 211 | + |
| 212 | +### Key Components |
| 213 | + |
| 214 | +- **Frontend**: Streamlit-based web interface with custom CSS styling |
| 215 | +- **Backend**: LangChain integration with OCI Generative AI |
| 216 | +- **Model Management**: Dynamic model initialization and response generation |
| 217 | + |
| 218 | +### Data Flow |
| 219 | + |
| 220 | +1. User selects models and enters prompt |
| 221 | +2. Application initializes both base and fine-tuned models |
| 222 | +3. Concurrent API calls to OCI Generative AI service |
| 223 | +4. Response processing and timing calculation |
| 224 | +5. Side-by-side display with performance metrics |
| 225 | + |
| 226 | + |
| 227 | +## Supported Models |
| 228 | + |
| 229 | +### Base Models |
| 230 | +- Foundational Large Language Models, e.g., **Meta Llama 3.3 70B Instruct** |
| 231 | + |
| 232 | +### Fine-tuning Methods |
| 233 | +- **LoRA (Low-Rank Adaptation)**: Parameter-efficient fine-tuning |
| 234 | +- **T-Few**: Task-specific few-shot learning |
| 235 | + |
| 236 | +## Troubleshooting |
| 237 | + |
| 238 | +### Common Issues |
| 239 | + |
| 240 | +#### Authentication Errors |
| 241 | +``` |
| 242 | +Error: Authentication failed |
| 243 | +``` |
| 244 | +**Solution**: Verify OCI config file and API key permissions |
| 245 | + |
| 246 | +#### Model Access Issues |
| 247 | +``` |
| 248 | +Error: Model not found or access denied |
| 249 | +``` |
| 250 | +**Solution**: Check compartment permissions and model OCIDs |
| 251 | + |
| 252 | +#### Endpoint Connection Issues |
| 253 | +``` |
| 254 | +Error: Connection timeout |
| 255 | +``` |
| 256 | +**Solution**: Verify regional endpoint URL and network connectivity |
| 257 | + |
| 258 | +#### Missing Dependencies |
| 259 | +``` |
| 260 | +ModuleNotFoundError: No module named 'langchain_community' |
| 261 | +``` |
| 262 | +**Solution**: Install required packages using pip |
| 263 | + |
| 264 | +## Security Considerations |
| 265 | + |
| 266 | +- **API Keys**: Store OCI credentials securely |
| 267 | +- **Network Security**: Use HTTPS endpoints only |
| 268 | +- **Access Control**: Implement proper OCI IAM policies |
0 commit comments