---
title: thunder.transforms.MaterializationTransform
description: Materialize a model that can fit on a device only after transforms applied.
canonical: >-
  https://lightning.ai/docs/thunder/stable/api-reference/generated/thunder.transforms.MaterializationTransform
---
# thunder.transforms.MaterializationTransform {#thunder-transforms-materializationtransform}

### `class thunder.transforms.MaterializationTransform(device, *, init)` {#thunder.transforms.MaterializationTransform}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/transforms/materialization.py#L92-L172)

Bases: `Transform`

Materialize a model that can fit on a device only after transforms applied.

Parameters:

*   **device** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") | [`device`](https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch.device "(in PyTorch v2.15)")) – Device to host [`ThunderModule`](/docs/thunder/thunder#thunder.ThunderModule "thunder.core.module.ThunderModule") after materialization. The transform will annotate any unannotated parameters on the meta device as to be initialized on this device.
    
*   **device** ([_str_](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") _|_ [_torch.device_](https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch.device "(in PyTorch v2.15)")) –
    
*   **init** (_Callable__\[__\[_[_MaterializationTransform_](#thunder.transforms.MaterializationTransform "thunder.transforms.MaterializationTransform")_,_ [_ThunderModule_](/docs/thunder/thunder#thunder.ThunderModule "thunder.ThunderModule")_\]__,_ _None__\]_) –
    

Keyword Arguments:

**init** –

Post-processing callable applied to [`ThunderModule`](/docs/thunder/thunder#thunder.ThunderModule "thunder.core.module.ThunderModule") after materialization. possible values are obtained from

*   MaterializationTransform.init\_from\_original\_state\_dict(state\_dict) populate weights from a state\_dict from the untransformed module,
    
*   MaterializationTransform.init\_from\_transformed\_state\_dict(state\_dict) populate weights from a state\_dict from the transformed module,
    
*   MaterializationTransform.init\_from\_original\_module\_init() initialize using the weight initialization of the original module (reset\_parameters)
    

#### `__init__(device, *, init)` {#thunder.transforms.MaterializationTransform.__init__}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/transforms/materialization.py#L111-L118)

Parameters:

*   **device** ([_str_](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)") _|_ [_torch.device_](https://docs.pytorch.org/docs/stable/tensor_attributes.html#torch.device "(in PyTorch v2.15)")) –
    
*   **init** ([_Callable_](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable "(in Python v3.15)")_\[__\[_[_MaterializationTransform_](#thunder.transforms.MaterializationTransform "thunder.transforms.materialization.MaterializationTransform")_,_ [_ThunderModule_](/docs/thunder/thunder#thunder.ThunderModule "thunder.core.module.ThunderModule")_\]__,_ _None__\]_) –
    

Return type:

None

Methods

- [`__init__(device, *, init)`](#thunder.transforms.MaterializationTransform.__init__)
- `init_from_original_module_init()`
- `init_from_original_state_dict(state_dict)`
- `init_from_transformed_state_dict(state_dict)`
- `reverse_transform_state_dict_for_submodule(...)` — rtype:dict[str, Any]
- [`transform_module(model)`](#thunder.transforms.MaterializationTransform.transform_module) — Transforms the ThunderModule.
- `transform_state_dict_for_submodule(model, ...)` — Implement this to transform the state dict (mostly parameters and buffers) of a module, e.g.
- `transform_trace_post_optimization(...)` — transform_trace_post_optimization enables transforming computation trace after optimization pass.
- `transform_traces_pre_prologue(...)` — transform_traces_pre_prologue enables transforming prologue, computation and epilogue trace.

#### `transform_module(model)` {#thunder.transforms.MaterializationTransform.transform_module}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/transforms/materialization.py#L120-L148)

Transforms the ThunderModule. This is executed once on application of the transform

Parameters:

**model** ([_ThunderModule_](/docs/thunder/thunder#thunder.ThunderModule "thunder.core.module.ThunderModule")) –

---

**Navigation**

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