Sequential.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --- /usr/local/lib/python3.5/dist-packages/torch/nn/modules/container.py
  2. +++ /usr/local/lib/python3.5/dist-packages/torch/nn/modules/container.py
  3. @@ -22,15 +22,7 @@
  4. ]))
  5. """
  6. - @overload
  7. - def __init__(self, *args: Module) -> None:
  8. - ...
  9. -
  10. - @overload
  11. - def __init__(self, arg: 'OrderedDict[str, Module]') -> None:
  12. - ...
  13. -
  14. - def __init__(self, *args: Any):
  15. + def __init__(self, *args):
  16. super(Sequential, self).__init__()
  17. if len(args) == 1 and isinstance(args[0], OrderedDict):
  18. for key, module in args[0].items():
  19. @@ -48,18 +40,17 @@
  20. idx %= size
  21. return next(islice(iterator, idx, None))
  22. - @_copy_to_script_wrapper
  23. - def __getitem__(self: T, idx) -> T:
  24. + def __getitem__(self, idx):
  25. if isinstance(idx, slice):
  26. return self.__class__(OrderedDict(list(self._modules.items())[idx]))
  27. else:
  28. return self._get_item_by_idx(self._modules.values(), idx)
  29. - def __setitem__(self, idx: int, module: Module) -> None:
  30. + def __setitem__(self, idx, module):
  31. key = self._get_item_by_idx(self._modules.keys(), idx)
  32. return setattr(self, key, module)
  33. - def __delitem__(self, idx: Union[slice, int]) -> None:
  34. + def __delitem__(self, idx):
  35. if isinstance(idx, slice):
  36. for key in list(self._modules.keys())[idx]:
  37. delattr(self, key)
  38. @@ -67,26 +58,16 @@
  39. key = self._get_item_by_idx(self._modules.keys(), idx)
  40. delattr(self, key)
  41. - @_copy_to_script_wrapper
  42. - def __len__(self) -> int:
  43. + def __len__(self):
  44. return len(self._modules)
  45. - @_copy_to_script_wrapper
  46. def __dir__(self):
  47. keys = super(Sequential, self).__dir__()
  48. keys = [key for key in keys if not key.isdigit()]
  49. return keys
  50. - @_copy_to_script_wrapper
  51. - def __iter__(self) -> Iterator[Module]:
  52. - return iter(self._modules.values())
  53. -
  54. - # NB: We can't really type check this function as the type of input
  55. - # may change dynamically (as is tested in
  56. - # TestScript.test_sequential_intermediary_types). Cannot annotate
  57. - # with Any as TorchScript expects a more precise type
  58. def forward(self, input):
  59. - for module in self:
  60. + for module in self._modules.values():
  61. input = module(input)
  62. return input