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

[llava] How to clear imagepaths ? #643

Open
dchatel opened this issue Apr 2, 2024 · 9 comments
Open

[llava] How to clear imagepaths ? #643

dchatel opened this issue Apr 2, 2024 · 9 comments

Comments

@dchatel
Copy link

dchatel commented Apr 2, 2024

How to clear the embedded images from the context ?
Apparently, calling executor.ImagePaths.Clear() has no effect on the private variable _embeds

@AsakusaRinne
Copy link
Collaborator

FYI @SignalRT

@SignalRT
Copy link
Collaborator

SignalRT commented Apr 3, 2024

@dchatel, In my knowledge there is no LlavaAPI to reset images from the context (I could be wrong).

Right now the option that I can think about is to create a new context / executor when the user prompts new images. Here you have the example modified:

https://github.com/SignalRT/LLamaSharp/blob/LlavaResetIContext/LLama.Examples/Examples/LlavaInteractiveModeExecute.cs

@AsakusaRinne , If this is OK to you I can make a PR with this change.

@AsakusaRinne
Copy link
Collaborator

@SignalRT According to the code, LLavaExecutor clear the image embeds when it has finished to generate the output. Is it possible to fix this issue based on this? (Please correct me if I'm wrong)

@SignalRT
Copy link
Collaborator

SignalRT commented Apr 3, 2024

I will review if there is a better way to manage this.

@SignalRT SignalRT self-assigned this Apr 4, 2024
@dchatel
Copy link
Author

dchatel commented Apr 6, 2024

I will review if there is a better way to manage this.

Maybe a good way would be to clear the image embeds when ImagePaths is cleared?...
Or reflect ImagePaths state into image embeds?

@SignalRT
Copy link
Collaborator

SignalRT commented Apr 6, 2024

ImagePath it's clearing right now automatically at the end of InferInternal:

                    _EmbedImagePosition = -1;
                    _imageEmbedHandles.Clear();
                    ImagePaths.Clear();

I'm trying some options searching for "continuity" adding or changing images during conversation.

I get something way better, but I need to solve some cases before to make a PR.

@IntptrMax
Copy link

Will llama_kv_cache_seq_rm can help? When embding image/prompt, we can get n_past, will it can be recorded as the positison. (I could be wrong).

`// Removes all tokens that belong to the specified sequence and have positions in [p0, p1)
// seq_id < 0 : match any sequence
// p0 < 0 : [0, p1]
// p1 < 0 : [p0, inf)

LLAMA_API bool llama_kv_cache_seq_rm(
struct llama_context * ctx,
llama_seq_id seq_id,
llama_pos p0,
llama_pos p1);`

@SignalRT
Copy link
Collaborator

SignalRT commented Apr 8, 2024

@IntptrMax, it’s what I’m working on, I also introduce the capability to add images in the middle of conversation that’s something that is not possible with master code. I expect to have the complete solution this week.

@SignalRT
Copy link
Collaborator

@dchatel , @IntptrMax In this PR #664 I introduce the idea to clear the images and to change the images during conversation.

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

No branches or pull requests

4 participants