34 Commits

Author SHA1 Message Date
758a0a88a2 [BE][Easy] enable ruff rule PIE790: unnecessary pass statement (#133200)
This PR removes unnecessary `pass` statement. This is semanticly safe because the bytecode for the Python code does not change.

Note that if there is a docstring in the function, a empty function does not need a `pass` statement as placeholder.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/133200
Approved by: https://github.com/malfet, https://github.com/eqy, https://github.com/kit1980
2024-08-15 15:50:19 +00:00
73e1455327 [BE] Enable ruff's UP rules and autoformat test/ (#105434)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105434
Approved by: https://github.com/albanD
2023-07-19 20:36:06 +00:00
429a80dded [NNC] Lowering function generates the output buffer with the specified stride (#76529)
Summary:
Pass stride information to lowering function to generate the output bufer with proper memory layout.

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

Reviewed By: ZolotukhinM

Differential Revision: D36116712

Pulled By: IvanKobzarev

fbshipit-source-id: d3901f756b3710ecce172d6db3ecb0b7c12fb929
(cherry picked from commit b6cd53c91c01db36ea0e99167dc0ce0ae1d3aa23)
2022-05-04 20:04:22 +00:00
1d55518198 Revert "[nnc] Strides to Tensor (#72962)"
This reverts commit 939060925f28c9498da42225f216d838e1f7f4ca.

Fixes https://github.com/pytorch/vision/issues/5873

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76332
Approved by: https://github.com/seemethere
2022-04-25 19:50:00 +00:00
939060925f [nnc] Strides to Tensor (#72962)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/72962

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM, cpuhrsch

Differential Revision: D34589306

Pulled By: IvanKobzarev

fbshipit-source-id: ecee5249760ecc0c8b2edb1842b90218899bc944
(cherry picked from commit 9e310c4c67389da30da89126d838ffe3864aba6f)
2022-04-23 19:35:15 +00:00
320e5a8268 Revert D34808051: [tensorexpr] Enabled aten::stack in the fuser pass with static shapes
Test Plan: revert-hammer

Differential Revision:
D34808051

Original commit changeset: 213e2ffdf87f

Original Phabricator Diff: D34808051

fbshipit-source-id: b618daeb346f784e8ab9525040edcb4a30a39613
(cherry picked from commit e47b973cba5c95e9410f8aecdfd5619de6d4be7c)
2022-03-31 04:25:43 +00:00
90c3699cc8 [tensorexpr] Enabled aten::stack in the fuser pass with static shapes (#74077)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/74077

Test Plan: Imported from OSS

Reviewed By: gchanan

Differential Revision: D34808051

Pulled By: huiguoo

fbshipit-source-id: 213e2ffdf87fb1a74104037cea7ef25e4bfd4307
(cherry picked from commit ad9e84842e5b47eda845827d325b08ba361a8286)
2022-03-31 04:25:43 +00:00
1855b14922 [TensorExpr] Delet DimArg class. (#72390)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72390

This class didn't add much value and only caused more boilerplate code.
This change removes the class and updates all the use cases with
uses of `ExprHandle`.

A side effect of this change is different names in loop variables, which
caused massive mechanical changes in our tests.

Test Plan: Imported from OSS

Reviewed By: navahgar

Differential Revision: D34030296

Pulled By: ZolotukhinM

fbshipit-source-id: 2ba4e313506a43ab129a10d99e72b638b7d40108
(cherry picked from commit c2ec46a0587cafd4e915c5bf1e0dc0b5d244e8d5)
2022-02-11 01:21:59 +00:00
8c7f4a0d0b [tensorexpr] check for index out of bounds in ir_eval (#68858)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68858

when executing with ir_eval, check for index out of bounds.

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D32657881

Pulled By: davidberard98

fbshipit-source-id: 62dd0f85bb182b34e9c9f795ff761081290f6922
2021-12-16 09:27:45 -08:00
49251d05ec [skip ci] Set test owners for NNC tests (#66833)
Summary:
Action following https://github.com/pytorch/pytorch/issues/66232

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

Reviewed By: albanD

Differential Revision: D31907812

Pulled By: janeyx99

fbshipit-source-id: 5e5013b4276fd208ac68d61cf787679799695602
2021-10-26 07:46:18 -07:00
59b28063b4 [NNC] Adding more python bindings for missing operators (#66612)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66612

For op authoring project, we want to expose the python bindings
to create Expr. These are the missing bindings.

Test Plan: Imported from OSS

Reviewed By: soulitzer

Differential Revision: D31667852

fbshipit-source-id: 6d3ff83a7676cfea391ab3ea60dde6874a64047a
2021-10-14 22:09:01 -07:00
199031c48e [TensorExpr] PyBinds: improve QoL of pybind users. (#64886)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/64886

Bind methods for implicit conversions and constructors to avoid
boilerplate code.

Differential Revision:
D30889193
D30889193

Test Plan: Imported from OSS

Reviewed By: jbschlosser

Pulled By: ZolotukhinM

fbshipit-source-id: 137c0c98f7f1576e1bb97c8de8a900b28407a30e
2021-09-14 00:21:28 -07:00
82ac3f108d [TensorExpr] Move 2 graph passes from kernel.cpp to graph_opt.cpp (#64828)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/64828

Also, make `removeUnusedSelfArgument` more consistent with other passes
by mutating the graph in-place rather than returning a copy.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D30870776

Pulled By: ZolotukhinM

fbshipit-source-id: 4873f01b013921143a5aa43746d655a2d8d620c9
2021-09-11 10:23:15 -07:00
f0d274294d [TensorExpr] Nuke KernelArena and KernelScope. (#63587)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63587

Now that there is no classes using KernelArena for memory management we
can remove it.

Differential Revision:
D30429115
D30429115

Test Plan: Imported from OSS

Reviewed By: navahgar

Pulled By: ZolotukhinM

fbshipit-source-id: 375f6f9294d27790645eeb7cb5a8e87047a57544
2021-08-24 00:32:16 -07:00
4e15a6f495 [TensorExpr] Switch Exprs and Stmt from kernel-arena to shared_ptr. (#63216)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63216

Currently there are three classes managed by KernelArena: Expr, Stmt,
and Tensor (and derived classes). KernelArena has been a long standing
painpoint for NNC devs and we're moving away from that memory management
model to ref-count based memory model (using shared_ptr). This commit
switches Expr and Stmt to shared_ptr and is the biggest change in this
transition. Later commits will detach Tensor from KernelArena and kill
the arena + scope altogether.

Differential Revision:
D30353195
D30353195

Test Plan: Imported from OSS

Reviewed By: navahgar

Pulled By: ZolotukhinM

fbshipit-source-id: 9575225ada3d0fb65087ae40435f3dfea4792cae
2021-08-24 00:32:11 -07:00
99203580a9 Updates internal assert_allclose callsites in favor of assert_close (#61841)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/61841

Redo of #60863.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D30408145

Pulled By: mruberry

fbshipit-source-id: 0b34ebc7f23ba38ecd89640b61d8aca59b7eab58
2021-08-19 12:50:41 -07:00
1022443168 Revert D30279364: [codemod][lint][fbcode/c*] Enable BLACK by default
Test Plan: revert-hammer

Differential Revision:
D30279364 (b004307252)

Original commit changeset: c1ed77dfe43a

fbshipit-source-id: eab50857675c51e0088391af06ec0ecb14e2347e
2021-08-12 11:45:01 -07:00
b004307252 [codemod][lint][fbcode/c*] Enable BLACK by default
Test Plan: manual inspection & sandcastle

Reviewed By: zertosh

Differential Revision: D30279364

fbshipit-source-id: c1ed77dfe43a3bde358f92737cd5535ae5d13c9a
2021-08-12 10:58:35 -07:00
b963607d50 [nnc] Insert alloc/free at global scope (#61725)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/61725

Alloc/free inside a loop isn't really an optimization, and furthermore
it breaks some attempted optimization in the llvm backend: we use alloca for
small allocations, which is efficient since alloca is on the stack, but there's
no corresponding free, so we leak tons of stack.  I hit this while building an
rfactor buffer inside a very deeply nested loop.
ghstack-source-id: 133627310

Test Plan:
Unit test which simulates use of a temp buffer in a deeply nested
loop.

Reviewed By: navahgar

Differential Revision: D29533364

fbshipit-source-id: c321f4cb05304cfb9146afe32edc4567b623412e
2021-07-16 08:42:24 -07:00
b52909d861 [TensorExpr] Add python bindings for ArgValue class and TensorExprKernel constructor accepting custom lowerings. (#61385)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/61385

The bindings coverage might be not full yet, but this already allows us
to register custom lowerings from python.

Test Plan: Imported from OSS

Reviewed By: navahgar

Differential Revision: D29623487

Pulled By: ZolotukhinM

fbshipit-source-id: b97ee420a57fd887e204c021b9e098764b2ee232
2021-07-09 18:27:14 -07:00
85517a2b70 [TensorExpr] More python binding cleanups (#60058)
Summary:
A few more quality of life improvements for NNC's python bindings:
- Use standard `torch.dtype`s (rather than `te.Dtype`)
- Make names optional (they don't seem to matter)
- Make shapes optional
- A few implicit conversions to make code cleaner

Followup to https://github.com/pytorch/pytorch/issues/59920

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

Reviewed By: bertmaher

Differential Revision: D29151953

Pulled By: jansel

fbshipit-source-id: c8286e329eb4ee3921ca0786e17248cf6a898bd8
2021-06-16 20:06:08 -07:00
ab70e1e984 [TensorExpr] Add error checking in mem_arena (#59922)
Summary:
Gives an error message (rather than a segfault) if you forget `KernelScope()`.

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

Reviewed By: bertmaher

Differential Revision: D29091303

Pulled By: jansel

fbshipit-source-id: a24ee2385cae1f210b0cbc3f8860948fc052b655
2021-06-14 10:37:32 -07:00
3d90c82a5c [TensorExpr] Python binding improvements (#59920)
Summary:
Some minor quality of life improvements for the NNC python bindings:
- expose `call_raw()`
- support passing integers to `call()` (for dynamic shapes)
- implicit conversions to cleanup `[BufferArg(x) for x in [A, B, C]]` into just `[A, B, C]`
- don't silently default to "ir_eval" for unknown mode (e.g. "LLVM")

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

Reviewed By: ZolotukhinM

Differential Revision: D29090904

Pulled By: jansel

fbshipit-source-id: 154ace82725ae2046cfe2e6eb324fd37f5d209a7
2021-06-14 09:31:40 -07:00
ee4be5322b Fix lint in test_tensorexpr_pybind (#57869)
Summary:
Fixes #{issue number}

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

Pulled By: driazati

Reviewed By: gmagogsfm

Differential Revision: D28303542

fbshipit-source-id: a4c77c1e7ee92c39fd1c7d88422728e2f1c31680
2021-05-07 15:58:21 -07:00
b38f153d91 [nnc] Added NNC lowerings for t/transpose/permute/expand + other cleaning (#57426)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/57426

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D28293191

Pulled By: Chillee

fbshipit-source-id: b8fc44299acf2569c11e87e1991a2b724434b15d
2021-05-07 15:38:56 -07:00
839d549f8f [JIT] Add a pass for removing a first (self) argument from a graph if it is unused. (#57169)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57169

The pass is planned to be used in AOT pipeline, where we expect input
graphs to be functional. As such, these graphs should not use 'self'
argument even if it is present, and thus it can be remove safely.

Test Plan: Imported from OSS

Reviewed By: bertmaher

Differential Revision: D28128328

Pulled By: ZolotukhinM

fbshipit-source-id: a7dfbf7776682826100c8eb0fef982a2e81c2554
2021-05-03 20:02:25 -07:00
3ad3d8bd3f [JIT] Add a pass for annotating graph with input types derived from sample inputs. (#57076)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57076

This pass is intended to be used in conjunction with shape propagation
pass: first we use sample inputs to specify shape info for graph inputs
and then we run shape-prop to infer shapes of intermediate values in the
graph.

Differential Revision: D28048290

Test Plan: Imported from OSS

Reviewed By: astaff

Pulled By: ZolotukhinM

fbshipit-source-id: 778d772e873d59d77af9f669f45dc44b9ee5e443
2021-05-03 20:01:15 -07:00
50cb75edce [tensorexpr] Add python bindings for TensorExprKernel (#54450)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/54450

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D27243175

Pulled By: huiguoo

fbshipit-source-id: 820cf0d6cd1dd984d4153628e0f419d234668c82
2021-04-01 02:11:32 -07:00
a176c73ed5 [TensorExpr] Reland: "PyBind: bind ExternalCalls." (#53063)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/53063

The problem was that a derived class was marked with "py::nodelete",
while the base class wasn't. Now they both are marked correctly.

Test Plan: Imported from OSS

Reviewed By: bertmaher

Differential Revision: D26737877

Pulled By: ZolotukhinM

fbshipit-source-id: 17d9d430651c8f695fc7b6bf6784e7719e20a4d2
2021-03-01 20:44:10 -08:00
7d060735ca Back out "[TensorExpr] PyBind: bind ExternalCalls."
Summary: Original commit changeset: e1ea3b3630d1

Test Plan: Broke tests, e.g. T85754010

Reviewed By: ZolotukhinM

Differential Revision: D26727166

fbshipit-source-id: 42d2090bc55ec2982a4a08c38278c80617d5398a
2021-03-01 10:51:06 -08:00
e63ec556bf [TensorExpr] PyBind: bind ExternalCalls. (#52905)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/52905

Differential Revision: D26707491

Test Plan: Imported from OSS

Reviewed By: Chillee

Pulled By: ZolotukhinM

fbshipit-source-id: e1ea3b3630d115e3d81842895c62e22c4cb06fb8
2021-02-26 20:28:13 -08:00
9920ae665b Make te a hidden package for now (#51690)
Summary:
As discussed with suo , having it in `torch._C.XX` means that it automatically gets added to `torch.XX` which is unfortunate. Making it `torch._C._XX` means that it won't be added to `torch.`.

Let me know if that approach to hide it is not good and we can update that.

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

Reviewed By: gchanan

Differential Revision: D26243207

Pulled By: albanD

fbshipit-source-id: 3eb91a96635e90a6b98df799e3a732833dd280d5
2021-02-04 07:58:38 -08:00
806010b75e [BE] move more unittest.main() to run_tests() (#50923)
Summary:
Relate to https://github.com/pytorch/pytorch/issues/50483.

Everything except ONNX, detectron and release notes tests are moved to use common_utils.run_tests() to ensure CI reports XML correctly.

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

Reviewed By: samestep

Differential Revision: D26027621

Pulled By: walterddr

fbshipit-source-id: b04c03f10d1fe96181b720c4c3868e86e4c6281a
2021-01-25 07:23:09 -08:00
e9dc8fc162 [TensorExpr] Add python bindings. (#49698)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49698

Reincarnation of #47620 by jamesr66a.

It's just an initial bunch of things that we're exposing to python, more
is expected to come in future. Some things can probably be done better,
but I'm putting this out anyway, since some other people were interested
in using and/or developing this.

Differential Revision: D25668694

Test Plan: Imported from OSS

Reviewed By: bertmaher

Pulled By: ZolotukhinM

fbshipit-source-id: fb0fd1b31e851ef9ab724686b9ac2d172fa4905a
2021-01-14 21:02:47 -08:00