|
1 | 1 | """Autonomous pipeline agent for chaining kernel generation steps.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | import logging |
4 | 5 | import os |
5 | 6 | import re |
|
12 | 13 | from google.adk.models import LlmRequest |
13 | 14 | from google.genai import types |
14 | 15 |
|
15 | | -from auto_agent.config import WORKDIR |
| 16 | +from auto_agent.config import TPU_VERSION, WORKDIR |
| 17 | +from auto_agent.knowledge_base import pallas_docs, pallas_profiling_docs |
16 | 18 |
|
17 | 19 |
|
18 | 20 | class AutonomousPipelineAgent(BaseAgent): |
@@ -319,6 +321,29 @@ def _initialize_state(self, ctx: InvocationContext) -> Event: |
319 | 321 | if "history" not in ctx.session.state: |
320 | 322 | ctx.session.state["history"] = [] |
321 | 323 |
|
| 324 | + # Initialize TPU version and Pallas docs in state |
| 325 | + tpu_version = TPU_VERSION |
| 326 | + ctx.session.state["tpu_version"] = tpu_version |
| 327 | + logging.info(f"[{self.name}] Detected TPU version: {tpu_version}") |
| 328 | + |
| 329 | + try: |
| 330 | + with open("auto_agent/tpu_specs.json", "r") as f: |
| 331 | + tpu_specs = json.load(f) |
| 332 | + |
| 333 | + if tpu_version in tpu_specs: |
| 334 | + ctx.session.state["tpu_specs"] = tpu_specs[tpu_version] |
| 335 | + else: |
| 336 | + ctx.session.state["tpu_specs"] = ( |
| 337 | + "TPU specs not found for detected version." |
| 338 | + ) |
| 339 | + logging.info(f"[{self.name}] Loaded TPU specs for {tpu_version}") |
| 340 | + except Exception as e: |
| 341 | + logging.error(f"[{self.name}] Failed to load TPU specs: {e}") |
| 342 | + ctx.session.state["tpu_specs"] = None |
| 343 | + |
| 344 | + ctx.session.state["pallas_docs"] = pallas_docs.PROMPT |
| 345 | + ctx.session.state["pallas_profiling_docs"] = pallas_profiling_docs.PROMPT |
| 346 | + |
322 | 347 | # Path related states |
323 | 348 | session_dir = self.session_dir or os.path.join(WORKDIR, ctx.session.id) |
324 | 349 |
|
@@ -425,6 +450,12 @@ def _initialize_state(self, ctx: InvocationContext) -> Event: |
425 | 450 | "autotune_specs_path": ctx.session.state["autotune_specs_path"], |
426 | 451 | "autotune_results_path": ctx.session.state["autotune_results_path"], |
427 | 452 | "xplane_pb_path": ctx.session.state["xplane_pb_path"], |
| 453 | + "tpu_version": ctx.session.state.get("tpu_version"), |
| 454 | + "tpu_specs": ctx.session.state.get("tpu_specs"), |
| 455 | + "pallas_docs": ctx.session.state.get("pallas_docs"), |
| 456 | + "pallas_profiling_docs": ctx.session.state.get( |
| 457 | + "pallas_profiling_docs" |
| 458 | + ), |
428 | 459 | } |
429 | 460 | ), |
430 | 461 | ) |
|
0 commit comments