-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add llm-rag demo workload #62
Open
kusumachalasani
wants to merge
19
commits into
kruize:master
Choose a base branch
from
kusumachalasani:llm-rag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
837a9cb
Add llm-rag demo benchmark
kusumachalasani 158b128
llm-rag demo
kusumachalasani 49f0fcb
llm-rag demo
kusumachalasani 0585c3f
Add llm-rag demo benchmark
kusumachalasani 2a71606
Update ReadMe
kusumachalasani 5091c0d
Update load
kusumachalasani 380bc0c
Update load script
kusumachalasani a6c0c25
Update ReadMe
kusumachalasani 0a6c73f
update load script
kusumachalasani 960809f
Update deploy script
kusumachalasani b15ce0f
Update load files
kusumachalasani cf56ebc
Update ReadMe
kusumachalasani 7e5ef3c
Add cleanup
kusumachalasani b089500
update cleanup
kusumachalasani 2d17890
update cleanup
kusumachalasani 4470785
add namespace changes
kusumachalasani 2514a09
update ReadMe
kusumachalasani f264839
Update load script
kusumachalasani 457fa46
Include cleanup
kusumachalasani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
## LLM+RAG Workload | ||
|
||
### Deploy the LLM+RAG Demo | ||
|
||
To deploy the demo, run the following command: | ||
|
||
```sh | ||
./deploy.sh | ||
``` | ||
|
||
This script performs the following actions: | ||
- Clone the repo `https://github.com/kusumachalasani/llm-rag-deployment.git`. | ||
- Uses namespace `ic-shared-rag-llm` for the demo. | ||
- Includes a custom GenAI image. | ||
- Deploys the Postgres database. | ||
- Deploys the LLM which uses model MaziyarPanahi/Mistral-7B-Instruct-v0.2 | ||
- Deploys the Gradio service for Q&A. | ||
- Ingests several sources of data into the database for RAG (Retrieval-Augmented Generation). | ||
|
||
### Running the Load | ||
|
||
``` | ||
docker run -d --rm --network=host quay.io/kruizehub/llmragdemo-load-puppeteer:v1 node load.js --url <GRADIO_Service> [--duration <Duration load runs in ms>:default null] [--delay <Delay between questions in ms>:default 10] [--browsers <Number of browsers running the load in parallel>:default 1] | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Clone the repo | ||
git clone https://github.com/kusumachalasani/llm-rag-deployment.git | ||
|
||
cd llm-rag-deployment/bootstrap-rag | ||
|
||
# Pre-requisites | ||
# Create the Imagestream that supports the demo | ||
oc apply -f rhoai-rag-configuration/workbench-imagestream.yaml | ||
|
||
# Install ODF and ceph-rbd-storage class. <TODO> | ||
# This is required for llm PVC to support multiprocessing | ||
# Has issues creating the storage system in AWS. | ||
# Workaround to use gp3 which is default Storage system | ||
|
||
# Deploy the postres | ||
|
||
oc apply -f pgvector-rag-deployment/01-db-secret.yaml | ||
oc apply -f pgvector-rag-deployment/02-pvc.yaml | ||
oc apply -f pgvector-rag-deployment/03-deployment.yaml | ||
oc apply -f pgvector-rag-deployment/04-services.yaml | ||
oc apply -f pgvector-rag-deployment/05-grant-access-too-db.yaml | ||
|
||
# Deploy the llm | ||
oc apply -f shared-rag-llm/namespace.yaml | ||
|
||
oc apply -f shared-rag-llm/pvc.yaml | ||
oc apply -f shared-rag-llm/deployment.yaml | ||
oc apply -f shared-rag-llm/service.yaml | ||
oc apply -f shared-rag-llm/route.yaml | ||
|
||
|
||
# Deploy gradio | ||
oc apply -f gradio-rag/deployment.yaml | ||
oc apply -f gradio-rag/service.yaml | ||
oc apply -f gradio-rag/route.yaml | ||
|
||
# Access gradio service | ||
GRADIO_ROUTE=$(oc get route -n ic-shared-rag-llm --template='{{range .items}}{{.spec.host}}{{"\n"}}{{end}}') | ||
echo "Access gradio service as ${GRADIO_ROUTE}" | ||
|
||
|
||
# Extend pgvector and ingest data to DB | ||
oc apply -f pgvector-rag-deployment/06-extend-pg-db.yaml | ||
oc apply -f pgvector-rag-deployment/07-ingest-data.yaml | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Use an official Node.js runtime as a parent image | ||
FROM node:18 | ||
|
||
# Set the working directory in the container | ||
WORKDIR /usr/src/app | ||
|
||
# Copy the package.json and package-lock.json files | ||
COPY package*.json ./ | ||
|
||
# Install any needed packages | ||
RUN npm install | ||
RUN npx puppeteer browsers install chrome | ||
|
||
# Install dependencies required by Puppeteer | ||
RUN apt-get update && apt-get install -y \ | ||
wget \ | ||
gnupg \ | ||
ca-certificates \ | ||
--no-install-recommends | ||
|
||
# Install Chromium | ||
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \ | ||
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \ | ||
&& apt-get update \ | ||
&& apt-get install -y google-chrome-stable \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Command to run the script | ||
CMD ["node", "load.js", "--url", "http://example.com", "--browsers", "1", "--duration", "60000", "--delay", "100"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
const puppeteer = require('puppeteer'); | ||
const fs = require('fs'); | ||
const minimist = require('minimist'); | ||
|
||
function readQuestionsFromFile(filePath) { | ||
const rawData = fs.readFileSync(filePath); | ||
return JSON.parse(rawData); | ||
} | ||
|
||
async function askQuestions(page, questions, endTime, delay) { | ||
let questionsAnswered = 0; | ||
for (const question of questions) { | ||
if(endTime != null) { | ||
if (Date.now() >= endTime) break; | ||
} | ||
console.log(question); | ||
await page.focus('[data-testid="textbox"]'); | ||
await page.evaluate(() => { | ||
document.querySelector('[data-testid="textbox"]').value = ''; | ||
}); | ||
|
||
await page.type('[data-testid="textbox"]', question.question); | ||
|
||
await page.keyboard.press('Enter'); | ||
|
||
console.log("Entered the question and waiting for the response indicator.."); | ||
|
||
// Wait for the bot's response to appear | ||
const initialResponses = await page.$$('button[data-testid="bot"]'); | ||
const initialResponseCount = initialResponses.length; | ||
//console.log(initialResponseCount) | ||
await page.waitForFunction( | ||
initialCount => { | ||
const responses = document.querySelectorAll('button[data-testid="bot"]'); | ||
//console.log(`Current response count: ${responses.length}, Initial response: ${responses}`); | ||
return responses.length > initialCount; | ||
}, | ||
{}, | ||
initialResponseCount, | ||
{ timeout: 100 } | ||
); | ||
console.log("Waiting for response....") | ||
const latestResponseIndex = initialResponseCount + 1; | ||
let stable = false; | ||
let lastResponse = ''; | ||
const stabilityCheckDelay = 5; | ||
const stabilityCheckDuration = 1000; | ||
let stabilityCheckCounter = 0; | ||
// Monitor changes in the bot's latest response area until the content stabilizes | ||
while (!stable) { | ||
let currentResponse; | ||
const botButtons = await page.$$('button[data-testid="bot"]'); | ||
//const buttonCount = botButtons.length; | ||
//console.log(`Number of bot buttons found: ${buttonCount}`); | ||
|
||
let retries = 0; | ||
const maxRetries = 5; // Adjust based on your needs | ||
while (retries < maxRetries) { | ||
try { | ||
currentResponse = await botButtons[latestResponseIndex - 1].evaluate(el => el.innerText); | ||
//console.log(currentResponse); | ||
break; | ||
} catch (error) { | ||
console.error(`Failed to find element: button[data-testid="bot"]:nth-of-type(${latestResponseIndex})`, error); | ||
retries++; | ||
await new Promise(resolve => setTimeout(resolve, delay1)); | ||
} | ||
} | ||
if (retries === maxRetries) { | ||
console.error('Failed to find the current response after multiple attempts.'); | ||
break; | ||
} | ||
if (currentResponse.includes('Loading content')) { | ||
//console.log("Response is still loading..."); | ||
stabilityCheckCounter = 0; | ||
} else if (currentResponse === lastResponse) { | ||
stabilityCheckCounter += stabilityCheckDelay; | ||
if (stabilityCheckCounter >= stabilityCheckDuration) { | ||
stable = true; | ||
} | ||
} else { | ||
lastResponse = currentResponse; | ||
stabilityCheckCounter = 0; | ||
} | ||
await new Promise(resolve => setTimeout(resolve, stabilityCheckDelay)); | ||
|
||
} | ||
questionsAnswered++; | ||
await delayFunc(delay); | ||
} | ||
return questionsAnswered; | ||
|
||
|
||
} | ||
|
||
// Function to run a browser instance | ||
async function runBrowser(url, questions, duration, delay, headless) { | ||
const headlessBool = (headless === 'true'); | ||
const browser = await puppeteer.launch({ | ||
headless: headlessBool, | ||
args: ['--no-sandbox', '--disable-setuid-sandbox','--disable-features=BlockInsecurePrivateNetworkRequests'] }); | ||
const page = await browser.newPage(); | ||
await page.setCacheEnabled(false); | ||
if (url.startsWith('http://')) { | ||
await page.setRequestInterception(true); | ||
} | ||
page.on('request', request => { | ||
const requestUrl = request.url(); | ||
if (url.startsWith('http://')) { | ||
if (requestUrl.includes('https')) { | ||
request.abort(); | ||
} else { | ||
request.continue(); | ||
} | ||
} | ||
}); | ||
|
||
await page.goto(url, { waitUntil: 'networkidle2', timeout: 60000 }); | ||
await page.waitForSelector('[data-testid="textbox"]', { timeout: 120000 }); | ||
console.log("Page has come up!"); | ||
let questionsBrowserAnswered = 0; | ||
const endTime = Date.now() + duration; | ||
const startQATime = performance.now(); | ||
if (duration) { | ||
console.log("Duration to run the load is set. Loops over the questions until the duration specified!"); | ||
while(Date.now() < endTime) { | ||
const questionsBrowserAnsweredtemp = await askQuestions(page, questions, endTime, delay); | ||
questionsBrowserAnswered += questionsBrowserAnsweredtemp; | ||
} | ||
} else { | ||
console.log("No duration is set"); | ||
if (loop) { | ||
console.log(`Runs all the 8 questions ${loop} times`); | ||
for (let round = 0; round < loop; round++) { | ||
const questionsBrowserAnsweredtemp = await askQuestions(page, questions, null, delay); | ||
questionsBrowserAnswered += questionsBrowserAnsweredtemp; | ||
} | ||
} | ||
} | ||
const endQATime = performance.now(); | ||
const QATime = (endQATime - startQATime) / 1000; | ||
//console.log(`Time taken to get answers for ${questionsBrowserAnswered} questions : ${(endQATime - startQATime) / 1000} seconds`); | ||
return { questionsBrowserAnswered, QATime }; | ||
await browser.close(); | ||
} | ||
|
||
function delayFunc(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function main(url, numberOfBrowsers, duration, delay, headless) { | ||
const startSetTime = performance.now(); | ||
const questions = readQuestionsFromFile('./questions.json'); | ||
|
||
const browserPromises = []; | ||
|
||
for (let i = 0; i < numberOfBrowsers; i++) { | ||
browserPromises.push(runBrowser(url, questions, duration, delay, headless)); | ||
await delayFunc(5000); | ||
} | ||
|
||
const results = await Promise.all(browserPromises); | ||
results.forEach((result, index) => { | ||
const { questionsBrowserAnswered, QATime } = result; | ||
console.log(`Browser ${index + 1} answered ${questionsBrowserAnswered} questions in ${QATime} seconds.`); | ||
}); | ||
|
||
await Promise.all(browserPromises); | ||
const endSetTime = performance.now(); | ||
console.log(`Time taken to complete the load run: ${(endSetTime - startSetTime) / 1000} seconds`); | ||
} | ||
|
||
// Parse command-line arguments | ||
// Parameters: URL, number of browsers, duration in milliseconds, delay between questions in milliseconds, headless mode (true/false) | ||
const args = minimist(process.argv.slice(2)); | ||
|
||
const url = args.url; | ||
const numberOfBrowsers = parseInt(args.browsers) || 1; | ||
const duration = parseInt(args.duration) || null; | ||
const loop = parseInt(args.loop) || 1; | ||
const delay = parseInt(args.delay) || 100; | ||
const headless = args.headless || 'true'; | ||
|
||
if (!url) { | ||
console.error('Error: URL parameter is required'); | ||
process.exit(1); | ||
} | ||
|
||
main(url, numberOfBrowsers, duration, delay, headless) | ||
.then(() => console.log('All browsers completed')) | ||
.catch(error => console.error('Error:', error)); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These throw an error as the namespace doesn't exist, might be we need to move it after namespace creation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a script for cleaning up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.