Skip to content

Commit 91c0c19

Browse files
llm-comparator
Baseline code
1 parent 16bf9f1 commit 91c0c19

File tree

11 files changed

+914
-0
lines changed

11 files changed

+914
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# LLM Performance Comparator
2+
3+
A web application that enables side-by-side comparison of Large Language Models (LLMs) and their fine-tuned counterparts on Oracle Cloud Infrastructure (OCI). The application provides an intuitive interface to evaluate model performance, response quality, and inference time improvements achieved through fine-tuning.
4+
5+
Reviewed: 23.07.2025
6+
7+
# When to use this asset?
8+
9+
**Data Scientists, ML Engineers or Developers** would use this asset when evaluating the effectiveness of fine-tuned models against their base counterparts, demonstrating fine-tuning improvements to stakeholders, making data-driven decisions about model deployment and selection, benchmarking different fine-tuning configurations, and validating fine-tuning results before production deployment.
10+
11+
**AI/ML Team Leaders** would use this asset when presenting ROI of fine-tuning investments to management, comparing multiple fine-tuning approaches (LoRA or T-Few) and establishing best practices for model evaluation workflows.
12+
13+
# How to use this asset?
14+
15+
Configure your Oracle Cloud Infrastructure credentials and endpoints in the config file, install the required dependencies and run the application. Select your base model and fine-tuned variant from the dropdown menus, enter your test prompt, and generate side-by-side comparisons. The application displays response quality, inference times, and detailed fine-tuning parameters to help you make informed decisions about model deployment.
16+
17+
# Useful Links
18+
19+
- [Gen AI DAC: Performance](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/performance.htm)
20+
- [Gen AI Data handlining](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/data-handling.htm)
21+
- [Hyperparameter details](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/fine-tuning-parameters.htm)
22+
- [Model performance details](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/concepts-metrics.htm)
23+
- [Available fine tunning methods](https://docs.public.content.oci.oraclecloud.com/en-us/iaas/Content/generative-ai/choose-method.htm)
24+
25+
# License
26+
27+
Copyright (c) 2025 Oracle and/or its affiliates.
28+
29+
Licensed under the Universal Permissive License (UPL), Version 1.0.
30+
31+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[client]
2+
toolbarMode = "minimal"
3+
4+
[server]
5+
headless = true
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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

Comments
 (0)