Skip to content

Commit

Permalink
Put invalid vector for broken images
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Feb 26, 2024
1 parent 2b2c05e commit 7c51f96
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-cli-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
type: string
description: "CLI version"
required: true
default: "0.1.0"
default: "0.1.1"
IMAGE_NAME:
type: string
description: "Container image name to tag"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.cli.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apt update && \
apt install -y --no-install-recommends wget build-essential pkg-config clang curl libssl-dev && \
cargo build --release --package lantern_cli

FROM nvcr.io/nvidia/cuda:11.8.0-runtime-ubuntu22.04
FROM nvcr.io/nvidia/cuda:12.3.1-runtime-ubuntu22.04
COPY --from=build /app/target/release/lantern-cli .
RUN apt update && \
apt install -y wget && apt clean
Expand Down
2 changes: 1 addition & 1 deletion lantern_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lantern_cli"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

[[bin]]
Expand Down
43 changes: 36 additions & 7 deletions lantern_cli/src/embeddings/core/ort_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,18 @@ impl<'a> EmbeddingRuntime for OrtRuntime<'a> {
.filter(|b| b.len() > 0)
.collect::<Vec<&Vec<u8>>>();

let model_result = model_info
.encoder
.as_ref()
.unwrap()
.process_image(&filtered_buffers);
let model_result = if filtered_buffers.len() > 0 {
model_info
.encoder
.as_ref()
.unwrap()
.process_image(&filtered_buffers)
} else {
Ok(EmbeddingResult {
embeddings: Vec::new(),
processed_tokens: 0,
})
};

let model_result: EmbeddingResult = match model_result {
Ok(res) => res,
Expand All @@ -811,13 +818,35 @@ impl<'a> EmbeddingRuntime for OrtRuntime<'a> {
};

// Now we are mapping back the results, and for failed images
// We will put an empty vector, which will later become null in DB
// We will put an a vector filled with -1
// We are not putting an empty vector here
// Because on each daemon start it would take null values
// And try to generate embeddings for them, so startup will slow down
let mut idx = 0;
// We are unwrapping here, as models are static
// And we believe the model file to have the outputs
// And output shuold have the dimensions
// This should be checked when adding new model

let output_dims = model_info
.encoder
.as_ref()
.unwrap()
.encoder
.outputs
.last()
.unwrap()
.dimensions()
.last()
.unwrap()
.unwrap();

let invalid_vec = vec![-1.0; output_dims];
let return_res = buffers
.iter()
.map(|el| {
if el.len() == 0 {
Vec::new()
invalid_vec.clone()
} else {
let vec = model_result.embeddings[idx].clone();
idx += 1;
Expand Down

0 comments on commit 7c51f96

Please sign in to comment.