Rate this Page

python.builtin#

dynamic_shape_round#

Note

Tags:python.builtin,torch.dynamic-shape

Support Level: NOT_SUPPORTED_YET

Original source code:

# mypy: allow-untyped-defsimporttorchfromtorch._export.db.caseimportSupportLevelfromtorch.exportimportDimclassDynamicShapeRound(torch.nn.Module):"""    Calling round on dynamic shapes is not supported.    """defforward(self,x):returnx[:round(x.shape[0]/2)]x=torch.randn(3,2)dim0_x=Dim("dim0_x")example_args=(x,)tags={"torch.dynamic-shape","python.builtin"}support_level=SupportLevel.NOT_SUPPORTED_YETdynamic_shapes={"x":{0:dim0_x}}model=DynamicShapeRound()torch.export.export(model,example_args,dynamic_shapes=dynamic_shapes)

Result:

Unsupported: Constraints violated (dim0_x)! For more information, run with TORCH_LOGS="+dynamic".

tensor_setattr#

Note

Tags:python.builtin

Support Level: SUPPORTED

Original source code:

# mypy: allow-untyped-defsimporttorchclassTensorSetattr(torch.nn.Module):"""    setattr() call onto tensors is not supported.    """defforward(self,x,attr):setattr(x,attr,torch.randn(3,2))returnx+4example_args=(torch.randn(3,2),"attr")tags={"python.builtin"}model=TensorSetattr()torch.export.export(model,example_args)

Result:

ExportedProgram:classGraphModule(torch.nn.Module):defforward(self,x:"f32[3, 2]",attr):randn:"f32[3, 2]"=torch.ops.aten.randn.default([3,2],device=device(type='cpu'),pin_memory=False);randn=Noneadd:"f32[3, 2]"=torch.ops.aten.add.Tensor(x,4);x=Nonereturn(add,)Graphsignature:# inputsx:USER_INPUTattr:USER_INPUT# outputsadd:USER_OUTPUTRangeconstraints:{}

type_reflection_method#

Note

Tags:python.builtin

Support Level: SUPPORTED

Original source code:

# mypy: allow-untyped-defsimporttorchclassA:@classmethoddeffunc(cls,x):return1+xclassTypeReflectionMethod(torch.nn.Module):"""    type() calls on custom objects followed by attribute accesses are not allowed    due to its overly dynamic nature.    """defforward(self,x):a=A()returntype(a).func(x)example_args=(torch.randn(3,4),)tags={"python.builtin"}model=TypeReflectionMethod()torch.export.export(model,example_args)

Result:

ExportedProgram:classGraphModule(torch.nn.Module):defforward(self,x:"f32[3, 4]"):add:"f32[3, 4]"=torch.ops.aten.add.Tensor(x,1);x=Nonereturn(add,)Graphsignature:# inputsx:USER_INPUT# outputsadd:USER_OUTPUTRangeconstraints:{}