Skip to content

Explore AI-agent-assisted translation pipeline (inspired by Modular's Mojo approach) #88

Description

@Tokarzewski

Context

Modular published a writeup on how they translate Python/CUDA/SYCL/C++ code to Mojo using general-purpose AI coding agents (Claude, etc.) augmented with a lightweight "skills" system, instead of a purely rule-based transpiler.

Source: https://www.modular.com/blog/translating-to-mojo-via-ai-agents

Key ideas from the article

  • Skill-injected idioms instead of hardcoded rule tables: target-language conventions/gotchas (mojo-syntax, mojo-gpu-fundamentals, etc.) are packaged as retrievable docs the agent loads on demand (npx skills add modular/skills), compensating for the target language being too new/low-resource for the LLM to know natively.
  • Compile-error-driven repair loop: the agent translates → compiles → runs against a reference/test harness → reads compiler errors and numerical diffs → self-corrects. Strict, typed target languages give much better repair signal than loose ones.
  • Structural/idiomatic remapping over literal translation: for constructs with no 1:1 equivalent (e.g. CUDA warp-level tricks → portable shared-memory tree reduction), the agent restructures to the target's idiomatic form rather than doing line-by-line translation.
  • Numerical/behavioral equivalence as the correctness oracle: when exact output isn't feasible (floating-point kernels, reordered reductions), validate via numerical drift (e.g. softmax row-sum ≈ 1.0 within float epsilon) and benchmark comparisons rather than only pass/fail unit tests.
  • Reference implementations + published test harnesses: ground truth to diff against, usable by rule-based or agentic translation alike.

Proposed action items

  • Evaluate whether a "skills"-style idiom-injection approach could reduce hardcoded pattern tables in our transpiler passes
  • Investigate piping target-compiler errors back into an LLM-assisted repair loop for cases our static rules don't cover
  • Identify constructs in our supported source/target languages that have no 1:1 mapping and would benefit from idiomatic restructuring instead of literal translation
  • Consider numerical/behavioral equivalence checks as a fallback oracle where exact output matching isn't feasible
  • Audit our test harnesses/reference implementations for reuse as ground truth in an agent-assisted pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions