Generate the Python __init__.py for the HF Kernels module.
(
name: str,
functions: List[Dict[str, str]],
repo_id: str,
backend: str = "cuda",
)
| 448 | # --------------------------------------------------------------------------- |
| 449 | |
| 450 | def generate_init_py( |
| 451 | name: str, |
| 452 | functions: List[Dict[str, str]], |
| 453 | repo_id: str, |
| 454 | backend: str = "cuda", |
| 455 | ) -> str: |
| 456 | """Generate the Python __init__.py for the HF Kernels module.""" |
| 457 | first_func = functions[0]["name"] if functions else "kernel_fn" |
| 458 | |
| 459 | if backend == "cuda": |
| 460 | return textwrap.dedent(f'''\ |
| 461 | """ |
| 462 | {name} - Optimized GPU kernel exported from AutoKernel |
| 463 | https://github.com/RightNow-AI/autokernel |
| 464 | |
| 465 | Usage: |
| 466 | from kernels import get_kernel |
| 467 | module = get_kernel("{repo_id}") |
| 468 | result = module.{first_func}(input) |
| 469 | """ |
| 470 | from ._C import * # noqa: F401,F403 |
| 471 | ''') |
| 472 | else: |
| 473 | # Triton kernel: import the Python module directly |
| 474 | return textwrap.dedent(f'''\ |
| 475 | """ |
| 476 | {name} - Optimized Triton GPU kernel exported from AutoKernel |
| 477 | https://github.com/RightNow-AI/autokernel |
| 478 | |
| 479 | Usage: |
| 480 | from kernels import get_kernel |
| 481 | module = get_kernel("{repo_id}") |
| 482 | result = module.kernel_fn(input) |
| 483 | """ |
| 484 | from .kernel import kernel_fn # noqa: F401 |
| 485 | ''') |
| 486 | |
| 487 | |
| 488 | # --------------------------------------------------------------------------- |
no outgoing calls
no test coverage detected