2024-04-25 07:42:17 -06:00
|
|
|
import { check } from 'k6';
|
|
|
|
import { scenario } from 'k6/execution';
|
2023-08-18 11:28:56 -06:00
|
|
|
import http from 'k6/http';
|
|
|
|
import { Trend, Counter } from 'k6/metrics';
|
|
|
|
|
2024-04-25 07:42:17 -06:00
|
|
|
const host = __ENV.HOST;
|
|
|
|
const model_id = __ENV.MODEL_ID;
|
2023-08-18 11:28:56 -06:00
|
|
|
const timePerToken = new Trend('time_per_token', true);
|
2023-12-11 04:46:30 -07:00
|
|
|
const tokens = new Counter('tokens');
|
|
|
|
const new_tokens = new Counter('new_tokens');
|
|
|
|
const input_tokens = new Counter('input_tokens');
|
2024-04-25 07:42:17 -06:00
|
|
|
const max_new_tokens = 50;
|
2023-08-18 11:28:56 -06:00
|
|
|
|
|
|
|
// const shareGPT = JSON.parse(open("ShareGPT_V3_unfiltered_cleaned_split.json"))
|
|
|
|
const shareGPT = JSON.parse(open("small.json"))
|
|
|
|
|
|
|
|
|
2024-04-25 07:42:17 -06:00
|
|
|
export function get_options() {
|
2023-08-18 11:28:56 -06:00
|
|
|
return {
|
|
|
|
thresholds: {
|
|
|
|
http_req_failed: ['rate==0'],
|
2024-04-25 07:42:17 -06:00
|
|
|
// time_per_token: [{
|
|
|
|
// threshold: `p(50)<${5 * reference_latency_ms}`,
|
|
|
|
// abortOnFail: true,
|
|
|
|
// delayAbortEval: '10s'
|
|
|
|
// }],
|
2023-08-18 11:28:56 -06:00
|
|
|
},
|
|
|
|
scenarios: {
|
2024-04-26 07:39:00 -06:00
|
|
|
// single_user: {
|
|
|
|
// executor: 'constant-arrival-rate',
|
|
|
|
// duration: '60s',
|
|
|
|
// preAllocatedVUs: 1,
|
|
|
|
// rate: 20,
|
|
|
|
// timeUnit: '1s',
|
|
|
|
// },
|
|
|
|
load_test: {
|
2023-08-18 11:28:56 -06:00
|
|
|
executor: 'constant-arrival-rate',
|
|
|
|
duration: '60s',
|
2024-04-26 07:39:00 -06:00
|
|
|
preAllocatedVUs: 100,
|
2024-04-25 07:42:17 -06:00
|
|
|
rate: 1,
|
2023-08-18 11:28:56 -06:00
|
|
|
timeUnit: '1s',
|
|
|
|
},
|
2024-04-25 07:42:17 -06:00
|
|
|
// breakpoint: {
|
|
|
|
// executor: 'ramping-arrival-rate', //Assure load increase if the system slows
|
2024-04-26 07:39:00 -06:00
|
|
|
// preAllocatedVUs: 300,
|
2024-04-25 07:42:17 -06:00
|
|
|
// stages: [
|
|
|
|
// { duration: '60s', target: 100 }, // just slowly ramp-up to a HUGE load
|
|
|
|
// ],
|
|
|
|
// },
|
|
|
|
// throughput: {
|
|
|
|
// executor: 'shared-iterations',
|
|
|
|
// vus: 100,
|
|
|
|
// iterations: 200,
|
|
|
|
// maxDuration: '40s',
|
|
|
|
// },
|
2023-08-18 11:28:56 -06:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-25 07:42:17 -06:00
|
|
|
function generate_payload(gpt, max_new_tokens) {
|
|
|
|
const input = gpt["conversations"][0]["value"];
|
|
|
|
return { "messages": [{ "role": "user", "content": input }], "temperature": 0, "model": `${model_id}`, "max_tokens": max_new_tokens }
|
|
|
|
}
|
|
|
|
|
|
|
|
export const options = get_options();
|
2023-08-18 11:28:56 -06:00
|
|
|
|
2024-04-25 07:42:17 -06:00
|
|
|
export default function run() {
|
|
|
|
const headers = { 'Content-Type': 'application/json' };
|
|
|
|
const query = shareGPT[scenario.iterationInTest % shareGPT.length];
|
|
|
|
const payload = JSON.stringify(generate_payload(query, max_new_tokens));
|
|
|
|
const res = http.post(`http://${host}/v1/chat/completions`, payload, {
|
2023-08-18 11:28:56 -06:00
|
|
|
headers,
|
|
|
|
});
|
2024-04-25 07:42:17 -06:00
|
|
|
if (res.status >= 400 && res.status < 500) {
|
2023-08-18 11:28:56 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-11 04:46:30 -07:00
|
|
|
|
2023-08-18 11:28:56 -06:00
|
|
|
check(res, {
|
2024-04-25 07:42:17 -06:00
|
|
|
'Post status is 200': (res) => res.status === 200,
|
2023-08-18 11:28:56 -06:00
|
|
|
});
|
2023-12-11 04:46:30 -07:00
|
|
|
const duration = res.timings.duration;
|
2023-08-18 11:28:56 -06:00
|
|
|
|
|
|
|
if (res.status === 200) {
|
2024-02-16 03:58:58 -07:00
|
|
|
const body = res.json();
|
2024-04-25 07:42:17 -06:00
|
|
|
const completion_tokens = body.usage.completion_tokens;
|
|
|
|
const latency_ms_per_token = duration / completion_tokens;
|
2023-08-18 11:28:56 -06:00
|
|
|
timePerToken.add(latency_ms_per_token);
|
2024-04-25 07:42:17 -06:00
|
|
|
const prompt_tokens = body.usage.prompt_tokens;
|
|
|
|
input_tokens.add(prompt_tokens);
|
|
|
|
new_tokens.add(completion_tokens);
|
|
|
|
tokens.add(completion_tokens + prompt_tokens);
|
2023-08-18 11:28:56 -06:00
|
|
|
}
|
|
|
|
}
|