Skip to content

Integrating Custom Backends via JSON Platform Configs#109

Open
can-gaa-hou wants to merge 1 commit intometa-pytorch:mainfrom
can-gaa-hou:multi-backend
Open

Integrating Custom Backends via JSON Platform Configs#109
can-gaa-hou wants to merge 1 commit intometa-pytorch:mainfrom
can-gaa-hou:multi-backend

Conversation

@can-gaa-hou
Copy link

Summary

This change extends KernelAgent’s multi-platform support by allowing users to integrate a custom backend (or override existing platform settings) via an external JSON file. The JSON is loaded at import time and merged into the in-memory platform registry, enabling new --target-platform <name> values (e.g., npu) without modifying repository code.

Motivation

KernelAgent already supports CUDA and Intel XPU via a built-in PlatformConfig registry. However, adding a new backend (e.g., an NPU platform) typically requires:

  • Modifying the in-repo platform registry,
  • Updating prompts and device checks,
  • Shipping and maintaining these changes for each new backend.

This PR introduces a lightweight escape hatch: JSON-defined platform configs that can be set per-environment. It lowers the friction for downstream teams with custom backends (rocm, tpu, npu, etc.) experimenting.

Usage

Define a custom platform (example: NPU)

  1. Create a JSON file:
{
  "npu": {
    "name": "npu",
    "device_string": "npu",
    "guidance_block": "...",
    "kernel_guidance": "...",
    "cuda_hacks_to_strip": []
  }
}
  1. Export the env var (must be set before importing KernelAgent modules):
export KERNELAGENT_PLATFORM_JSON=/abs/path/to/platforms.json
  1. Select the platform via existing CLI flags (examples shown in README):
python -m Fuser.auto_agent --problem /abs/path/to/problem.py --target-platform npu

Programmatic usage

from triton_kernel_agent import TritonKernelAgent

agent = TritonKernelAgent(
    num_workers=4,
    max_rounds=8,
    model_name="gpt-5",
    target_platform="npu",  # can now pass a string
)

Testing

This PR does not add new unit tests since it requires external JSON files, but the following verification has been tested:

  • Tested on CUDA (default behavior unchanged)
  • Tested on a custom backend (NPU)
  • CLI --target-platform flag works for auto_agent, pipeline, and cli
  • UI platform dropdown works in all three UIs

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 2, 2026
@Jack-Khuu Jack-Khuu requested review from Jack-Khuu, Laurawly and kaiming-cheng and removed request for Jack-Khuu, Laurawly and kaiming-cheng March 3, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant