-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sb_ai): Sessions are dropped while still in use (#443)
* fix(sb_ai): error handling on `run session` - removing `unwrap()` from `run session` * fix(sb_ai): cleanup logic, passing Session ref to js land - adding currently active session's refs to `OpState` * stamp: clippy * feat(k6): add scenario for `ort-rust-backend` - adding a scenario that uses `transformers.js` + `ort rust backend`
- Loading branch information
1 parent
390a5c1
commit e522925
Showing
5 changed files
with
111 additions
and
11 deletions.
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
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
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,19 @@ | ||
import { env, pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]'; | ||
|
||
// Ensure we do not use browser cache | ||
env.useBrowserCache = false; | ||
env.allowLocalModels = false; | ||
|
||
const pipe = await pipeline('feature-extraction', 'supabase/gte-small', { device: 'auto' }); | ||
|
||
Deno.serve(async (req) => { | ||
const payload = await req.json(); | ||
const text_for_embedding = payload.text_for_embedding; | ||
|
||
// Generate embedding | ||
const embedding = await pipe(text_for_embedding, { pooling: 'mean', normalize: true }); | ||
|
||
return Response.json({ | ||
length: embedding.ort_tensor.size, | ||
}); | ||
}); |
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
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,70 @@ | ||
/* | ||
./scripts/run.sh | ||
#!/usr/bin/env bash | ||
GIT_V_TAG=0.1.1 cargo build --features cli/tracing && \ | ||
EDGE_RUNTIME_WORKER_POOL_SIZE=8 \ | ||
EDGE_RUNTIME_PORT=9998 RUST_BACKTRACE=full ./target/debug/edge-runtime "$@" start \ | ||
--main-service ./examples/main \ | ||
--event-worker ./examples/event-manager | ||
*/ | ||
|
||
import http from "k6/http"; | ||
|
||
import { check, fail } from "k6"; | ||
import { Options } from "k6/options"; | ||
|
||
import { target } from "../config"; | ||
|
||
/** @ts-ignore */ | ||
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.2.0/index.js"; | ||
import { MSG_CANCELED } from "../constants"; | ||
|
||
export const options: Options = { | ||
scenarios: { | ||
simple: { | ||
executor: "constant-vus", | ||
vus: 12, | ||
duration: "3m", | ||
} | ||
} | ||
}; | ||
|
||
const GENERATORS = import("../generators"); | ||
|
||
export async function setup() { | ||
const pkg = await GENERATORS; | ||
return { | ||
words: pkg.makeText(1000) | ||
} | ||
} | ||
|
||
export default function ort_rust_backend(data: { words: string[] }) { | ||
const wordIdx = randomIntBetween(0, data.words.length - 1); | ||
|
||
console.debug(`WORD[${wordIdx}]: ${data.words[wordIdx]}`); | ||
const res = http.post( | ||
`${target}/k6-ort-rust-backend`, | ||
JSON.stringify({ | ||
"text_for_embedding": data.words[wordIdx] | ||
}) | ||
); | ||
|
||
const isOk = check(res, { | ||
"status is 200": r => r.status === 200 | ||
}); | ||
|
||
const isRequestCancelled = check(res, { | ||
"request cancelled": r => { | ||
const msg = r.json("msg"); | ||
return r.status === 500 && msg === MSG_CANCELED; | ||
} | ||
}); | ||
|
||
if (!isOk && !isRequestCancelled) { | ||
console.log(res.body); | ||
fail("unexpected response"); | ||
} | ||
} |