Commit Graph

247 Commits

Author SHA1 Message Date
1aa3cbb83b Use weakref.proxy when saving module to internal dictionaries to not increase refcount (#76435)
Fixes #76434

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76435
Approved by: https://github.com/jbschlosser
2022-05-11 18:40:59 +00:00
87e543da9b Add load_state_dict error message for non-dicts (#77197)
Fixes #76886
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77197
Approved by: https://github.com/jbschlosser
2022-05-10 22:11:51 +00:00
56bed0dcfe Load state dict post hook
Implements `register_load_state_dict_post_hook` API as discussed in https://github.com/pytorch/pytorch/issues/75287.

Unittests cover:
- Ensuring hooks are called with the correct module
- Hook is called with `IncompatibleKeys` field
- If hook modifies this, load_state_dict returns the modified result

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76823
Approved by: https://github.com/albanD
2022-05-05 19:27:05 +00:00
b8776e143f Fix false DeprecationWarning in Module.state_dict
Fixes #75404

TODO:
- [x] add tests
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75507
Approved by: https://github.com/jbschlosser
2022-05-04 20:08:23 +00:00
fb0f285638 [lint] upgrade mypy to latest version
Fixes https://github.com/pytorch/pytorch/issues/75927.

Had to fix some bugs and add some ignores.

To check if clean:
```
lintrunner --paths-cmd='git grep -Il .' --take MYPY,MYPYSTRICT
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76753

Approved by: https://github.com/malfet
2022-05-03 20:51:34 +00:00
3d7428d9ac Revert "[lint] upgrade mypy to latest version"
This reverts commit 9bf18aab94943f5352604a39340ad57ad4d0c5a4.

Reverted https://github.com/pytorch/pytorch/pull/76753 on behalf of https://github.com/suo
2022-05-03 20:01:18 +00:00
9bf18aab94 [lint] upgrade mypy to latest version
Fixes https://github.com/pytorch/pytorch/issues/75927.

Had to fix some bugs and add some ignores.

To check if clean:
```
lintrunner --paths-cmd='git grep -Il .' --take MYPY,MYPYSTRICT
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76753

Approved by: https://github.com/malfet
2022-05-03 19:43:28 +00:00
9fae0762b0 fix typing in Module.state_dict and load_state_dict
Fixes #72707

Pull Request resolved: https://github.com/pytorch/pytorch/pull/73483
Approved by: https://github.com/albanD, https://github.com/jbschlosser
2022-05-02 17:27:54 +00:00
43cc726c22 updated _forward_unim. to include descriptive error
Fixes #74303

Added error description for an unimplemented forward function.

_Using torch summary to test the functionality_
Before:
![image](https://user-images.githubusercontent.com/34219451/161395955-39947ea0-3664-41b6-9ed7-0af58c3c8901.png)

After:
![image](https://user-images.githubusercontent.com/34219451/161395910-71d2078d-268a-4b1f-88af-33dba6dff6a7.png)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75148
Approved by: https://github.com/albanD
2022-04-08 20:22:47 +00:00
ce9e27a0fc Add new keys for Graphcore IPU (DispatchKey / Backend / DeviceType)
We need a key to register our out of tree backend: https://github.com/graphcore/poptorch
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74763
Approved by: https://github.com/bdhirsh
2022-04-07 17:18:45 +00:00
21a82fb519 Make torch.nn importable on Python-3.7.0
As `typing.OrderedDict` were introduced by Python-3.7.2+, see
https://docs.python.org/3.10/library/typing.html#typing.OrderedDict

Fixes #74087

Pull Request resolved: https://github.com/pytorch/pytorch/pull/74211
Approved by: https://github.com/suo, https://github.com/janeyx99
2022-03-15 06:12:42 +00:00
97ade8c64c Back out "fix: nn.Module allowing for expected Mixin MRO"
Summary:
Original commit changeset: 54741d983477

Original Phabricator Diff: D34822179

(Note: this ignores all push blocking failures!)

Test Plan: good_testplan

Reviewed By: osalpekar

Differential Revision: D34866030

fbshipit-source-id: 852182b90634873e51634228c33adbb72c5111c7
(cherry picked from commit 28f9a000c06f9c8e6477f369407036c9e54aec27)
2022-03-14 17:39:24 +00:00
1ac519e6b5 fix: nn.Module allowing for expected Mixin MRO
## Description

This pull request solves #74036

## How Functionality Changes Were Tested

Running:
```
from torch import nn

class A:
    def __init__(self):
        super().__init__()
        self.a = True

class B(A, nn.Module):
    def __init__(self):
        super().__init__()
        self.b = True

class C(nn.Module, A):
    def __init__(self):
        super().__init__()
        self.c = True

b = B()
c = C()

print(b.b)
print(b.a)

print(c.c)
print(c.a)
```

- ### Results - Before:
  ```
  >>> from torch import nn
  >>>
  >>>
  >>> class A:
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.a = True
  ...
  >>>
  >>> class B(A, nn.Module):
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.b = True
  ...
  >>>
  >>> class C(nn.Module, A):
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.c = True
  ...
  >>>
  >>> b = B()
  >>> c = C()
  >>>
  >>> print(b.b)
  True
  >>> print(b.a)
  True
  >>>
  >>> print(c.c)
  True
  >>> print(c.a)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/pytorch/torch/nn/modules/module.py", line 1188, in __getattr__
      raise AttributeError("'{}' object has no attribute '{}'".format(
  AttributeError: 'C' object has no attribute 'a'
  ```

- ### Results - After:
  ```
  >>> from torch import nn
  >>>
  >>>
  >>> class A:
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.a = True
  ...
  >>>
  >>> class B(A, nn.Module):
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.b = True
  ...
  >>>
  >>> class C(nn.Module, A):
  ...     def __init__(self):
  ...         super().__init__()
  ...         self.c = True
  ...
  >>>
  >>> b = B()
  >>> c = C()
  >>>
  >>> print(b.b)
  True
  >>> print(b.a)
  True
  >>>
  >>> print(c.c)
  True
  >>> print(c.a)
  True
  ```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/74096
Approved by: https://github.com/albanD
2022-03-11 15:32:05 +00:00
3c45fc8e20 Fix URL for creating github issues
Minor typos for the URL that allows users to create new issues on PyTorch's GH issues page
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73411
2022-02-25 16:19:03 +00:00
9d6639abcd Fix nn.Module.state_dict() (#72780)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/72778

TODO
- [x] Waiting for a conclusion from discussion in the issue.
- [x] Still bugs in handling misplaced args. Need a re-design to cover all corner cases.

TODO changes
- [x] Put deprecated signature to the second.
- [x] Change to kwargs, positional deprecated
- [x] `DeprecationWarning` add comment on why not use it
- [x] Remove unnecessary comments.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/72780

Reviewed By: george-qi

Differential Revision: D34398656

Pulled By: albanD

fbshipit-source-id: e8f2708e3dfd925ff354e098a66905f9775f4e0a
(cherry picked from commit 7f8eaf05fc48b333d22a07af57a7024b8b9ec6bf)
2022-02-23 22:32:06 +00:00
af3ca50291 Fixed docstring typo for nn.Module.get_submodule (#73018)
Summary:
Description:
- Fixed docstring typo for nn.Module.get_submodule

otherwise output is invisible: https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_submodule

Pull Request resolved: https://github.com/pytorch/pytorch/pull/73018

Reviewed By: davidberard98

Differential Revision: D34310091

Pulled By: jbschlosser

fbshipit-source-id: e35aef2b7479bdd81fb6b7ddd203bd71798769e1
(cherry picked from commit e4944e1f8e5779667ed98f1278150c5d46773835)
2022-02-17 22:40:18 +00:00
352eeb2ef9 doc fix nn.Module: docstring should come after class variable (#72912)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/72862

Pull Request resolved: https://github.com/pytorch/pytorch/pull/72912

Reviewed By: cpuhrsch

Differential Revision: D34286017

Pulled By: jbschlosser

fbshipit-source-id: d172f7600e7f66c30187996ee42c72bf273643cc
(cherry picked from commit d9f9b5b4180fb1554eaca675a20661b979da2234)
2022-02-16 23:10:38 +00:00
8bf3179f6e #71946 Remove Python 3.6 references (#72211)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/71946

This commit removes some bits of code that were hard coded for Python 3.6 support from the `.circleci` and `torch` folders. It should only be merged if https://github.com/pytorch/pytorch/issues/66462 is complete.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/72211

Reviewed By: dagitses, seemethere

Differential Revision: D33982604

Pulled By: musebc

fbshipit-source-id: 8f453bf9909df615addd59538adb369c65484044
(cherry picked from commit 944a9970fe68a40999b5c8af731e632c28fd15c5)
2022-02-08 03:46:20 +00:00
7cdbbfaee2 Revert D33716716: [pytorch][PR] Added remove_duplicate parameter to nn.Module
Test Plan: revert-hammer

Differential Revision:
D33716716 (7e8217549f)

Original commit changeset: ff1ed9980bd1

Original Phabricator Diff: D33716716 (7e8217549f)

fbshipit-source-id: 91c3d9acc5bc731da716dd0d2485431f85f861c9
(cherry picked from commit c81d193bf0fccbffdc009255bc85d0c287c1e409)
2022-02-03 09:04:29 +00:00
7e8217549f Added remove_duplicate parameter to nn.Module (#39)
Summary:
Pull Request resolved: https://github.com/pytorch/torchrec/pull/39

Pull Request resolved: https://github.com/facebookresearch/torchrec/pull/6

This makes it so that shared parameters get their own entry in `named_parameters`.

More broadly, this makes it so that
```
params_and_buffers = {**mod.named_named_parameters(remove_duplicate=False), **mod.named_buffers(remove_duplicate=False)}
_stateless.functional_call(mod, params_and_buffers, args, kwargs)
```
is identical to calling the original module's forwards pass.

cc pietern mrshenli pritamdamania87 zhaojuanmao satgera rohan-varma gqchen aazzolini osalpekar jiayisuse SciPioneer H-Huang

Pull Request resolved: https://github.com/pytorch/pytorch/pull/71542

Reviewed By: jbschlosser, albanD

Differential Revision: D33716716

Pulled By: Chillee

fbshipit-source-id: ff1ed9980bd1a3f7ebaf695ee5e401202b543213
(cherry picked from commit d6e3ad3cd0c694886d4d15a38876835e01f68134)
2022-02-01 18:34:58 +00:00
0a2cdd18f3 nice error msg from load_state_dict for non-tensor value (#70596)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/67549

Pull Request resolved: https://github.com/pytorch/pytorch/pull/70596

Reviewed By: anjali411

Differential Revision: D33710750

Pulled By: jbschlosser

fbshipit-source-id: 870b5fafffcd005fd4fcd62f865542739c133805
(cherry picked from commit da374fbc58a61774632c6517d68ad56ecb82019e)
2022-01-21 22:02:13 +00:00
0460324b9b Fix docs rendering for nn.Module.named_modules() (#70491)
Summary:
The documentation rendering for nn.Module.named_modules() is a bit broken, see the description of the last argument [here](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.named_modules).

This PR fixes that.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/70491

Reviewed By: mikaylagawarecki

Differential Revision: D33349882

Pulled By: albanD

fbshipit-source-id: a46327c12e8114f7ef2055a8518c4ca9d186e669
2021-12-29 10:08:53 -08:00
3fe2ff800c Module docs update (#66909)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/37824

{F671745341}

Pull Request resolved: https://github.com/pytorch/pytorch/pull/66909

Reviewed By: anjali411

Differential Revision: D31782046

Pulled By: mikaylagawarecki

fbshipit-source-id: 009d2ea3c8a51a89786ef55bb9e88dc53aa8360f
2021-10-20 08:14:36 -07:00
7191dd2613 Update Module docstring for Python 3 (#65748)
Summary:
In Python 3, we can call `super()` without any arguments.

If I understand correctly, Python 2 is no longer supported by PyTorch, so we can change the documentation to be Python-3 only :)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/65748

Reviewed By: saketh-are

Differential Revision: D31246055

Pulled By: albanD

fbshipit-source-id: 3980def1a556d4bdfa391ea61cb2a65efa20df79
2021-09-29 13:40:15 -07:00
b80bdcc73b Add register_module alias to nn.Module (#65174)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/60397. I'm not sure how aliases are supposed to be implemented, but this is the most basic/direct way, IMO. As a side-effect, this implementation results in a "duplicate" doc entry, inheriting the one from `add_module`:

![monkey-patch](https://user-images.githubusercontent.com/7027770/133693137-8408d8e7-1f4f-436b-b176-57dda9bc3a32.png)

An alternative implementation could be:

```python
def register_module(self, name: str, module: Optional['Module']) -> None:
    r"""Alias for :func:`add_module`."""
    self.add_module(name, module)
```

which results in this documentation:

![image](https://user-images.githubusercontent.com/7027770/133693249-d969a71a-be44-489d-9633-4f38b44ab887.png)

Questions:
1. Should I replicate the tests? There are two for `add_module`: [test_add_module_raises_error_if_attr_exists](873255c6d9/test/test_nn.py (L1420-L1434)) and [test_add_module](873255c6d9/test/test_nn.py (L1837-L1855)).
2. This PR only adds `register_module` to `nn.Module`. There is an `add_module` in [`_RemoteModule`](https://github.com/pytorch/pytorch/blob/master/torch/distributed/nn/api/remote_module.py#L311-L312), which raises `NotSupported`, and there is another one in [`ConcreteModuleTypeBuilder`](873255c6d9/torch/_C/__init__.pyi.in (L468)), which means something else, I think. Should I do anything about them?

cc ngimel SsnL

Pull Request resolved: https://github.com/pytorch/pytorch/pull/65174

Reviewed By: soulitzer

Differential Revision: D31089717

Pulled By: jbschlosser

fbshipit-source-id: abd8d14a434fd8c7efa0bd8c242df56da33491e9
2021-09-22 16:37:28 -07:00
544af391b5 Allow arbitrary objects in state_dicts (#62976)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/62094

Introduces functionality for adding arbitrary objects to module state_dicts. To take advantage of this, the following functions can be defined on a module:
* `get_extra_state(self) -> dict` - Returns a dict defining any extra state this module wants to save
* `set_extra_state(self, state)` - Subsumes the given state within the module

In the details, a sub-dictionary is stored in the state_dict under the key `_extra_state` for each module that requires extra state.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62976

Reviewed By: heitorschueroff

Differential Revision: D30518657

Pulled By: jbschlosser

fbshipit-source-id: 5fb35ab8e3d36f35e3e96dcd4498f8c917d1f386
2021-08-24 19:06:14 -07:00
2d5b19f62b Update full backward hook doc with not-same-object note (#63245)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/61446

Pull Request resolved: https://github.com/pytorch/pytorch/pull/63245

Reviewed By: ejguan

Differential Revision: D30352656

Pulled By: albanD

fbshipit-source-id: 7000ecb54a80f2da968ec7600b98574b608578ae
2021-08-19 06:50:56 -07:00
9fdf7ec6a2 [docs] Update sphinx to 3.5.4 (#61601)
Summary:
Sphinx 4.x is out, but it seems that requires many more changes to
adopt. So instead use the latest version of 3.x, which includes
several nice features.

* Add some noindex directives to deal with warnings that would otherwise
  be triggered by this change due to conflicts between the docstrings
  declaring a function and the autodoc extension declaring the
  same function.
* Update distributions.utils.lazy_property to make it look like a
  regular property when sphinx autodoc inspects classes.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/61601

Reviewed By: ejguan

Differential Revision: D29801876

Pulled By: albanD

fbshipit-source-id: 544d2434a15ceb77bff236e934dbd8e4dbd9d160
2021-07-30 06:23:10 -07:00
cac4aa71ca Provide option to pass module instance to _load_state_dict_pre_hooks. (#62070)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/62070

We have a custom Tensor:
https://github.com/pytorch/pytorch/blob/master/torch/distributed/_sharded_tensor/api.py#L67,
which doesn't show up in state_dict for the module. This was resolved by
using the _register_state_dict_hook:
https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/module.py#L1196
to parse and add custom tensors to state_dict.

However, the problem is during load time  _register_load_state_dict_pre_hook:
https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/module.py#L1272,
does not pass in the module instance and as a result, a ShardedTensor in the
state_dict cannot be appropriately added to a module at load time.

To resolve this issue, in this PR I've enhanced this hook to support two
variations, one which passes in the module instance (for the problem described
above) and one is the previous version for BC reasons.
ghstack-source-id: 134541391

Test Plan:
1) unit tests
2) waitforbuildbot

Reviewed By: jbschlosser

Differential Revision: D29867142

fbshipit-source-id: bcb136ff51eedd0b508cfb419e8b8a6b7d95539c
2021-07-28 19:22:47 -07:00
414537ac99 DOC Fixes link in register_module_backward_hook (#61999)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/61580

Pull Request resolved: https://github.com/pytorch/pytorch/pull/61999

Reviewed By: saketh-are

Differential Revision: D29847397

Pulled By: albanD

fbshipit-source-id: 3d9e1a5abac82d658b4f1746ace73e2fecb41725
2021-07-22 14:29:40 -07:00
4e94e84f65 Type annotate torch.nn.Module ctor (#61334)
Summary:
Annotate generic types
Fix some type violations
Override `_modules` and `_parameters` in `Sequential`, `ModuleList`, `ModuleDict`, etc

Fixes https://github.com/pytorch/pytorch/issues/45497

Pull Request resolved: https://github.com/pytorch/pytorch/pull/61334

Reviewed By: albanD

Differential Revision: D29579533

Pulled By: malfet

fbshipit-source-id: 5cd8ca918b260ca35cfdd873dee8851d39d17de2
2021-07-16 13:59:06 -07:00
aa01a7a61c Fix for get_buffer(): check buffers by name instead of value (#61429)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/61242

Previous code was wrongly checking if a tensor is a buffer in a module by comparing values; fix compares names instead.
Docs need some updating as well- current plan is to bump that to a separate PR, but I'm happy to do it here as well if preferred.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/61429

Reviewed By: gchanan

Differential Revision: D29712341

Pulled By: jbschlosser

fbshipit-source-id: 41f29ab746505e60f13de42a9053a6770a3aac22
2021-07-15 09:55:09 -07:00
f0316ec0b6 Revert D24068202: [pytorch][PR] Add typing return value to init in nn.Module
Test Plan: revert-hammer

Differential Revision:
D24068202 (506397a809)

Original commit changeset: 4cd9b6ca12b5

fbshipit-source-id: f45fcf7ee6ee9198ed6f3f34956ce68a64378c32
2021-07-06 22:15:31 -07:00
506397a809 Add typing return value to init in nn.Module (#45654)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/45497

Pull Request resolved: https://github.com/pytorch/pytorch/pull/45654

Reviewed By: driazati

Differential Revision: D24068202

Pulled By: malfet

fbshipit-source-id: 4cd9b6ca12b531311302e3cdeeab39bc45d86c94
2021-07-06 17:09:30 -07:00
ad69e2fd11 [torch] Module fix on the support of LazyModule on bug #60132 (#60517)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/60517

This is to fix the module support on lazymodulefixin on the bug issue #60132
Check the link: https://github.com/pytorch/pytorch/issues/60132

We will have to update lazy_extension given the dependency on module.py and update the unit test as well.

Test Plan:
Unit test passes

torchrec test passes

Reviewed By: albanD

Differential Revision: D29274068

fbshipit-source-id: 1c20f7f0556e08dc1941457ed20c290868346980
2021-06-25 16:20:19 -07:00
4e347f1242 [docs] Fix backticks in docs (#60474)
Summary:
There is a very common error when writing docs: One forgets to write a matching `` ` ``, and something like ``:attr:`x`` is rendered in the docs. This PR fixes most (all?) of these errors (and a few others).

I found these running ``grep -r ">[^#<][^<]*\`"`` on the `docs/build/html/generated` folder. The regex finds an HTML tag that does not start with `#` (as python comments in example code may contain backticks) and that contains a backtick in the rendered HTML.

This regex has not given any false positive in the current codebase, so I am inclined to suggest that we should add this check to the CI. Would this be possible / reasonable / easy to do malfet ?

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60474

Reviewed By: mrshenli

Differential Revision: D29309633

Pulled By: albanD

fbshipit-source-id: 9621e0e9f87590cea060dd084fa367442b6bd046
2021-06-24 06:27:41 -07:00
6d1b4642f0 DOC Describes parameters/buffers registered as None in load_state_dict (#60549)
Summary:
Related to https://github.com/pytorch/pytorch/issues/8104

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60549

Reviewed By: VitalyFedyunin

Differential Revision: D29343732

Pulled By: jbschlosser

fbshipit-source-id: ef5ba3094c8eaf2f9c8efeba6a9d9ab52ebf8b2c
2021-06-23 20:15:22 -07:00
7e032f18cf DOC Describes behavior for None in module.register_* (#60125)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/45834

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60125

Reviewed By: zou3519

Differential Revision: D29196138

Pulled By: jbschlosser

fbshipit-source-id: af736c0d66005ec33412860f00b233a5d2922137
2021-06-17 19:18:23 -07:00
8af6281201 DOC Adds register_module_full_backward_hook into docs (#58954)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/54443

Adds `register_module_full_backward_hook` into the index so it is rendered in the html docs.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/58954

Reviewed By: ngimel

Differential Revision: D28801816

Pulled By: jbschlosser

fbshipit-source-id: a2e737fe983e5d7e4e26d7639183bca34b571cb8
2021-06-01 15:47:10 -07:00
5f1117226f DOC Update register_buffer/parameter docstring explaining None (#59015)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/40977

Pull Request resolved: https://github.com/pytorch/pytorch/pull/59015

Reviewed By: ngimel

Differential Revision: D28797948

Pulled By: jbschlosser

fbshipit-source-id: 3bf60af5c1cfc5f1786b4975b48f093391374503
2021-06-01 13:55:07 -07:00
a7a5992d7d Add no-grad inference mode note (#58513)
Summary:
Adds a note explaining the difference between several often conflated mechanisms in the autograd note
Also adds a link to this note from the docs in `grad_mode` and `nn.module`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/58513

Reviewed By: gchanan

Differential Revision: D28651129

Pulled By: soulitzer

fbshipit-source-id: af9eb1749b641fc1b632815634eea36bf7979156
2021-05-25 13:06:54 -07:00
ee93a348de ENH Raises nicer error when calling module.train with invalid modes (#58247)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/46763

Pull Request resolved: https://github.com/pytorch/pytorch/pull/58247

Reviewed By: ejguan

Differential Revision: D28418080

Pulled By: albanD

fbshipit-source-id: fef8f4f641ef75e801ed8b8d04c4016579aea8b0
2021-05-17 05:57:18 -07:00
452569dffb cfloat and cdouble functions (#58137)
Summary:
This adds the methods `Tensor.cfloat()` and `Tensor.cdouble()`.

I was not able to find the tests for `.float()` functions. I'd be happy to add similar tests for these functions  once someone points me to them.

Fixes https://github.com/pytorch/pytorch/issues/56014

Pull Request resolved: https://github.com/pytorch/pytorch/pull/58137

Reviewed By: ejguan

Differential Revision: D28412288

Pulled By: anjali411

fbshipit-source-id: ff3653cb3516bcb3d26a97b9ec3d314f1f42f83d
2021-05-13 21:13:37 -07:00
f7fba854bf Implement module.to_empty() (#56610)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/54600

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56610

Reviewed By: malfet

Differential Revision: D27921653

Pulled By: jbschlosser

fbshipit-source-id: 10734b3eaa5b84bb4ba6eeba1043cfc8bb570a17
2021-04-27 06:19:54 -07:00
f2acdff73d DOC: Add note to mutating methods (#56877)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/56243 by adding a note to mutating functions not following the trailing `_` convention in `torch/nn/modules/module.py`

I can also raise separate PRs for other files, if needed

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56877

Reviewed By: ezyang

Differential Revision: D28008856

Pulled By: jbschlosser

fbshipit-source-id: 63bfca0df05e49fceadd3167b1427dcb5542206a
2021-04-27 06:16:56 -07:00
75024e228c Add lint for unqualified type: ignore (#56290)
Summary:
The other half of https://github.com/pytorch/pytorch/issues/56272.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56290

Test Plan:
CI should pass on the tip of this PR, and we know that the lint works because the following CI runs (before this PR was finished) failed:

- https://github.com/pytorch/pytorch/runs/2384511062
- https://github.com/pytorch/pytorch/actions/runs/765036024

Reviewed By: seemethere

Differential Revision: D27867219

Pulled By: samestep

fbshipit-source-id: e648f07b6822867e70833e23ddafe7fb7eaca235
2021-04-21 08:07:23 -07:00
0a541e23e1 [nn] Add allow_duplicate option for named_modules (#54812)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54812

Needed for quantization since different attribute might refer to the same module instance

Test Plan: Imported from OSS

Reviewed By: vkuzo

Differential Revision: D27408376

fbshipit-source-id: cada85c4a1772d3dd9502c3f6f9a56d690d527e7
2021-04-16 01:26:16 -07:00
d33829f844 Fix type annotations for state_dict() override (#55704)
Summary:
Change annotation to OrderedDict, but stringify it to stay compatible with Python-3.6

Fixes https://github.com/pytorch/pytorch/issues/55302

Pull Request resolved: https://github.com/pytorch/pytorch/pull/55704

Reviewed By: walterddr

Differential Revision: D27686011

Pulled By: malfet

fbshipit-source-id: 3a8dedf33f38d86767ebd4e8a1a8abfe850b375a
2021-04-09 17:48:12 -07:00
55d45458bd [cuDNN] Enable Conv3d channels_last_3d (#48430)
Summary:
This PR adds the functionality to use channals_last_3d, aka, NDHWC, in Conv3d. It's only enabled when cuDNN version is greater than or equal to 8.0.5.

Todo:

- [x] add memory_format test
- [x]  add random shapes functionality test

Close https://github.com/pytorch/pytorch/pull/52547

Pull Request resolved: https://github.com/pytorch/pytorch/pull/48430

Reviewed By: mrshenli

Differential Revision: D27641452

Pulled By: ezyang

fbshipit-source-id: 0e98957cf30c50c3390903d307dd43bdafd28880
2021-04-09 07:56:49 -07:00
8c798e0622 Forbid trailing whitespace (#53406)
Summary:
Context: https://github.com/pytorch/pytorch/pull/53299#discussion_r587882857

These are the only hand-written parts of this diff:
- the addition to `.github/workflows/lint.yml`
- the file endings changed in these four files (to appease FB-internal land-blocking lints):
  - `GLOSSARY.md`
  - `aten/src/ATen/core/op_registration/README.md`
  - `scripts/README.md`
  - `torch/csrc/jit/codegen/fuser/README.md`

The rest was generated by running this command (on macOS):
```
git grep -I -l ' $' -- . ':(exclude)**/contrib/**' ':(exclude)third_party' | xargs gsed -i 's/ *$//'
```

I looked over the auto-generated changes and didn't see anything that looked problematic.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/53406

Test Plan:
This run (after adding the lint but before removing existing trailing spaces) failed:
- https://github.com/pytorch/pytorch/runs/2043032377

This run (on the tip of this PR) succeeded:
- https://github.com/pytorch/pytorch/runs/2043296348

Reviewed By: walterddr, seemethere

Differential Revision: D26856620

Pulled By: samestep

fbshipit-source-id: 3f0de7f7c2e4b0f1c089eac9b5085a58dd7e0d97
2021-03-05 17:22:55 -08:00