-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
SequentialChain runs the same callbacks over and over in async mode #9401
Comments
🤖 Thank you for bringing this to our attention. You're correct in your observation that the The issue lies in the placement of the line To fix this issue, you should move the line for i, chain in enumerate(self.chains):
callbacks = _run_manager.get_child()
outputs = await chain.acall(
known_values, return_only_outputs=True, callbacks=callbacks
)
known_values.update(outputs) This will ensure that a new callbacks object is created for each chain, avoiding the cascading run of callbacks at each step. I will create a pull request with this fix and link it to this issue for tracking. Once the pull request is merged, this fix will be included in the next release of LangChain. Thank you for your contribution to improving LangChain. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Here is a new unit test for this issue.
|
… async mode (#9452) Issue: #9401 In the Async mode, SequentialChain implementation seems to run the same callbacks over and over since it is re-using the same callbacks object. Langchain version: 0.0.264, master The implementation of this aysnc route differs from the sync route and sync approach follows the right pattern of generating a new callbacks object instead of re-using the old one and thus avoiding the cascading run of callbacks at each step. Async mode: ``` _run_manager = run_manager or AsyncCallbackManagerForChainRun.get_noop_manager() callbacks = _run_manager.get_child() ... for i, chain in enumerate(self.chains): _input = await chain.arun(_input, callbacks=callbacks) ... ``` Regular mode: ``` _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager() for i, chain in enumerate(self.chains): _input = chain.run(_input, callbacks=_run_manager.get_child(f"step_{i+1}")) ... ``` Notice how we are reusing the callbacks object in the Async code which will have a cascading effect as we run through the chain. It runs the same callbacks over and over resulting in issues. Solution: Define the async function in the same pattern as the regular one and added tests. --------- Co-authored-by: vamsee_yarlagadda <vamsee.y@airbnb.com>
System Info
In the Async mode, SequentialChain implementation seems to run the same callbacks over and over since it is re-using the same callbacks object.
Langchain version: 0.0.264
The implementation of this aysnc route differs from the sync route and sync approach follows the right pattern of generating a new callbacks object instead of re-using the old one and thus avoiding the cascading run of callbacks at each step.
Async code
Sync code
Notice how we are reusing the
callbacks
object in the Async code which will have a cascading effect as we run through the chain. It runs the same callbacks over and over resulting in issues.CC @agola11
Who can help?
@agola11
Information
Related Components
Reproduction
You can write a simple sequential chain with 3 tasks with callbacks and run the code in async and notice that the callbacks run over and over as we can see in the log.
Expected behavior
We should ideally see the callbacks get run once per task.
The text was updated successfully, but these errors were encountered: