-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create mutable state for Axum server #73
Comments
I believe what you have here is a self-referencing struct. The compiler is currently unable to figure out that |
I see... I haven't been successful yet using 'ouroboros'. But I'll report back when I have something useful |
So this works: #[self_referencing(pub_extras)]
#[allow(unused_imports)]
pub struct AppState {
pub whisper_ctx: WhisperContext,
#[borrows(whisper_ctx)]
#[covariant]
pub whisper_state: WhisperState<'this>
} Constructing a new instance with: let model_path = "models/ggml-medium.bin";
let whisper_context = whisper_rs::WhisperContext::new(&model_path)
.expect("Failed to load model");
let app_state = Arc::new(Mutex::new(
AppStateAsyncSendBuilder {
whisper_ctx: whisper_context,
whisper_state_builder: |whisper_ctx| {
Box::pin(async move {
whisper_ctx.create_state().unwrap()
})
}
}.build().await
)); And the endpoint: async fn transcribe(
state: State<Arc<Mutex<AppState>>>,
audio: Bytes
) -> String {
debug!("Transcribing audio file of size {}", audio.len());
let decoded_audio = utils::decode(audio.to_vec()).expect("Failed to decode audio");
// create a params object
let params = FullParams::new(
SamplingStrategy::BeamSearch { beam_size: 12, patience: 0.1}
);
// Get a mutable reference to the whisper state
let mut lock = state.lock().await;
lock.with_whisper_state_mut(
|whisper_state| {
forward_pass(&decoded_audio, params, whisper_state)
}
)
} I am unfortunately getting very poor performance compared to whisper.cpp, even though I'm running on an M2 Max Macbook pro with a CoreML model. Is this a known issue? |
Might as well check the obvious first: do you have the |
Fair enough, but yes I am running with |
How is the poor performance manifesting? Since I know we had #67 that was loading and caching the model every time. |
I'll attempt to create a proper comparison between this and whisper.cpp tomorrow. |
Closed since my problem has been solved, created new issue (#74) for performance penalty |
I'm trying to create a
whisper-rs
server using Axum. In this server I'd like to only have to create the whisper state once at server startup. Hence, I created anAppState
struct that could then be passed around using anArc<Mutex<AppState>>
.However, I seem to be having issues with ownership (classic) when implementing
::new
for this struct, and I have the idea that it may have to do with the underlying implementation ofWhisperContext
andWhisperState
, since they using raw pointers underneath, and a lifetime specifier for aPhantomData<&'a WhisperContext>
as a field forWhisperState
.My implementation is as follows:
This yields the following compilation error:
Perhaps this has got to do with my understanding of Rust, in which case please tell me so. So far I've tried most things that conventional googling and/or ChatGPT would suggest such as wrapping the struct's field types in
Arc
, but to no avail.Otherwise I'm curious to hear your thoughts, any help is greatly appreciated. I've unfortunately been stuck for some time.
The text was updated successfully, but these errors were encountered: