-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Change behavior of pending event triggers #2436
Conversation
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2436-all-demos |
Very interesting, some questions I have:
|
I don't think we want both behaviours, and I don't really like the idea of adding more API surface area to solve this. I think we should just honour the latest request at any given moment (letting them all through), rather than rejecting subsequent request until we have a response.
Now it would also be nice if we could 'abort' those processes on the backend where possible too but depending on the stage they are at that might not be possible. If the queue is active we could remove them from the queue though. You can't really abort requests in the browser but we could signal to the server that it should ignore them if they are not already being processed. I think we'll need to assign ids or hashes to requests though because, especially for the queue otherwise we won't know what response we are dealing with. |
I think there are clear cases where we want each of these behaviors:
I definitely can see a user wanting to be able to use each of these three behaviors. |
I also think we avoid increasing the API. Instead of having our users think through these options, what about if we were to simply change the default behavior to "wait"? Wouldn't that solve all of the issues?
|
We could just batch requests per client.
It works for heavy models: you'll never run another while one is running. And if there's is a large queue of requests you still only run one. This assumes they are idempotent which they might not be due to state, they could be batched. For live text inputs, same story really, we discard the intermediate requests. I'm still not sure what the run usecase is really, since the output would be a single component they would just overwrite each other, with multiple threads are there even any guarantees of order? I guess if you were triggering a bunch of side effects or logging stuff the then you would be happy to just launch them whenever, some of these kinds of requests could probably be batched though. Would need to understand the concrete usecases for this. |
@pngwn by batching, are you referring to collecting a list of samples and passing them into the prediction function as a list (as in this PR that I've been working on)? This requires the function to accept batched inputs, so it wouldn't always work. But basically as long as:
we should be fine! |
Not really. I guess just discarding intermediate requests is fine but this won't work when we have state. If those intermediate requests make use of |
I actually feel that all three modes will have very valid use-cases as people build more complex interfaces, and I don't think that this is significantly expanding the API surface. It's also possible to disallow "run" mode if any of the inputs or outputs are state. |
@dawoodkhan82 this might close #1453 as well? |
I synced with @dawoodkhan82 on this a bit, and here's what we're thinking:
|
This is technically a breaking change. Would we consider this a bug fix instead? Have we tested to ensure this doesn't break any other existing use-cases or cause issues because of the change in behaviour? |
Good point @pngwn. Here's a demo that would "no longer work" as expected: import gradio as gr
import time
def slow_identity(x):
time.sleep(1)
return x
with gr.Blocks() as demo:
with gr.Row():
i1 = gr.Textbox()
o1 = gr.Textbox()
with gr.Row():
i2 = gr.Textbox()
o2 = gr.Textbox()
with gr.Row():
i3 = gr.Textbox()
o3 = gr.Textbox()
i1.change(slow_identity, i1, o1)
i2.change(slow_identity, i2, o2)
i3.change(slow_identity, i3, o3)
demo.launch() Currently, if you make changes really quickly to i1, i2, and i3 in sequence, they will all show up in o1, o2, o3. But with this PR, the changes in i2 will not show up I still think that having the "wait" behavior is overall better, but perhaps we should make this change in 4.0 to avoid any breaking changes we don't foresee. WDYT about kicking this PR and associated issues to 4.0 milestone? |
Closing for now. |
Description
Change default behavior of event triggers to "wait" for pending requests to complete. Fixes issues related textbox change events not registering latest change. ex: #1954
TODO: make this work for queue
Please include:
Closes: #1954
Checklist:
A note about the CHANGELOG
Hello 👋 and thank you for contributing to Gradio!
All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.
Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by
[@myusername](link-to-your-github-profile)
in[PR 11111](https://github.com/gradio-app/gradio/pull/11111)
".If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.