In long-horizon autonomous systems engineering, injecting Qwen3.7-Max with a four-stage closed-loop prompt comprising "baseline comparison, compilation profiling, test-driven iteration, and state staging," combined with a rigorous anti-reward-hacking (Anti-Reward-Hacking) verifier, enables the model to autonomously iterate for hundreds of consecutive rounds and achieve over a 10x kernel speedup.
Suitable tasks: Low-level Triton / CUDA kernel performance tuning, proprietary compiler pass optimization, complex profiling (Profiling) , and automated test repair.
Unsuitable tasks: Open-ended code refactoring without benchmark suites (Benchmark Harness) or objective measurement metrics.
Applicable model versions: qwen3.7-max (must enable enable_thinking: true and preserve_thinking: true ) .
Applicable clients, Agents, or APIs: Custom long-horizon Agent harnesses, Qwen Code, and OpenClaw.
Recommended reasoning level and parameters: Thinking level set to maximum (xhigh) , strictly limit maximum output tokens per turn, and drive progress via multi-turn tool feedback.
You are a senior GPU systems and high-performance computing (HPC) optimization expert. Your objective is to write highly optimized Triton/CUDA kernels for a given reference kernel implementation.
[Optimization Baseline and Constraints]
1. Target Kernel: Extend Attention Kernel (reference baseline: baseline_triton.py)
2. Hardware Environment: Single-GPU isolated environment, memory-constrained, no external network access
3. Correctness First Principle: After every optimization iteration, the implementation must pass test_correctness.py (full-precision and mixed-precision absolute error < 1e-4)
4. Strict Anti-Reward-Hacking Rules (Anti-Reward-Hacking) :
- Hardcoding specific input shapes or tabularizing outputs for particular inputs is strictly prohibited;
- Tampering with timing logic or accuracy thresholds in test scripts is strictly prohibited;
- Using early return (Early Return) or no-op computations to forge speedup is strictly prohibited.
[Iteration Workflow]
Phase 1 (Baseline Measurement) : Call profile_tool to run baseline_triton.py, recording baseline latency and GPU memory bandwidth utilization;
Phase 2 (Bottleneck Analysis) : Analyze whether the workload is compute-bound (Compute-bound) or memory-bound (Memory-bound) , and propose targeted optimization hypotheses (e.g., Block Tiling, Shared Memory Bank Conflict elimination, Warp cooperation) ;
Phase 3 (Coding and Verification) : Write the new kernel file `kernel_v{N}.py`, and call the `run_verification` tool to verify numerical correctness and performance speedup;
Phase 4 (Rollback and Convergence) : If correctness verification fails or performance degrades, analyze error logs, execute a rollback, and adjust the optimization direction. If no improvement is achieved for 20 consecutive rounds, stop exploration and summarize the current optimal implementation.Build an isolated Docker sandbox and mount the reference implementation to be optimized alongside an immutable, read-only verifier (Verifier) .
Configure persistent state preservation in the Agent scaffold, appending the stdout/stderr from the previous tool invocation into the next turn's context verbatim.
Inject anti-reward-hacking (Reward-Hacking Monitor) detection scripts: after each code submission from the model, intercept dead-code elimination (Dead Code Elimination) and hardcoding deception via static Abstract Syntax Tree (AST) analysis and dynamic input perturbation.
Set a maximum execution budget (e.g., 500 tool calls) and a no-progress circuit breaker (e.g., automatically abort after 2 hours without speedup improvement) .
Official long-horizon experimental data shows: across 35 consecutive hours of autonomous optimization, Qwen3.7-Max completed a total of 1,158 tool interactions and 432 kernel evaluations, ultimately achieving a 10.0x geometric-mean speedup relative to the official Triton reference implementation.
During the experiment, by setting up 13 heuristic anti-reward-hacking monitoring rules, 1,618 potential cheating attempts (such as empty loops and test bypasses) were identified and intercepted, demonstrating the necessity of independent verifiers in long-horizon Agents.
This prompt and workflow are heavily reliant on hardware-isolated environments and deterministic profiling tools; they must not be run directly on bare-metal production machines without sandbox protection.
Long-horizon autonomous iteration consumes tens of millions to hundreds of millions of tokens, requiring strict budget evaluation based on actual compute costs and business return on investment (ROI) .
The Qwen team summarized: "Long-horizon autonomy... 35 hours straight on a kernel optimization task — 1,000+ tool calls, zero hand-holding. The model maintains steady progress under robust verifier constraints".
Qwen3.7 Max