python.object-model
=======================
model_attr_mutation
^^^^^^^^^^^^^^^^^^^

.. note::

    Tags: :doc:`python.object-model <python.object-model>`

    Support Level: NOT_SUPPORTED_YET

Original source code:

.. code-block:: python

    import torch
    
    
    
    class ModelAttrMutation(torch.nn.Module):
        """
        Attribute mutation is not supported.
        """
    
        def __init__(self):
            super().__init__()
            self.attr_list = [torch.ones(3, 2), torch.ones(3, 2)]
    
        def recreate_list(self):
            return [torch.zeros(3, 2), torch.zeros(3, 2)]
    
        def forward(self, x):
            self.attr_list = self.recreate_list()
            return x.sum() + self.attr_list[0].sum()
    

Result:

.. code-block::

    AssertionError: Mutating module attribute attr_list during export.


optional_input
^^^^^^^^^^^^^^

.. note::

    Tags: :doc:`python.object-model <python.object-model>`

    Support Level: NOT_SUPPORTED_YET

Original source code:

.. code-block:: python

    import torch
    
    
    
    class OptionalInput(torch.nn.Module):
        """
        Tracing through optional input is not supported yet
        """
    
        def forward(self, x, y=torch.ones(2, 3)):
            if y is not None:
                return x + y
            return x
    

Result:

.. code-block::

    AssertionError: graph-captured input #2, of type <class 'torch.Tensor'>, is not among original inputs of types: (<class 'torch.Tensor'>)