Skip to content
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

Async implementation of LLamaExecutors #829

Closed
asmirnov82 opened this issue Jul 5, 2024 · 2 comments · Fixed by #834
Closed

Async implementation of LLamaExecutors #829

asmirnov82 opened this issue Jul 5, 2024 · 2 comments · Fixed by #834

Comments

@asmirnov82
Copy link
Contributor

Description

I am developing WPF application that uses LLamaSharp library and particulary LLama Executores (like InstructExecutor and InteractiveExecutor).
I expect that code

await foreach (var text in executor.InferAsync(prompt, _inferenceParams))
{
    currentResult.Content += text;
}

doesn't block my UI thread. However, UI freezes.

Looks, that this happens, because InferAsync awaits InferInternal(inferenceParams, args) method. And InferInternal implementations in InstructExecutor and InteractiveExecutor classes are synchronous.

As an experiment I changed the var (result, _) = Context.NativeHandle.Decode(_embeds, LLamaSeqId.Zero, batch, ref _pastTokensCount); line in InstructExecutor to var (result, _) = await Task.Run(() => Context.NativeHandle.Decode(_embeds, LLamaSeqId.Zero, batch, ref _pastTokensCount)); and this solved the issue.

Do you have any plans to add Async implementations for all methods that are awaited by StatefulExecutorBase in all inhereted executors?

@martindevans
Copy link
Member

There is a DecodeAsync method in the LlamaContext which should be a "drop in" replacement for Decode in an async context. Would you be interested in putting together a PR updating the three executors (Interact, Instruct and Stateless) to use this?

@asmirnov82
Copy link
Contributor Author

Yes, I'll do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants