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

Update parallelism example #431

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion burr/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ApplicationContext,
ApplicationGraph,
)
from burr.core.graph import Graph
from burr.core.graph import Graph, GraphBuilder
from burr.core.state import State

__all__ = [
Expand All @@ -22,4 +22,5 @@
"State",
"when",
"Graph",
"GraphBuilder",
]
22 changes: 14 additions & 8 deletions burr/core/parallelism.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def actions(self, state: State) -> Generator[Action | Callable | RunnableGraph,
query_llm.bind(model="gpt-4").with_name("gpt_4_answer"),
query_llm.bind(model="o1").with_name("o1_answer"),
query_llm.bind(model="claude").with_name("claude_answer"),
]
]:
yield action

def states(self, state: State) -> Generator[State, None, None]:
Expand All @@ -335,10 +335,12 @@ def reduce(self, states: Generator[State, None, None]) -> State:
)
return state.update(all_llm_outputs=all_llm_outputs)

def reads() -> List[str]:
@property
def reads(self) -> list[str]:
return ["prompts"]

def writes() -> List[str]:
@property
def writes(self) -> list[str]:
return ["all_llm_outputs"]

"""
Expand Down Expand Up @@ -433,7 +435,7 @@ def actions(self, state: State) -> Generator[Action | Callable | RunnableGraph,
query_llm.bind(model="gpt-4").with_name("gpt_4_answer"),
query_llm.bind(model="o1").with_name("o1_answer"),
query_llm.bind(model="claude").with_name("claude_answer"),
]
]:
yield action

def state(self, state: State) -> State:
Expand All @@ -445,10 +447,12 @@ def reduce(self, states: Generator[State, None, None]) -> State:
all_llm_outputs.append(state["llm_output"])
return state.update(all_llm_outputs=all_llm_outputs)

def reads() -> List[str]:
@property
def reads(self) -> List[str]:
return ["prompt"] # we're just running this on a single prompt, for multiple actions

def writes() -> List[str]:
@property
def writes(self) -> List[str]:
return ["all_llm_outputs"]

"""
Expand Down Expand Up @@ -542,10 +546,12 @@ def reduce(self, states: Generator[State, None, None]) -> State:
all_llm_outputs.append(state["llm_output"])
return state.update(all_llm_outputs=all_llm_outputs)

def reads() -> List[str]:
@property
def reads(self) -> List[str]:
return ["prompts"]

def writes() -> List[str]:
@property
def writes(self) -> List[str]:
return ["all_llm_outputs"]
"""

Expand Down
4 changes: 3 additions & 1 deletion examples/parallelism/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

In this example we go over Burr's parallelism capabilities. It is based on the documentation (https://burr.dagworks.io/pull/370/concepts/parallelism/), demonstrating the `MapStates` capabilities.

See [the notebook](./notebook.ipynb) for the full example.
See [the notebook](./notebook.ipynb) for the full example. Or <a target="_blank" href="https://colab.research.google.com/github/dagworks-inc/burr/blob/main/examples/parallelism/notebook.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
</a>

You can follow along with this [Loom video](https://www.loom.com/share/a871abe84f974a499d7fb5bae42c35ae)
Loading
Loading