Skip to main content

Tilesmith

Tilesmith is a small optimization layer for PyTorch. PyTorch still performs graph capture, AOTAutograd, and TorchInductor compilation. After Inductor emits an eligible CUDA wrapper, Tilesmith gives that complete generated implementation to an Agent, measures its candidates against the original wrapper, and installs only a numerically correct, independently confirmed speedup.

import tilesmith

optimized_model = tilesmith.compile(
    model,
    example_inputs=(x,),
    agent_model="gpt-5.5",
)
output = optimized_model(x)

for result in tilesmith.benchmarks(optimized_model):
    print(result.torch_inductor_ms, result.tilesmith_ms, result.speedup)

for diagnostic in tilesmith.diagnostics(optimized_model):
    print(diagnostic.kind, diagnostic.message)

optimized_model remains a normal torch.compile callable. Tilesmith does not replace PyTorch or ask the model to rewrite the user's module. Benchmark results and fallback diagnostics appear after the first call because optimization is lazy.

Install

Start with an environment that already has a matching CUDA build of PyTorch and Triton, then install Tilesmith and its agent runtime:

python3 -m pip install tilesmith-ai
cliproxyapi -codex-login

All model traffic goes through a private CLIProxyAPI process. Its upstreams may be OAuth accounts or API providers from the CLIProxyAPI YAML. Tilesmith detects accounts at ~/.cli-proxy-api and Homebrew's CLIProxyAPI config; set TILESMITH_CLIPROXYAPI_EXECUTABLE, TILESMITH_CLIPROXYAPI_AUTH_DIR, or TILESMITH_CLIPROXYAPI_CONFIG to override those paths. Tilesmith copies the config for each run, preserving provider and routing settings while replacing only its private loopback server settings.

Provider keys can instead be exported normally. Tilesmith converts them into the temporary CLIProxyAPI config; it does not create a direct provider path:

export ANTHROPIC_API_KEY=sk-ant-...

Supported conventional names are OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY, XAI_API_KEY, VERTEX_API_KEY, and OPENROUTER_API_KEY. For any OpenAI-compatible endpoint, export TILESMITH_API_KEY together with TILESMITH_API_BASE_URL.

Compile from PyTorch

optimized_model = tilesmith.compile(
    model,
    example_inputs=(x,),
    agent_model="gpt-5.5",
    agency="medium",
    loops=1,
    max_model_calls=None,
)

example_inputs must be a tuple with at least one CUDA tensor. agent_model selects the optimizer model and overrides TILESMITH_MODEL; choose one listed by CLIProxyAPI. Compilation is lazy: PyTorch finishes compiling first, and the first real invocation supplies the concrete tensors used for Tilesmith's correctness and timing checks.

When example_inputs, agent_model/TILESMITH_MODEL, or CLIProxyAPI is unavailable, tilesmith.compile(...) returns ordinary torch.compile(...). tilesmith.benchmarks(...) then returns an empty tuple.

agency controls how broadly the agent may alter generated code. "low" preserves the existing wrapper and kernel boundaries while allowing localized tuning such as coalescing, tile sizes, launch parameters, and vectorization. The default "medium" may restructure wrapper logic, intermediate buffers, and kernel fusion or decomposition while preserving the high-level algorithm. "high" may also redesign the algorithm and generated implementation. All three levels preserve the generated callable ABI and pass the same host-owned correctness, timing, and fresh-confirmation gates.

loops counts accepted optimization cycles, not agent turns or timing repetitions. It defaults to 1. A slower, incorrect, duplicate, or marginal candidate is rejected and the same loop continues.

max_model_calls is an optional exact budget on LangChain model invocations shared by the main agent and its subagents. It defaults to None; there is no default 70-step limit. Provider transport retries remain inside one invocation. Shell, tool, benchmark, and graph-transition calls do not consume this budget. For example, max_model_calls=70 permits 70 invocations and blocks the 71st. If the budget expires without a validated win, Tilesmith keeps ordinary Inductor rather than installing an unconfirmed candidate.

Dynamic-shape, mixed-device, multi-GPU, input-mutating, and already wrapped graphs currently stay on ordinary Inductor. A raw single-GPU CUDA wrapper stays eligible whether it embeds Triton or generated CUDA templates, calls external libraries, or combines them. Inductor's FX and generated-code caches remain enabled.

What the agent does

Each uncached graph gets an agent.

Each tilesmith.compile() call receives a unique run ID. When an eligible graph is first invoked, it keeps five rolling source files within that run:

~/.cache/tilesmith/runs/<run-id>/<cache-key>/attempts/
  attempt_00.py
  attempt_01.py
  attempt_02.py
  attempt_03.py
  attempt_04.py

<cache-key> is the 64-character SHA-256 identity of one generated graph and its optimization environment. A single compile run may contain several such graphs, such as forward, backward, or graph-break regions.

Every attempt starts with the captured PyTorch FX program as comments, followed by one canonical Inductor-generated Python wrapper for that graph. The wrapper contains its call(args) entry point, allocations, streams, launches, embedded Triton or generated-template source when Inductor emits it, and external-library call sites. Library implementations, weights, PTX, cubins, and shared objects remain runtime dependencies or cache artifacts rather than being copied into the attempt. Forward, backward, graph-break, and shape-specialized graphs each receive their own track instead of being merged into one model-sized file.

A new turn copies the most recently evaluated source. After attempt_04.py, the oldest contents are discarded and the other attempts shift down. Complete host reports are retained beside the attempts under profiles/. Set TILESMITH_DEBUG=1 to also retain per-turn structured agent traces. An exact artifact-cache hit does not rerun the agent; its fresh run track contains cache.json, which identifies the reused artifact.

An agent final answer ends only that agent turn. The outer LangGraph does not finish a requested loop until the host:

  1. compares the candidate with the original Inductor wrapper on normal, zero, and high-magnitude inputs, including output strides;
  2. measures alternating paired CUDA-event samples;
  3. observes at least TILESMITH_MIN_IMPROVEMENT, which defaults to 0.02;
  4. repeats correctness and timing in a fresh confirmation; and
  5. sees the confirmation clear the same speedup threshold.

Metadata

Release files for tilesmith-ai 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tilesmith-ai 0.1.4
File Size Uploaded Provenance Actions
tilesmith_ai-0.1.4.tar.gz 49.9 kB With provenance Details for tilesmith_ai-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tilesmith-ai 0.1.4
File Interpreter ABI Platform Actions
tilesmith_ai-0.1.4-py3-none-any.whl Python 3 none any Details for tilesmith_ai-0.1.4-py3-none-any.whl

Total release size: 99.0 kB

Release files / tilesmith_ai-0.1.4.tar.gz

Download URL tilesmith_ai-0.1.4.tar.gz
Size 49.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6abf32bf6b9d7575474d50a4e32fbc097fac7f70b16929469b0abd2f6ae027e5
BLAKE2b-256 checksum
How to use checksums
4da561609ab20d3acbdd9d068ed66be48c618a875c8ebb70da8583ff9ae5feb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2026.

Transparency log

Release files / tilesmith_ai-0.1.4-py3-none-any.whl

Download URL tilesmith_ai-0.1.4-py3-none-any.whl
Size 49.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ee0dc95a8b1248654cf66128b215cf2d6a67c62cf4b5dfa85578ffebab34f79
BLAKE2b-256 checksum
How to use checksums
4262d25c5857da45af1a8c3c9a738b411ecb2a43c4d3009ffbe546e4dcf21ff1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2026.

Transparency log

Security for tilesmith-ai 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tilesmith_ai-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page