Skip to content

Commit 1e680ab

Browse files
kallebysantosnyannyachaEC2 Default User
authored
feat: onnx runtime upgrade (#478)
* chore(sb_ai): update `Cargo.toml` * chore(sb_ai): update `ONNXRUNTIME_VERSION` * stamp: solving `ort` api breaking changes - `ndarray_linalg`: Since `ort` deps to `ndarray=0.16`, decided to remove this extra dependency. Normalization can be done in a simple small funtion instead of deriving it from an external crate. * stamp: converting `from_ort_tensor` without clonning using the `rc-9` apis to get the same results from older `rc-2` * test(sb_ai): removing snapshots from onnx `v1.19.2` Since `ONNX`version has been upgraded, the snapshots need to be recreated * stamp: cleaning * test(sb_ai): adding `macos_aarch64` snapshots with onnx `v1.20` * feat: apply `normalize` without external deps - Since `ndarray_linalg` has been removed we need to manually apply L2 normalization * test(sb_ai): ensuring `mean_pool` and `normalize` - Applying `dot product` between two embeddings to ensures that `mean_pool` and `normalize` is working properly * chore: add aarch64 (linux) snapshots for integration tests * chore: add x86_64 (macos) snapshots for integration tests * chore: add x86_64 (linux) snapshots for integration tests * feat: add `Tensor<String>` support Co-authored-by: Nyannyacha <[email protected]> Co-authored-by: kallebysantos <[email protected]> * test(sb_ai): adding `Tensor<string>` integration test * fix(sb_ai): adding 'bool' alias to `JsTensorData` * fix(sb_ai): parsing input tensors correctly * test(sb_ai): updating `extract_tensor_ref` to match `JsTensorData` enum * fix(ai): reflecting module rename * stamp: enabling cache adapter on `ort-rust-backend` example * stamp: applying format * chore: update `Cargo.lock` --------- Co-authored-by: Nyannyacha <[email protected]> Co-authored-by: EC2 Default User <[email protected]>
1 parent 7dc3b49 commit 1e680ab

File tree

26 files changed

+298
-198
lines changed

26 files changed

+298
-198
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ONNXRUNTIME_VERSION=1.19.2
1+
ONNXRUNTIME_VERSION=1.20.1
22
DENO_VERSION=2.1.4
33
EDGE_RUNTIME_PORT=9998
4-
AI_INFERENCE_API_HOST=http://localhost:11434
4+
AI_INFERENCE_API_HOST=http://localhost:11434

Cargo.lock

Lines changed: 26 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { assertExists, assertInstanceOf } from "jsr:@std/assert";
2+
3+
// @ts-ignore: No types for 'onnxruntime' symbol
4+
const { Tensor, InferenceSession } = globalThis[Symbol.for("onnxruntime")];
5+
6+
const modelUrl =
7+
"https://huggingface.co/pirocheto/phishing-url-detection/resolve/main/model.onnx?download=true";
8+
9+
const encoder = new TextEncoder();
10+
const modelUrlBuffer = encoder.encode(modelUrl);
11+
const session = await InferenceSession.create(modelUrlBuffer);
12+
13+
Deno.serve(async (_req: Request) => {
14+
const urls = [
15+
"https://clubedemilhagem.com/home.php",
16+
"http://www.medicalnewstoday.com/articles/188939.php",
17+
"https://magalu-crediarioluiza.com/Produto_20203/produto.php?sku=1",
18+
];
19+
20+
const inputs = new Tensor("string", urls, [urls.length]);
21+
const output = await session.run({ inputs });
22+
23+
// just need to make sure that model output something
24+
// we don't care about the predicts values
25+
assertExists(output.label);
26+
assertExists(output.probabilities);
27+
28+
assertInstanceOf(output.label, Tensor);
29+
assertInstanceOf(output.probabilities, Tensor);
30+
31+
return new Response();
32+
});

crates/base/test_cases/ai-ort-rust-backend/transformers-js/feature-extraction-cache/__snapshot__/linux_aarch64.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

crates/base/test_cases/ai-ort-rust-backend/transformers-js/feature-extraction-cache/__snapshot__/macos_aarch64.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

crates/base/test_cases/ai-ort-rust-backend/transformers-js/feature-extraction/__snapshot__/linux_aarch64.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

crates/base/test_cases/ai-ort-rust-backend/transformers-js/feature-extraction/__snapshot__/macos_aarch64.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)