Skip to content

Commit

Permalink
Update time profiler to use context dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpalmieri committed Aug 28, 2024
1 parent 3876ba5 commit c66253d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 2 additions & 5 deletions lavague-core/lavague/core/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,15 @@ def get_nodes(self, query: str) -> List[str]:

html = self.driver.get_html()

retrieved_nodes_size = {"size": 0}

with time_profiler(
"Retriever Inference",
html_size=len(html),
retrieved_nodes_size=retrieved_nodes_size,
):
) as profiler:
source_nodes = self.retriever.retrieve(
QueryBundle(query_str=query), [html], viewport_only
)

retrieved_nodes_size["size"] = sum(len(node) for node in source_nodes)
profiler["retrieved_nodes_size"] = sum(len(node) for node in source_nodes)

return source_nodes

Expand Down
10 changes: 3 additions & 7 deletions lavague-core/lavague/core/utilities/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def time_profiler(
event_name,
prompt_size=None,
html_size=None,
retrieved_nodes_size=None,
full_step_profiling=False,
):
"""
Expand All @@ -43,9 +42,10 @@ def time_profiler(
- html_size: Optional size of the HTML, if applicable.
- full_step_profiling: Boolean indicating whether to profile full steps or individual events.
"""
context = {}
start_time = time.perf_counter()
try:
yield
yield context
finally:
end_time = time.perf_counter()
duration = end_time - start_time
Expand All @@ -57,11 +57,7 @@ def time_profiler(
"duration": duration,
**({"prompt_size": prompt_size} if prompt_size is not None else {}),
**({"html_size": html_size} if html_size is not None else {}),
**(
{"retrieved_nodes_size": retrieved_nodes_size["size"]}
if retrieved_nodes_size is not None
else {}
),
**context,
}

# append the record to the appropriate list
Expand Down

0 comments on commit c66253d

Please sign in to comment.