Rate this Page

python.object-model#

model_attr_mutation#

Note

Tags:python.object-model

Support Level: NOT_SUPPORTED_YET

Original source code:

# mypy: allow-untyped-defsimporttorchfromtorch._export.db.caseimportSupportLevelclassModelAttrMutation(torch.nn.Module):"""    Attribute mutation is not supported.    """def__init__(self)->None:super().__init__()self.attr_list=[torch.randn(3,2),torch.randn(3,2)]defrecreate_list(self):return[torch.zeros(3,2),torch.zeros(3,2)]defforward(self,x):self.attr_list=self.recreate_list()returnx.sum()+self.attr_list[0].sum()example_args=(torch.randn(3,2),)tags={"python.object-model"}support_level=SupportLevel.NOT_SUPPORTED_YETmodel=ModelAttrMutation()torch.export.export(model,example_args)

Result:

AssertionError:Mutatingmoduleattributeattr_listduringexport.

optional_input#

Note

Tags:python.object-model

Support Level: NOT_SUPPORTED_YET

Original source code:

# mypy: allow-untyped-defsimporttorchfromtorch._export.db.caseimportSupportLevelclassOptionalInput(torch.nn.Module):"""    Tracing through optional input is not supported yet    """defforward(self,x,y=torch.randn(2,3)):ifyisnotNone:returnx+yreturnxexample_args=(torch.randn(2,3),)tags={"python.object-model"}support_level=SupportLevel.NOT_SUPPORTED_YETmodel=OptionalInput()torch.export.export(model,example_args)

Result:

Unsupported:Tracingthroughoptionalinputisnotsupportedyet