mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Rewrite Python built-in class `super()` calls. Only non-semantic changes should be applied. - #94587 - #94588 - #94592 Also, methods with only a `super()` call are removed: ```diff class MyModule(nn.Module): - def __init__(self): - super().__init__() - def forward(self, ...): ... ``` Some cases that change the semantics should be kept unchanged. E.g.:f152a79be9/caffe2/python/net_printer.py (L184-L190)f152a79be9/test/test_jit_fuser_te.py (L2628-L2635)Pull Request resolved: https://github.com/pytorch/pytorch/pull/94592 Approved by: https://github.com/ezyang, https://github.com/seemethere
37 lines
707 B
Python
37 lines
707 B
Python
from typing import Any
|
|
|
|
import torch
|
|
|
|
|
|
@torch.jit.script
|
|
class MyScriptClass:
|
|
"""Intended to be scripted."""
|
|
|
|
def __init__(self, x):
|
|
self.foo = x
|
|
|
|
def set_foo(self, x):
|
|
self.foo = x
|
|
|
|
|
|
@torch.jit.script
|
|
def uses_script_class(x):
|
|
"""Intended to be scripted."""
|
|
foo = MyScriptClass(x)
|
|
return foo.foo
|
|
|
|
|
|
class IdListFeature:
|
|
def __init__(self):
|
|
self.id_list = torch.ones(1, 1)
|
|
|
|
def returns_self(self) -> "IdListFeature":
|
|
return IdListFeature()
|
|
|
|
|
|
class UsesIdListFeature(torch.nn.Module):
|
|
def forward(self, feature: Any):
|
|
if isinstance(feature, IdListFeature):
|
|
return feature.id_list
|
|
else:
|
|
return feature
|