tnzr.agents#
Coding agents building a tensor contraction compiler
tnzr.agents develops a workflow in which coding agents build a compiler for tensor contractions. The workflow splits the development into tasks. Each task gives one agent a fixed working time for one part of the compiler. A review system judges the agent’s work with hidden test cases. We ran the workflow once, for three GPUs and two CPUs of NVIDIA, AMD and Apple. In 11 tasks with 295 hours of working time and 109 reviews, the agents built a compiler that runs without a language model and uses heuristics to compile a new contraction within seconds.
We compare the compiler’s programs with three baselines on benchmark workloads from applications:
Transpose-transpose-GEMM-transpose (TTGT) transposes the tensors into matrices and multiplies them with the general matrix multiplication (GEMM) from a library of the device’s vendor.
Direct calls a library for tensor contractions.
ML compiler compiles the contraction with the compiler of a machine learning framework.
The speedup on a workload is the time of the fastest baseline divided by the time of our compiler’s program. A speedup above 1 shows that this program is faster.
The compiler’s programs pass on every benchmark workload that fits into the device’s memory. Figure 1 shows their speedups with bfloat16 (BF16) tensors on the GPUs and 32-bit floating-point (FP32) tensors on the CPUs. On the general contractions of the sets TCCG and NWChem, the speedups range from 1.04 to 5.00 in the geometric mean of each set and device. On the GEMMs of the sets DeepGEMM, Muse and oneDNN, they range from 0.60 to 1.36.
Figure 1 Speedup of the compiler’s programs over the fastest of three baselines on each benchmark set with BF16 tensors on the GPUs and FP32 tensors on the CPUs, as the geometric mean over the set’s workloads. The gray line at 1 marks the fastest baseline.#
We describe the workflow and the compiler in six chapters:
Background introduces tensor contractions, schedules, the roofline model and coding agents.
TZIR presents TZIR, the intermediate representation on which the compiler builds.
Workflow describes how the agents built the compiler in tasks with reviews.
Benchmarks describes the workloads, the baselines and how we measured the programs.
Results compares the compiler with the baselines in two datatypes on each device and analyzes its heuristics and performance models.
Outlook gives the limitations of this work, its next steps and related work.