# \[GUIDE\] Getting C++ custom ops to work with torch.compile

**URL:** <https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737>\
**Category:** compiler\
**Created:** [December 18, 2023, 8:52pm UTC](https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737 "2023-12-18T20:52:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zou3519](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/zou3519/32/163_2.png) [@zou3519](https://dev-discuss.pytorch.org/u/zou3519)\
**Post date:** [December 18, 2023, 8:52pm UTC](https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737/1 "2023-12-18T20:52:51Z")

</div>

If you have a library of existing C++ custom ops that work with PyTorch, they may not work with torch.compile. Here’s our guide on how to get them to work: [The C++ Custom Operators Manual - Google Docs](https://docs.google.com/document/d/1_W62p8WJOQQUzPsJYa7s701JXt0qf2OfLub2sbkHOaU/edit) .

We’re still looking into ways to make the experience better but would appreciate feedback from users.

---

<div class="post-metadata">

**Author:** ![YangFei1990](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/yangfei1990/32/961_2.png) [@YangFei1990](https://dev-discuss.pytorch.org/u/YangFei1990)\
**Post date:** [December 22, 2023, 12:23am UTC](https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737/2 "2023-12-22T00:23:25Z")

</div>

Hi Richard, many thanks for the guidance! Wondering if there is a easier way to handle a broader case, say that there is some function/module/custom op that could cause issue with `torch.compile`.  
Currently Dynamo offers API `torch._dynamo.allow_in_graph` in case there is something that user does not want trace through. However with this API Dynamo will still need to run the leaf node with fake tensor, there is an issue for it [Torch Dynamo allow\_in\_graph doesn't capture the custom function in graph · Issue #97295 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/97295).  
Would it be possible to change the `torch._dynamo.allow_in_graph` API to record the leaf node output signature as well? Something like

```auto
torch._dynamo.allow_in_graph(ModuleSkipTrace, example_output=torch.rand(4,4))

```

So during the wrapping FX proxy we can directly provide example value to skip [using fake tensor to run the node](https://github.com/pytorch/pytorch/blob/main/torch/_dynamo/variables/builder.py#L1408)?

---

<div class="post-metadata">

**Author:** ![zou3519](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/zou3519/32/163_2.png) [@zou3519](https://dev-discuss.pytorch.org/u/zou3519)\
**Post date:** [January 4, 2024, 5:59pm UTC](https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737/3 "2024-01-04T17:59:04Z")

</div>

I believe you’re looking for [Black box a Python function for use with torch.compile - Google Docs](https://docs.google.com/document/d/1ZuCVyMfibExwvtzhd9cfMWk5zXT3Dhy1b3kuvAIkBoU/edit#heading=h.56tggsazyrkh)

---

<div class="post-metadata">

**Author:** ![YangFei1990](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/yangfei1990/32/961_2.png) [@YangFei1990](https://dev-discuss.pytorch.org/u/YangFei1990)\
**Post date:** [January 16, 2024, 7:22pm UTC](https://dev-discuss.pytorch.org/t/guide-getting-c-custom-ops-to-work-with-torch-compile/1737/4 "2024-01-16T19:22:37Z")

</div>

Exactly!  
Do we have a timeline for this feature and can we also black box a module in the same way?
