---
title: thunder.core.trace.TraceCtx
description: Trace representing fn.
canonical: >-
  https://lightning.ai/docs/thunder/stable/api-reference/generated/thunder.core.trace.TraceCtx
---
# thunder.core.trace.TraceCtx {#thunder-core-trace-tracectx}

### `class thunder.core.trace.TraceCtx(fn=None)` {#thunder.core.trace.TraceCtx}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py#L46-L514)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object "(in Python v3.15)")

Trace representing `fn`.

Parameters:

*   **fn** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable "(in Python v3.15)")\]) – Callable to represent.
    
*   **fn** (_None_ _|_ _Callable_) –
    

#### `fn` {#thunder.core.trace.TraceCtx.fn}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py)

Callable to represent. It’s either a callable written with pytorch functions or [`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)").

Type:

Callable | None

#### `args` {#thunder.core.trace.TraceCtx.args}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py)

Arguments of `fn`. Elements are proxified, e.g., [`torch.Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)") is converted to [`TensorProxy`](/docs/thunder/0.2.6/api-reference/generated/thunder.core.proxies.TensorProxy.md#thunder.core.proxies.TensorProxy "thunder.core.proxies.TensorProxy").

Type:

Any

#### `kwargs` {#thunder.core.trace.TraceCtx.kwargs}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py)

Keyword arguments of `fn`. Values are converted to `Proxy` if possible.

Type:

[dict](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[str](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), Any\]

#### `bound_symbols` {#thunder.core.trace.TraceCtx.bound_symbols}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py)

Each [`BoundSymbol`](/docs/thunder/0.2.6/api-reference/generated/thunder.core.symbol.BoundSymbol.md#thunder.core.symbol.BoundSymbol "thunder.core.symbol.BoundSymbol") represents one line of trace.

Type:

[list](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[BoundSymbol](/docs/thunder/0.2.6/api-reference/generated/thunder.core.symbol.BoundSymbol.md#thunder.core.symbol.BoundSymbol "thunder.core.symbol.BoundSymbol")\]

#### `scopes` {#thunder.core.trace.TraceCtx.scopes}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py)

In most cases, same as `[self.bound_symbols]`. Direct modification of this attribute would provide better flexibility to trace transformation as in [`insert_inplace()`](/docs/thunder/0.2.6/api-reference/generated/thunder.core.transforms.insert_inplace.md#thunder.core.transforms.insert_inplace "thunder.core.transforms.insert_inplace") and [`replace_inplace()`](/docs/thunder/0.2.6/api-reference/generated/thunder.core.transforms.replace_inplace.md#thunder.core.transforms.replace_inplace "thunder.core.transforms.replace_inplace"). Also [\[tutorial\] How to Implement CPU Offloading as Trace Transform](https://lightning-thunder.readthedocs.io/en/latest/notebooks/writing_a_trace_transform_cpu_offloading.html) would be a great read.

Type:

[list](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[list](https://docs.python.org/3/builtins/stdtypes.html#list "(in Python v3.15)")\[[BoundSymbol](/docs/thunder/0.2.6/api-reference/generated/thunder.core.symbol.BoundSymbol.md#thunder.core.symbol.BoundSymbol "thunder.core.symbol.BoundSymbol")\]\]

#### `__init__(fn=None)` {#thunder.core.trace.TraceCtx.__init__}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/trace.py#L69-L115)

Parameters:

**fn** ([_Optional_](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")_\[_[_Callable_](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable "(in Python v3.15)")_\]_) –

Methods

- [`__init__([fn])`](#thunder.core.trace.TraceCtx.__init__)
- `add_bound_symbol(bsym)` — rtype:None
- `add_name(name)` — rtype:None
- `add_object(x)` — rtype:ContextObject
- `get_provenance()` — rtype:Optional[TraceProvenance]
- `has_name(name)` — rtype:bool
- `is_constant(x)` — rtype:bool
- `make_name([name, prefix])` — rtype:str
- `make_object_name(x)` — rtype:str
- `mark_complete()` — rtype:None
- `peek_scope()` — rtype:Optional[list]
- `pop_scope()` — rtype:list
- `post_unpack(fn)` — rtype:None
- `push_scope(scope)` — rtype:None
- `python(*[, print_depth, include_decorators])` — rtype:str
- `python_callable(*[, global_dicts])` — rtype:Callable
- `python_ctx()` — rtype:dict
- `save_trace(filename)` — rtype:None
- `set_current_source_location(filename, positions)`
- `set_provenance(provenance)` — rtype:None
- `siginfo()` — rtype:SigInfo
- `unpacked()` — rtype:None
- `unpacking()` — rtype:None

Attributes

- [`bound_symbols`](#thunder.core.trace.TraceCtx.bound_symbols)
- `output`
- `tags`

---

**Navigation**

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