Skip to content

Smoke test integration of XTC in Pytorch#80

Draft
ElectrikSpace wants to merge 3 commits into
xtc-tools:mainfrom
ElectrikSpace:dev/snoiry/pytorch
Draft

Smoke test integration of XTC in Pytorch#80
ElectrikSpace wants to merge 3 commits into
xtc-tools:mainfrom
ElectrikSpace:dev/snoiry/pytorch

Conversation

@ElectrikSpace

Copy link
Copy Markdown
Contributor

Motivation

Following discussions with the maintainers, we would like to propose a lighweight integration of XTC in the Pytorch ecosystem. The goal is to be able to compile with XTC selected operators coming from models written with Pytorch, and execute the model by combining code generated with XTC and a default code generator for the other operators.

Description

The PR proposes an integration of XTC in Pytorch, by extending Pytorch withing the XTC repo.

  • Create custom ops for xtc operators in pytorch (only xtc.matmul for
    now)
  • Create a pre_grad fx pass to rewrite torch operators to xtc torch
    operators (e.g. linear to matmul)
  • Provide a eager implementation of the xtc torch operators that do one
    shot compile with xtc
  • Provide a torch inductor lowering for xtc torch operators (with cpp
    wrapper), and call one shot xtc compile at compile time of aot
    inductor run
  • patch runtime inductor ops lib with compiled kernel from xtc + codegen
    a cpp wrapper around

This is still work in progres

(copied from commit message)

Commits

This PR contains 3 commits. The first two are the same as #79

The last commit contains the proposed integration of XTC with Pytorch.

[DO NOT MERGE BEFORE #79]

Discussion

Some points need to be discussed before merging the PR:

  • Do we want to put the integration of XTC with Pytorch in the XTC repo, meaning that it adds a dependency to Pytorch to run the XTC tests.

TODO:

  • Validate or amend architecture decisions before implementing the integration for all operators that XTC can support.
  • Create an example/marimo to explain to the users how to use it.

Lower ub dialect to llvm when using the LLVMIR target.
This patch adds a "layout" option when creating XTC tensors to relayout the
storage in memory. The relayouting is considered done outside the
evaluation or at compile time if the data is constat.
Thus this patch also add a "const" option to specify if the tensor data
is constant.
@ElectrikSpace ElectrikSpace requested a review from guillon May 26, 2026 12:16
Comment thread src/xtc/integration/pytorch/compile.py Outdated


def schedule_matmul(sch: object) -> None:
sch.strip_mine("i", {"i1": 2}) # type: ignore[attr-defined]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using the right itf.sch.Scheduler type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Because of the vide coded code x)]
It's fixed

@@ -0,0 +1,371 @@
#

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you use jinja2 templates instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never used jinja2 template, maybe that's a good idea.

- Create custom ops for xtc operators in pytorch (only xtc.matmul for
  now)
- Create a pre_grad fx pass to rewrite torch operators to xtc torch
  operators (e.g. linear to matmul)
- Provide a eager implementation of the xtc torch operators that do one
  shot compile with xtc
- Provide a torch inductor lowering for xtc torch operators (with cpp
  wrapper), and call one shot xtc compile at compile time of aot
  inductor run
- patch runtime inductor ops lib with compiled kernel from xtc + codegen
  a cpp wrapper around

This is still work in progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants