Download code/compoundingkernel/__init__.py from QianQu/CompoundingKernel-Explorer: direct link, hf CLI and curl.
- Browser
- Download file 3.34 kB
-
https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/code/compoundingkernel/__init__.py
- Command line
-
hf download hf://spaces/QianQu/CompoundingKernel-Explorer/code/compoundingkernel/__init__.py
-
curl -L -o __init__.py https://huggingface.co/spaces/QianQu/CompoundingKernel-Explorer/resolve/main/code/compoundingkernel/__init__.py
3.34 kB
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
| # SPDX-License-Identifier: CC-BY-NC-4.0 | |
| """CompoundingKernel: a self-improving search in which LLM agents write fast GPU kernels.""" | |
| from __future__ import annotations | |
| import copy | |
| import json | |
| import os | |
| import string | |
| __version__ = "0.1.0" | |
| # Our prompts are not included. Every model-facing text (the prompts, the first and follow-up | |
| # turns, the tool descriptions) comes from load_prompt(). With no prompt_dir, or no file for a | |
| # slot, the slot gets this placeholder, so the code shows the data flow without our text. | |
| PROMPT_PLACEHOLDER = "<prompt not released>" | |
| # The slots, and the fields each one is given (as $name in your own template files). | |
| PROMPT_SLOTS = { | |
| "controller": (), | |
| "controller_start": ("problem_dir", "minutes", "budget", "slots"), | |
| "controller_continue": ("minutes_remaining", "used", "budget", "transient"), | |
| "child": (), | |
| "child_task": ("problem_dir", "parent_id", "parent_files", "parent_result", "direction"), | |
| "tool_query_archive": (), | |
| "tool_expand": (), | |
| "tool_compile_check": (), | |
| "tool_evaluate_kernel": (), | |
| "tool_profile_kernel": (), | |
| "tool_check_robustness": (), | |
| "tool_query_history": (), | |
| "tool_get_solution": (), | |
| } | |
| def load_prompt(name: str, prompt_dir: str | None = None, **fields) -> str: | |
| """The text for one model-facing slot: <prompt_dir>/<name>.txt with $fields filled in.""" | |
| if prompt_dir: | |
| path = os.path.join(prompt_dir, name + ".txt") | |
| if os.path.isfile(path): | |
| with open(path, encoding="utf-8") as f: | |
| return string.Template(f.read()).safe_substitute(fields) | |
| return PROMPT_PLACEHOLDER | |
| # The settings of one search (see examples/example_config.yaml for what each key means). | |
| DEFAULTS = { | |
| "search": {"arm": "hyper", "problem_dir": None, "run_id": "run-1", "archive_dir": "runs", | |
| "time_limit_min": 600, "budget": 1000, "gpus": [0], "children_per_gpu": 4, | |
| "candidates_per_child": 1}, | |
| "model": {"provider": "bedrock", "id": "global.anthropic.claude-opus-5-5", "aws_region": None, | |
| "controller_max_turns": 100000, "child_max_turns": 100000}, | |
| "prompts": {"prompt_dir": None}, | |
| "harness": {"compile_timeout_s": 300, "eval_timeout_s": 900, "lock_dir": "/tmp/ck-gpu-locks", | |
| "anchors": None, "bench_config": None}, | |
| "checks": {"native_code": "refuse", "precision": "paper", | |
| "precision_exempt_boards": ["Quant"], "robustness_on_new_best": True, | |
| "robustness_shapes": 12, "sanitizer_on_new_best": True}, | |
| "controller": {"reinvoke_max": 20, "min_left_min": 10, "idle_wait_min": 15, "grace_s": 60, | |
| "backoff_s": 30, "backoff_cap_s": 600}, | |
| "tree": {"c": 0.7, "width_start": 4, "width_decay": 0.6, "width_min": 1, "grace": 3, | |
| "margin": 0.15}, | |
| } | |
| def load_config(path) -> dict: | |
| """A config file (YAML, or JSON without PyYAML) merged over DEFAULTS.""" | |
| with open(path, encoding="utf-8") as f: | |
| text = f.read() | |
| try: | |
| import yaml | |
| data = yaml.safe_load(text) | |
| except ImportError: | |
| data = json.loads(text) | |
| cfg = copy.deepcopy(DEFAULTS) | |
| for section, values in (data or {}).items(): | |
| cfg.setdefault(section, {}).update(values or {}) | |
| return cfg | |