Skip to content

Commit 1091cde

Browse files
refactor: pass reference_code to ADKSessionWorker for base kernel input
1 parent 5382377 commit 1091cde

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

MaxKernel/auto_search/worker.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ async def expand_node(
1717
node_id: str,
1818
parent_node: Node,
1919
session_dir: str,
20+
reference_code: str,
2021
strategy: Optional[str] = None,
2122
agent_config: Optional[Dict[str, Any]] = None,
2223
) -> Node:
2324
"""Expand an ADK session to get a new optimized kernel."""
2425
os.makedirs(session_dir, exist_ok=True)
2526

26-
# Prepare inputs files for the agent based on parent_node
27-
self._prepare_inputs(session_dir, parent_node)
27+
# Prepare inputs files for the agent based on reference_code and parent_node
28+
self._prepare_inputs(session_dir, parent_node, reference_code)
2829

2930
# Run the agent and process results
3031
try:
@@ -56,15 +57,18 @@ async def expand_node(
5657
evaluation=EvaluationResult(correct=False),
5758
)
5859

59-
def _prepare_inputs(self, session_dir: str, parent_node: Node) -> None:
60-
"""Writes the parent node code and plan to the session directory."""
60+
def _prepare_inputs(
61+
self, session_dir: str, parent_node: Node, reference_code: str
62+
) -> None:
63+
"""Writes the reference code and parent's optimized code (if any) to session directory."""
6164
base_kernel_path = os.path.join(session_dir, "base_kernel.py")
6265
with open(base_kernel_path, "w") as f:
63-
f.write(parent_node.code)
66+
f.write(reference_code)
6467

65-
optimized_kernel_path = os.path.join(session_dir, "optimized_kernel.py")
66-
with open(optimized_kernel_path, "w") as f:
67-
f.write(parent_node.code)
68+
if parent_node.depth > 0 and parent_node.code:
69+
optimized_kernel_path = os.path.join(session_dir, "optimized_kernel.py")
70+
with open(optimized_kernel_path, "w") as f:
71+
f.write(parent_node.code)
6872

6973
kernel_plan_path = None
7074
if parent_node.plan:

0 commit comments

Comments
 (0)