Commit Graph

54 Commits

Author SHA1 Message Date
Edward Z. Yang
e6ec0efaf8 Apply UFMT to all non test/torch files (#106205)
Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/106205
Approved by: https://github.com/albanD
2023-07-29 02:56:24 +00:00
Justin Chu
4cc1745b13 [BE] f-stringify torch/ and scripts (#105538)
This PR is a follow up on the pyupgrade series to convert more strings to use f-strings using `flynt`.

- https://docs.python.org/3/reference/lexical_analysis.html#f-strings
- https://pypi.org/project/flynt/

Command used:

```
flynt torch/ -ll 120
flynt scripts/ -ll 120
flynt tools/ -ll 120
```

and excluded `collect_env.py`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/105538
Approved by: https://github.com/ezyang, https://github.com/malfet
2023-07-21 19:35:24 +00:00
Justin Chu
8a688277a2 [BE] Enable ruff's UP rules and autoformat dynamo / functorch and refs (#105432)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105432
Approved by: https://github.com/ezyang
2023-07-19 13:48:44 +00:00
Omkar Salpekar
ae1ed27756 [codemod][numpy] replace np.str with str (#103931)
Summary:
`np.str` is removed from numpy 1.20.0. It was an alias to builtin `str` and it's safe to do the replacement.

The whole changes is mechanical, generated using the following onliner:
```
fbgr -sl 'np\.str\b' | xargs perl -pi -e 's,\bnp\.str\b,str,g'
```

Test Plan: sandcastle

Differential Revision: D46586144

Pull Request resolved: https://github.com/pytorch/pytorch/pull/103931
Approved by: https://github.com/huydhn
2023-06-21 18:16:42 +00:00
Aaron Gokaslan
5471621497 [BE] Remove unnecessary dict comprehensions (#97116)
Removes unnecessary dict comprehensions that optimize creation of dicts from iterables

Pull Request resolved: https://github.com/pytorch/pytorch/pull/97116
Approved by: https://github.com/kit1980
2023-03-20 00:56:57 +00:00
Xuehai Pan
5b1cedacde [BE] [2/3] Rewrite super() calls in functorch and torch (#94588)
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/94588
Approved by: https://github.com/ezyang, https://github.com/albanD
2023-02-10 21:16:33 +00:00
Xuehai Pan
a229b4526f [BE] Prefer dash over underscore in command-line options (#94505)
Preferring dash over underscore in command-line options. Add `--command-arg-name` to the argument parser. The old arguments with underscores `--command_arg_name` are kept for backward compatibility.

Both dashes and underscores are used in the PyTorch codebase. Some argument parsers only have dashes or only have underscores in arguments. For example, the `torchrun` utility for distributed training only accepts underscore arguments (e.g., `--master_port`). The dashes are more common in other command-line tools. And it looks to be the default choice in the Python standard library:

`argparse.BooleanOptionalAction`: 4a9dff0e5a/Lib/argparse.py (L893-L895)

```python
class BooleanOptionalAction(Action):
    def __init__(...):
            if option_string.startswith('--'):
                option_string = '--no-' + option_string[2:]
                _option_strings.append(option_string)
```

It adds `--no-argname`, not `--no_argname`. Also typing `_` need to press the shift or the caps-lock key than `-`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94505
Approved by: https://github.com/ezyang, https://github.com/seemethere
2023-02-09 20:16:49 +00:00
Nikita Shulga
fde220ca44 [BE] Get rid of six in caffe2 code (#93956)
Mostly `s/string_types/str/` `s/binary_types/bytes/` and `s/text_types/str/`
Also `y.extend([str(x) for x in foo])`->`y.extend(map(str, foo))`
As Python-2 is long dead

Pull Request resolved: https://github.com/pytorch/pytorch/pull/93956
Approved by: https://github.com/albanD, https://github.com/Skylion007
2023-02-02 22:13:37 +00:00
samdow
39524f20de [functorch] excise remaining functorch imports from examples (#91282)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/91282
Approved by: https://github.com/zou3519
2023-01-09 14:35:21 +00:00
samdow
071756c9cf [functorch] rewrite examples that use make_functional to use functional_call (#88851)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88851
Approved by: https://github.com/zou3519
2023-01-09 14:35:21 +00:00
samdow
162474d7fd [functorch] add new ensembling api, demonstrate in example (#88850)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/88850
Approved by: https://github.com/zou3519
2023-01-04 00:33:14 +00:00
Sergii Dymchenko
99bd8d12e1 Fix non-existing parameters in docstrings in misc places (#91121)
This should be the last continuation of https://github.com/pytorch/pytorch/pull/90505

Pull Request resolved: https://github.com/pytorch/pytorch/pull/91121
Approved by: https://github.com/clee2000
2022-12-20 02:01:37 +00:00
Philip Meier
bc73affdad prepare removal of deprecated functionality in torch.testing (#87969)
_Redo of #86586 with all BC breaking changes granularly placed into separate commits._

---

Per title. Deprecation happened on Feb 25, 2022 in c6f1bbc0ac, which made it into the 1.12 release. Since it is now 245 days later and the next release will be 1.14, the removals later in the stack comply with the [BC policy](https://github.com/pytorch/pytorch/wiki/PyTorch's-Python-Frontend-Backward-and-Forward-Compatibility-Policy#minimizing-the-disruption-of-bc-breaking-changes).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/87969
Approved by: https://github.com/mruberry
2022-11-02 14:04:48 +00:00
Kazuaki Ishizaki
a3d495bd4e Fix typos under functorch directory (#87663)
This PR fixes typos in `.md` and `.rst` files under functorch directory

Pull Request resolved: https://github.com/pytorch/pytorch/pull/87663
Approved by: https://github.com/kit1980
2022-10-25 21:50:02 +00:00
Richard Zou
5e5c319549 Move functorch python bindings to torch/csrc (#85426)
This moves functorch's python bindings to torch/csrc/functorch/init.cpp.
Coming next is the torchdim move. I didn't do torchdim yet because
moving functorch's python bindings unblocks some other things that I
want to do first.

Test Plan:
- tests
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85426
Approved by: https://github.com/ezyang
2022-09-22 18:47:12 +00:00
Sergii Dymchenko
591222f5d9 Fix use-dict-literal lint (#83718)
Fix use-dict-literal pylint suggestions by changing `dict()` to `{}`. This PR should do the change for every Python file except test/jit/test_list_dict.py, where I think the intent is to test the constructor.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83718
Approved by: https://github.com/albanD
2022-08-24 00:26:46 +00:00
Richard Zou
f42ed3f98f Turn on linting for functorch (#81987)
Test Plan:
- wait for CI
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81987
Approved by: https://github.com/samdow
2022-07-25 14:36:22 +00:00
Richard Zou
d02f085f70 [functorch] Align functorch's flake8 config with pytorch's (pytorch/functorch#963) 2022-07-21 13:41:37 -07:00
SP Liew
b9829fd397 [functorch] fix dp-sgd example (pytorch/functorch#873)
see [this issue](https://github.com/pytorch/functorch/issues/467)
2022-07-21 13:41:35 -07:00
Andre
1feff6bb69 [functorch] update compile example imports (pytorch/functorch#834) 2022-07-21 13:41:34 -07:00
Richard Zou
43ae23f5d4 [functorch] Remove erroneous files 2022-07-21 13:41:27 -07:00
Richard Zou
7095647db6 [functorch] Fix some lint issues (pytorch/functorch#606) 2022-07-21 13:41:26 -07:00
Samantha Andow
0af3636257 [functorch] Add Batch Norm module utilities to not track running stats (pytorch/functorch#505)
* adds converter and tests, show omniglot wrong

* fix example to use batch norm, test to use group norm
2022-07-21 13:41:25 -07:00
Richard Zou
db8cfb0aff [functorch] Purge some licenses 2022-07-21 13:41:22 -07:00
Richard Zou
10e383b907 [functorch] Excise prototype mentions (pytorch/functorch#478) 2022-07-21 13:41:21 -07:00
Samantha Andow
33cb1967c2 [functorch] fix small issues with examples (pytorch/functorch#464) 2022-07-21 13:41:21 -07:00
Sam Andow
75b08c9bef [functorch] update differential privacy example 2022-07-21 13:41:21 -07:00
Animesh Jain
9157be2b10 [functorch] Cleaning up TVM compiler integration (pytorch/functorch#405)
* Cleaning up TVM compiler integration

* Linters
2022-07-21 13:41:19 -07:00
vfdev
c94446a04d [functorch] Fixed python code formatting and added flake8 setup (pytorch/functorch#346)
* Fixed python code formatting and added flake8 setup

* Fixes config.yaml

* Added missing setup.cfg

* Removed flake8 job from circle ci and setup GHA

* More flake8 fixes

* Fixed test_conv2d

* Fixed failing flake8
2022-07-21 13:41:17 -07:00
samdow
b25d781d80 [functorch] cleanup unnecessary functions, examples 2022-07-21 13:41:10 -07:00
Bert Maher
033e7109a4 [functorch] Support buffers in compiled_module (pytorch/functorch#147)
* Support buffers in compiled_module

* Don't compute gradients for inputs that don't require grad

* Add a unit test for batchnorm

* Fix eager compilation tests that change requires_grad

* Create new args for tests without recompilation

* Enable some eager fusion opinfo tests that now work (because we stopped asking for unimplemented derivatives)
2022-07-21 13:41:06 -07:00
Horace He
90ad67843b [functorch] plumbed partition_fn through compiled_module 2022-07-21 13:41:05 -07:00
Bert Maher
acf0318fa3 [functorch] Remove some commented code (pytorch/functorch#146) 2022-07-21 13:41:05 -07:00
Bert Maher
53c9fdd24b [functorch] Introduce compiled_module for eager compilation of modules (pytorch/functorch#133)
* Introduce compiled_module for eager compilation of modules

* Make parameters work

Co-authored-by: Horace He <horacehe2007@yahoo.com>
2022-07-21 13:41:05 -07:00
Horace He
b23c9b907c [functorch] removed unnecessary note 2022-07-21 13:41:03 -07:00
Horace He
7e13e3c6f5 [functorch] added option to skip specialization cache 2022-07-21 13:41:03 -07:00
Horace He
c0afd464d1 [functorch] Cleaned up the tests 2022-07-21 13:41:03 -07:00
Horace He
d314e2f78b [functorch] stored some stuff 2022-07-21 13:41:03 -07:00
Horace He
5466ac5da3 [functorch] Update eager_fusion.py 2022-07-21 13:41:00 -07:00
Horace He
e8a5b3725b [functorch] fix example to work well :) 2022-07-21 13:40:59 -07:00
Horace He
1a2e538580 [functorch] Moved to Keops example 2022-07-21 13:40:59 -07:00
Horace He
9ca5ae86d0 [functorch] Added eager-mode fusion prototype 2022-07-21 13:40:59 -07:00
Richard Zou
b29e666ade [functorch] [BC-breaking] Update make_functional* (pytorch/functorch#52)
Updates make_functional to use the new improved variants. The new
variants are superior in every way so we're replacing the previous
variants with this.

If someone wants the older variants, they can be found at:
- make_functional_with_buffers_deprecated_v1
- make_functional_deprecated_v1
2022-07-21 13:40:55 -07:00
Richard Zou
fdcc680c9d [functorch] Update tests and examples to use make_functional*_v2
make_functional*_v2 is superior to the older make_functional. This PR
has all of our examples use it.

This PR also adds a "combine_state_for_ensemble(models)" API.

Coming soon: We're probably going to break BC on make_functional and
replace it with make_functional_v2. That's the nice thing about being a
prototype, we don't have to worry about BC too much.
2022-07-21 13:40:55 -07:00
Richard Zou
6877541cc1 [functorch] Add some citations 2022-07-21 13:40:54 -07:00
Richard Zou
b627d3516e [functorch] Citations 2022-07-21 13:40:54 -07:00
Richard Zou
c446037aa4 [functorch] Add LICENSE headers to code files 2022-07-21 13:40:54 -07:00
Richard Zou
a7f406ce58 [functorch] Quick attempt at hiding functional module init
Introduces a `functional_init` and `functional_init_with_buffers` that
lets one initialize an ensemble of modules more easily than before. This
was done in the sprit of make_functional: the API still looks awkward,
especially when buffers are involved.
2022-07-21 13:40:53 -07:00
Richard Zou
9e6201db9a [functorch] lennard-jones example and test 2022-07-21 13:40:53 -07:00
Horace He
ac017463e0 [functorch] Added a simple function example 2022-07-21 13:40:52 -07:00