---
title: thunder.torch._register_custom_op
description: Register custom_op()’ed function to Thunder.
canonical: >-
  https://lightning.ai/docs/thunder/stable/api-reference/generated/thunder.torch._register_custom_op
---
# thunder.torch._register_custom_op {#thunder-torch-register-custom-op}

### `thunder.torch._register_custom_op(custom_op)` {#thunder.torch._register_custom_op}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/torch/custom_op.py#L310-L398)

Register [`custom_op()`](https://docs.pytorch.org/docs/stable/library.html#torch.library.custom_op "(in PyTorch v2.15)")’ed function to Thunder.

[`torch.library.custom_op()`](https://docs.pytorch.org/docs/stable/library.html#torch.library.custom_op "(in PyTorch v2.15)") operators always have schema as per [https://docs.google.com/document/d/1\_W62p8WJOQQUzPsJYa7s701JXt0qf2OfLub2sbkHOaU/edit?tab=t.0#heading=h.aotf6sastysc](https://docs.google.com/document/d/1_W62p8WJOQQUzPsJYa7s701JXt0qf2OfLub2sbkHOaU/edit?tab=t.0#heading=h.aotf6sastysc) saying “Use torch.library.custom\_op to decorate a function to turn it into a custom operator. The function must be decorated with type annotations, and you must correctly annotate inputs that are being mutated.” An example schema is `my_lib::foo(Tensor a, Tensor b, float? c=None, str d="") -> Tensor`.

This function does three things: 1. Register `custom_op` as a new [`Symbol`](/docs/thunder/core/generated/thunder.core.symbol.Symbol#thunder.core.symbol.Symbol "thunder.core.symbol.Symbol") whose `fn` is `custom_op._opoverload` and `meta` is based on `custom_op._abstract_fn` 2. When `_setup_context_fn` and `_backward_fn` are defined, register augmented forward and backward through `thunder.core.transforms.register_augmented_forward()` and `thunder.core.transforms.register_backward()`.

Parameters:

*   **custom\_op** ([`CustomOpDef`](https://docs.pytorch.org/docs/stable/library.html#torch._library.custom_ops.CustomOpDef "(in PyTorch v2.15)")) – [`torch.library.custom_op()`](https://docs.pytorch.org/docs/stable/library.html#torch.library.custom_op "(in PyTorch v2.15)")’ed function. This is not `torch.ops.{namespace}.{name}`.
    
*   **custom\_op** (_CustomOpDef_) –
    

Returns:

A symbol representing the input `custom_op`.

Return type:

[`Symbol`](/docs/thunder/core/generated/thunder.core.symbol.Symbol#thunder.core.symbol.Symbol "thunder.core.symbol.Symbol")

---

**Navigation**

- Parent: [Generated](/docs/thunder/0.2.6/api-reference/generated.md)
