Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: Bump ort to v2.0.0-rc.9
Signed-off-by: Anush008 <anushshetty90@gmail.com>
  • Loading branch information
Anush008 committed Nov 22, 2024
commit 7cdbc19d640b356b9499958a5bca62a5ad02f651
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [
"Luya Wang <luya.wang@qq.com>",
"Tri <tri@triandco.com>",
"Denny Wong <denwong47@hotmail.com>",
"Alex Rozgo <alex.rozgo@gmail.com>"
"Alex Rozgo <alex.rozgo@gmail.com>",
]
documentation = "https://docs.rs/fastembed"
repository = "https://github.com/Anush008/fastembed-rs"
Expand All @@ -26,8 +26,9 @@ anyhow = { version = "1" }
hf-hub = { version = "0.3", default-features = false }
image = "0.25.2"
ndarray = { version = "0.16", default-features = false }
ort = { version = "=2.0.0-rc.8", default-features = false, features = [
"half", "ndarray",
ort = { version = "=2.0.0-rc.9", default-features = false, features = [
"half",
"ndarray",
] }
rayon = { version = "1.10", default-features = false }
serde_json = { version = "1" }
Expand Down
7 changes: 6 additions & 1 deletion src/image_embedding/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use hf_hub::{
Cache,
};
use ndarray::{Array3, ArrayView3};
use ort::{GraphOptimizationLevel, Session, Value};
use ort::{
session::{builder::GraphOptimizationLevel, Session},
value::Value,
};
#[cfg(feature = "online")]
use std::path::PathBuf;
use std::{path::Path, thread::available_parallelism};
Expand Down Expand Up @@ -32,6 +35,8 @@ impl ImageEmbedding {
/// Uses the total number of CPUs available as the number of intra-threads
#[cfg(feature = "online")]
pub fn try_new(options: ImageInitOptions) -> anyhow::Result<Self> {
use ort::session::{builder::GraphOptimizationLevel, Session};

let ImageInitOptions {
model_name,
execution_providers,
Expand Down
2 changes: 1 addition & 1 deletion src/image_embedding/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use ort::{ExecutionProviderDispatch, Session};
use ort::{execution_providers::ExecutionProviderDispatch, session::Session};

use crate::{ImageEmbeddingModel, DEFAULT_CACHE_DIR};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod reranking;
mod sparse_text_embedding;
mod text_embedding;

pub use ort::ExecutionProviderDispatch;
pub use ort::execution_providers::ExecutionProviderDispatch;

pub use crate::common::{
read_file_to_bytes, Embedding, Error, SparseEmbedding, TokenizerFiles, DEFAULT_CACHE_DIR,
Expand Down
16 changes: 6 additions & 10 deletions src/output/embedding_output.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ndarray::{Array2, ArrayView, Dim, IxDynImpl};
use ort::session::SessionOutputs;

use crate::pooling;

Expand All @@ -10,7 +11,7 @@ use super::{OutputKey, OutputPrecedence};
/// pooling etc. This struct should contain all the necessary information for the
/// post-processing to be performed.
pub struct SingleBatchOutput<'r, 's> {
pub session_outputs: ort::SessionOutputs<'r, 's>,
pub session_outputs: SessionOutputs<'r, 's>,
pub attention_mask_array: Array2<i64>,
}

Expand All @@ -23,17 +24,12 @@ impl<'r, 's> SingleBatchOutput<'r, 's> {
&self,
precedence: &impl OutputPrecedence,
) -> anyhow::Result<ArrayView<f32, Dim<IxDynImpl>>> {
let ort_output = precedence
let ort_output: &ort::value::Value = precedence
.key_precedence()
.find_map(|key| match key {
OutputKey::OnlyOne => {
// Only export the value if there is only one output available.
if self.session_outputs.len() == 1 {
self.session_outputs.values().next()
} else {
None
}
}
OutputKey::OnlyOne => self
.session_outputs
.get(self.session_outputs.keys().nth(0)?),
OutputKey::ByOrder(idx) => {
let x = self
.session_outputs
Expand Down
7 changes: 6 additions & 1 deletion src/reranking/impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use anyhow::Result;
use ort::{
session::{builder::GraphOptimizationLevel, Session},
value::Value,
};
use std::thread::available_parallelism;

#[cfg(feature = "online")]
Expand All @@ -10,7 +14,6 @@ use crate::{
#[cfg(feature = "online")]
use hf_hub::{api::sync::ApiBuilder, Cache};
use ndarray::{s, Array};
use ort::{GraphOptimizationLevel, Session, Value};
use rayon::{iter::ParallelIterator, slice::ParallelSlice};
use tokenizers::Tokenizer;

Expand Down Expand Up @@ -47,6 +50,8 @@ impl TextRerank {

#[cfg(feature = "online")]
pub fn try_new(options: RerankInitOptions) -> Result<TextRerank> {
use ort::session::{builder::GraphOptimizationLevel, Session};

use super::RerankInitOptions;

let RerankInitOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/reranking/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use ort::{ExecutionProviderDispatch, Session};
use ort::{execution_providers::ExecutionProviderDispatch, session::Session};
use tokenizers::Tokenizer;

use crate::{RerankerModel, TokenizerFiles, DEFAULT_CACHE_DIR};
Expand Down
5 changes: 3 additions & 2 deletions src/sparse_text_embedding/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use hf_hub::{
Cache,
};
use ndarray::{Array, CowArray};
use ort::{session::Session, value::Value};
#[cfg_attr(not(feature = "online"), allow(unused_imports))]
use ort::GraphOptimizationLevel;
use ort::{Session, Value};
use rayon::{iter::ParallelIterator, slice::ParallelSlice};
#[cfg(feature = "online")]
use std::path::PathBuf;
Expand All @@ -34,6 +33,8 @@ impl SparseTextEmbedding {
/// Uses the total number of CPUs available as the number of intra-threads
#[cfg(feature = "online")]
pub fn try_new(options: SparseInitOptions) -> Result<Self> {
use ort::session::{builder::GraphOptimizationLevel, Session};

use super::SparseInitOptions;

let SparseInitOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/sparse_text_embedding/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use ort::{ExecutionProviderDispatch, Session};
use ort::{execution_providers::ExecutionProviderDispatch, session::Session};
use tokenizers::Tokenizer;

use crate::{models::sparse::SparseModel, TokenizerFiles, DEFAULT_CACHE_DIR};
Expand Down
7 changes: 6 additions & 1 deletion src/text_embedding/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use hf_hub::{
Cache,
};
use ndarray::Array;
use ort::{GraphOptimizationLevel, Session, Value};
use ort::{
session::{builder::GraphOptimizationLevel, Session},
value::Value,
};
use rayon::{
iter::{FromParallelIterator, ParallelIterator},
slice::ParallelSlice,
Expand All @@ -38,6 +41,8 @@ impl TextEmbedding {
/// Uses the total number of CPUs available as the number of intra-threads
#[cfg(feature = "online")]
pub fn try_new(options: InitOptions) -> anyhow::Result<Self> {
use ort::session::{builder::GraphOptimizationLevel, Session};

let InitOptions {
model_name,
execution_providers,
Expand Down
2 changes: 1 addition & 1 deletion src/text_embedding/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
pooling::Pooling,
EmbeddingModel, QuantizationMode,
};
use ort::{ExecutionProviderDispatch, Session};
use ort::{execution_providers::ExecutionProviderDispatch, session::Session};
use std::path::{Path, PathBuf};
use tokenizers::Tokenizer;

Expand Down