Commit Graph

46 Commits

Author SHA1 Message Date
Xuehai Pan
8d45f555d7 [BE] [1/3] Rewrite super() calls in caffe2 and benchmarks (#94587)
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/94587
Approved by: https://github.com/ezyang
2023-02-11 18:19:48 +00:00
Aaron Gokaslan
8fce9a09cd [BE]: pyupgrade Python to 3.8 - imports and object inheritance only (#94308)
Apply parts of pyupgrade to torch (starting with the safest changes).
This PR only does two things: removes the need to inherit from object and removes unused future imports.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94308
Approved by: https://github.com/ezyang, https://github.com/albanD
2023-02-07 21:10:56 +00:00
Nikita Shulga
1906eaf22f [BE] Get rid of future (#92596)
PyTorch has been Python-3.X+ for ages, so it's a shame to still rely on `future.utils` even in a deprecated Caffe2 codebase

For the reference:
https://peps.python.org/pep-0469/#migrating-directly-to-python-3

Pull Request resolved: https://github.com/pytorch/pytorch/pull/92596
Approved by: https://github.com/kit1980, https://github.com/orionr
2023-01-19 08:46:50 +00:00
Adam Simpkins
c4eb22009e Drop some Python 2 compatibility code (#51769)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51769

Remove some Python 2 compatibility code that otherwise causes errors to
be reported from static type checkers.

Static type checkers complain that the old Python 2 modules and
functions referenced by this code do not exist.  Given that Python 2
support is entirely deprecated now we can simply remove the
compatibility code.
ghstack-source-id: 121313191

Test Plan:
Was able to get Pyre to successfully type check the `caffe2/python`
directory with this and some other changes.

Reviewed By: Tianshu-Bao

Differential Revision: D26271723

Pulled By: simpkins

fbshipit-source-id: fec8a09466be6867388832380480aafd36616aa1
2021-02-11 11:02:33 -08:00
Bugra Akyildiz
27c7158166 Remove __future__ imports for legacy Python2 supports (#45033)
Summary:
There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports:

```2to3 -f future -w caffe2```

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

Reviewed By: seemethere

Differential Revision: D23808648

Pulled By: bugra

fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
2020-09-23 17:57:02 -07:00
Andres Suarez
9ea9d1b52e [fbs][2/n] Remove .python3 markers
Test Plan:
`xbgr '\.python3'` shows only one (dead) usage of this file:
https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/python/repo_stats/buck.py?commit=9a8dd3243207819325d520c208218f6ab69e4e49&lines=854

Reviewed By: lisroach

Differential Revision: D22955631

fbshipit-source-id: e686d9157c08c347d0ce4acdd05bd7ab29ff7df5
2020-08-05 18:25:50 -07:00
Stanislau Hlebik
b774ce54f8 remediation of S205607
fbshipit-source-id: 798decc90db4f13770e97cdce3c0df7d5421b2a3
2020-07-17 17:19:47 -07:00
Stanislau Hlebik
8fdea489af remediation of S205607
fbshipit-source-id: 5113fe0c527595e4227ff827253b7414abbdf7ac
2020-07-17 17:17:03 -07:00
James Reed
341fb6d11d Make caffe2/caffe2/python/models/seq2seq python3 compatible
Test Plan: watiforsadcastle

Reviewed By: dzhulgakov

Differential Revision: D19698403

fbshipit-source-id: 36b73e07e598c848abbe368e522484da9ba4c78f
2020-02-04 10:51:47 -08:00
rohithkrn
0d663cec30 Unify cuda and hip device types in Caffe2 python front end (#14221)
Summary:
Goal of this PR is to unify cuda and hip device types in caffe2 python front end.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14221

Differential Revision: D13148564

Pulled By: bddppq

fbshipit-source-id: ef9bd2c7d238200165f217097ac5727e686d887b
2018-11-29 14:00:16 -08:00
Pritam Damania
5bd43a7af8 Refactor Seq2SeqModelCaffe2EnsembleDecoder (#10035)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/10035

This is an initial diff which refactors some of the components in the Seq2SeqModelCaffe2EnsembleDecoder class.

Reviewed By: jmp84

Differential Revision: D9026372

fbshipit-source-id: 449635208f24494209ae2fb78a19fca872970ea8
2018-07-31 23:09:09 -07:00
Orion Reblitz-Richardson
1d5780d42c Remove Apache headers from source.
* LICENSE file contains details, so removing from individual source files.
2018-03-27 13:10:18 -07:00
jmp84
b465bb9a8e fix post eos penalty (#2235) 2018-03-12 12:42:22 -07:00
Junjie Bai
b11ba65204 Experimental support for setup.py develop mode install
Summary:
`python setup.py develop` / `pip install -e .`
Closes https://github.com/caffe2/caffe2/pull/1926

Reviewed By: orionr

Differential Revision: D6951780

Pulled By: bddppq

fbshipit-source-id: 01249cbca90ec5326ea4107d4e500ae95a9dbd7b
2018-02-12 23:36:18 -08:00
Alexander Sidorov
e0e124e617 Fix RNN scoping situation
Summary:
There is a long lasting problem of scoping which was introduced in original python wrappers early in H1. Basically each RNNCell implemented has to manually scope outputs of each of the operators. If somebody forgets, then there could be weird bugs with layers etc.

Approach is the following. User has to explicitly specify current scope when using  apply_over_sequence function and others if the function is going to be called several times (like for stacking layers). This way we use Caffe2 native scoping approach instead of inventing one extra API people have to use (i.e. passing scope name as an argument to the RNNCell constructor).
Closes https://github.com/caffe2/caffe2/pull/1681

Differential Revision: D6777536

Pulled By: salexspb

fbshipit-source-id: 73d860b8d4857589e04bdea5a6fcd3080d68427c
2018-02-07 17:35:29 -08:00
Ves Stoyanov
1a0eefd5fc Parallelize batcher
Summary: Still WIP, but works for the universal encoder. The other ones are currently broken.

Differential Revision: D6492786

fbshipit-source-id: 232e0058eb3a0c036de3adf0295db5efd624cca7
2017-12-22 20:23:26 -08:00
Martin Schatz
f233a3ebd8 Explicitly set default data type in seq2seq/translate.py
Summary: word_rewards data type is mixed; ConstantFill assigns long but later is filled with float32.  This causes issues when running net from outputted protobuf.  This change makes data type to be float32 for lifetime of blob.

Reviewed By: jhcross

Differential Revision: D6486723

fbshipit-source-id: c4ce5185a0a6d71b08b1819f2355e9354823b701
2017-12-07 11:21:01 -08:00
Simon Layton
a8250280bb Py3 test fixes
Summary:
\cc pietern
Closes https://github.com/caffe2/caffe2/pull/1555

Differential Revision: D6479902

Pulled By: pietern

fbshipit-source-id: 84647eddec45620b1ed603f4882ded2dd49adc43
2017-12-05 10:34:41 -08:00
James Cross
65a1dbc93d penalty for EOS successor
Summary: Current beam search generates successor states to EOS which are considered for inclusion in the beam even though they do not represent valid sequence prefixes. This diff introduces a penalty to ensure that such states are not included in the beam.

Reviewed By: xliilx

Differential Revision: D6325511

fbshipit-source-id: b17f10b0d00f3bc5fcc5a826a8a57a0f2cb360a6
2017-11-14 21:46:56 -08:00
James Cross
397793d61c simplify beam search code
Summary: This cleans up the _hack_get_slice_end() using the Conditional operator.

Reviewed By: jmp84

Differential Revision: D6177797

fbshipit-source-id: 5ce0b76b8472123415bba39488aa2c69aad96111
2017-10-31 16:59:20 -07:00
Aapo Kyrola
86e3e008e0 optimize RNN executor subnet construction for forward-only models
Summary:
RNN executor had a disadvantage to plain nets when running in forward-only mode: for plain nets, we only create two workspaces and two nets and alternate between them. With RNN executor, we had only four workspaces (4 > 2 because it was faster in some cases), but the nets (or rather the ops) were created for each of the timesteps. This has significant overhead. This diff changes this sos that if executor is is forward-only mode (i.e has limited parallelism setting), then it will use the same operators as the t - 4'th net -- excluding the ops that require the timestep blob. The latter exception is required because RNN executor needs different timestep blob for each timestep because it cannot modify the value of the timestep blob like when running nets in a loop.

Also removed redundancy in the dependency computation and added a debug flag to the executor that outputs the description of the rnn contents.

Reviewed By: salexspb

Differential Revision: D6155510

fbshipit-source-id: c47f727d2128649b081270d15020a08d41e5748d
2017-10-30 12:24:12 -07:00
Aapo Kyrola
63297e1a1f RunNetOnce->RunNet (removes rnn_executor overhead)
Summary:
seq2seq/translate.py was running much slower on RNNExecutor. This was because RNNExecutor has significant init overhead (I have another diff to reduce, but not completely eliminate it), and translate was calling the decoder with RunNetOnce -- thus always recreating the net and the ops. Changhing this to RunNet() makes translate run faster than without executor. RunNet uses the net name and uses the already created net, while RunNetOnce passes the whole protobuffer.

Noticed similar bug in seq2seq ensemble bean model, which also calls CreateNet() but uses RunNetOnce() instead of RunNet().

Reviewed By: jhcross

Differential Revision: D6156566

fbshipit-source-id: a933453e36a0d8fd163d0584186fda427a680687
2017-10-25 22:06:02 -07:00
Aapo Kyrola
241b9f6c14 disable rnn executor for beam search
Summary:
RNN executor has significant overhead of creating the timestep-nets the first time, and this is especially bad with beamsearch that is complex.
So disable RNN executor for now until perf regression is fixed (I have pending diff on it).

Reviewed By: salexspb

Differential Revision: D6138878

fbshipit-source-id: ce63ab9ce9cc1c0f67097aea1e370494ca98c680
2017-10-24 20:49:56 -07:00
Dmytro Dzhulgakov
2972a6ca02 Revert D6026557: [caffe2][PR] Fix "No handlers could be found for logger"
Summary:
This reverts commit 95c634872ac02be721257169e38c8fead04cd66b

bypass-lint

Differential Revision: D6026557

fbshipit-source-id: 663c28583ce3b01070ff5449115ed7e222f71776
2017-10-12 20:21:52 -07:00
Luke Yeager
75bece6ede Fix "No handlers could be found for logger"
Summary: Closes https://github.com/caffe2/caffe2/pull/1316

Differential Revision: D6026557

Pulled By: Yangqing

fbshipit-source-id: 95c634872ac02be721257169e38c8fead04cd66b
2017-10-10 22:32:13 -07:00
Andrey Malevich
e13f199452 Switch RNNOp to use NetDef argument for step represenetation.
Summary: Before this diff RNNOp was using TextFormat for representing steps. This diff is changing RNNOp to prefer NetDef argument instead. To be backward compatible it supports TextFormat for existing models, though we can compile RNNs without TextFormat as well.

Reviewed By: salexspb

Differential Revision: D5949330

fbshipit-source-id: 9336a8f5ccf30ad8d8e3a7067b9437e1704b1c9f
2017-10-10 22:01:51 -07:00
Yangqing Jia
8286ce1e3a Re-license to Apache
Summary: Closes https://github.com/caffe2/caffe2/pull/1260

Differential Revision: D5906739

Pulled By: Yangqing

fbshipit-source-id: e482ba9ba60b5337d9165f28f7ec68d4518a0902
2017-09-28 16:22:00 -07:00
Junjie Bai
d9b0bcd7a4 Make all existing (except in RoIPool) "is_test" arguments required
Reviewed By: akyrola

Differential Revision: D5830168

fbshipit-source-id: 8634e9cfe308ba0ee90cd8a5c4b09a47b0b5f015
2017-09-25 23:46:12 -07:00
James Reed
ab62a92dab De-dup beam search state reshape shape blob
Summary:
T22119644 showed that there is a potential illegal memory access in beam search with attention. Upon further inspection, we can see that there are multiple ops that write to the same old shape blob:

  {"output0": "model0/attention_decoder/attention_weighted_encoder_context_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/attention_decoder/attention_weighted_encoder_context" }},
  {"output0": "model0/attention_decoder/hidden_t_external_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/attention_decoder/hidden_t_external" }},
  {"output0": "model0/decoder/layer0/cell_t_reshaped", "output1": "state_old_shape_before_choosing_per_hypo", "input0": "model0/decoder/layer0/cell_t" }},

This diff de-dupes these outputs

Reviewed By: akyrola

Differential Revision: D5899103

fbshipit-source-id: 8b6f3f113e764dfeb9262f6c442e1124559cd2d8
2017-09-23 23:19:44 -07:00
James Reed
0d6baa0d59 Fix lack of data dependencies for beam search RecurrentNetwork op
Summary: Previously, the RecurrentNetwork op used for our beam search did not have any of the input blobs listed as data dependencies. This was fine when we were using SimpleNet, since the ops were run in the order in which we added them to the graph, and thus the RecurrentNetwork op was run after all the other ops. However, when switching to DAG, the ops that produce input data for the beam search were being run in parallel with the RecurrentNetwork beam search op, which caused non-deterministic failures based on thread scheduling. This fixes that

Reviewed By: jmp84, jhcross

Differential Revision: D5879622

fbshipit-source-id: b622de1f6a24b2636b191096db92990e0535890c
2017-09-22 12:18:20 -07:00
Xian Li
68e7a0f2ed Enable target dialect token in inference.
Differential Revision: D5665714

fbshipit-source-id: 56ba88e72f71cae23d992e3ad7ea134c3d2c6d1d
2017-09-12 17:22:18 -07:00
Xian Li
a782858285 Move go_token_id out of beam search constructor.
Summary: This is will allow the same decoder to handle different go tokens.

Differential Revision: D5801811

fbshipit-source-id: ddd309963c97e32c728b15d2ccd4ba0c4ad5ebbe
2017-09-11 18:52:08 -07:00
Aapo Kyrola
45f07238f4 make rnn executor figure out recurrent mappings from links
Summary: RNN executor previously relied on getting the mapping from x to x_prev (and gradients) from recurrent.py, but we can just infer them from links. This makes all models compatible with rnn executor, given enable_rnn_executor=1 argument.

Reviewed By: jamesr66a

Differential Revision: D5801436

fbshipit-source-id: 14d0e26dfbad6347f645d907da493187c98e9b17
2017-09-09 16:19:26 -07:00
James Cross
4758bd851b rectify args btw. train and translate
Summary: Make the command-line arguments pertaining to model architecture the same as between train.py and translate.py. Also use s() scoping function for all intermediate blobs in attention.py (this is for comatibility with multi-headed attention).

Differential Revision: D5594312

fbshipit-source-id: cadf51d854b5a9174ec913f32c655be2abf111e5
2017-08-10 15:27:18 -07:00
James Cross
9fcf676cfa testing for open-source seq2seq
Summary:
Fix multilayer inference in Caffe2 example seq2seq code. (Rely on LSTMWithAttentionDecoder.apply rather than fixed state indices to determine stepwise decoder output.)

Also assorted updates to bring code in line with changes elsewhere in the codebase, and added unit tests which ensure that training and inference networks generate the same loss, which should make these problems much easier to identify in future.

Reviewed By: jamesr66a

Differential Revision: D5579803

fbshipit-source-id: 6e0f27340d981990ab8d0da58e63793222e7be87
2017-08-08 10:09:41 -07:00
Juan Miguel Pino
4d8a8c2e1e Implement dot attention
Summary:
Implement dot attention as described in https://arxiv.org/abs/1508.04025
This saves the computation of weighted encoder outputs in `rnn_cell.py`
When the encoder and decoder dimensions are different, we apply an FC, which corresponds to the general case below Figure 2.
Refactored unit tests.

Reviewed By: jhcross

Differential Revision: D5486976

fbshipit-source-id: f9e9aea675b3b072fbe631bc004199b90a9d95cb
2017-08-06 11:50:16 -07:00
James Cross
8c65b5ab34 multilayer seq2seq
Summary: Several refinements to seq2seq example code, including support for multilayer LSTM.

Reviewed By: jamesr66a

Differential Revision: D5460372

fbshipit-source-id: d2eabf6aa9a5b5df7bbc341fd99c4e7d8322e717
2017-07-31 12:27:51 -07:00
Junjie Bai
a305ce3ece Fix broken seq2seq example
Reviewed By: harouwu

Differential Revision: D5423060

fbshipit-source-id: 4537b020546503a1f9cb237257ab3c42665ae07f
2017-07-13 23:31:54 -07:00
Thomas Dudziak
5355634dac Dict fixes/improvements and unittest targets for Python 3 in caffe2 core
Summary: As title

Reviewed By: salexspb

Differential Revision: D5316104

fbshipit-source-id: aee43819d817842e5ce6ba3d045a55b1a2491c30
2017-06-29 17:05:41 -07:00
Junjie Bai
86305ddd49 Deprecate CNNModelHelper in python/seq2seq/seq2seq_model_helper.py
Summary: Also added some simple tests for Seq2SeqModelHelper.

Reviewed By: jamesr66a

Differential Revision: D5291733

fbshipit-source-id: 15866dccb89acd82c08e0348f14834cd9c201422
2017-06-28 20:18:12 -07:00
Thomas Dudziak
d524d5b481 Fixes zip/izip for Python 3
Summary: As title

Reviewed By: salexspb

Differential Revision: D5154186

fbshipit-source-id: 2ef24557d82ae16d3bdfbc90a4cc96be8e2dc6c3
2017-06-07 00:04:26 -07:00
Thomas Dudziak
60c78d6160 Fixes range/xrange for Python 3
Summary: As title

Differential Revision: D5151894

fbshipit-source-id: 7badce5d3122e8f2526a7170fbdcf0d0b66e2638
2017-06-07 00:04:26 -07:00
Thomas Dudziak
47e921ba49 Remove map() and filter() in favor of comprehensions
Summary: These return views in Python 3 which would not do anything in a lot of usages currently present in Caffe2. This diff simply removes (almost) all usages of these two in Caffe2 and sub projects in favor of comprehensions which are also easier to read/understand

Reviewed By: akyrola

Differential Revision: D5142049

fbshipit-source-id: e800631d2df7d0823fed698cae46c486038007dc
2017-05-30 15:32:58 -07:00
Yury Zemlyanskiy
11052d03aa RNNCell API change: returns states and outputs
Summary:
Incorporating definition of cell's output and illustraing it's usage by adding dropout to all types of cell.

I think that we should try to get rid of aliases in RecurrentNetwork, so output of applied_over_sequence is also always (state_1_all, state_2_all, ...). This way we can merge get_output_from_single_step, get_output_from_sequence and get_outputs_with_grads into a single method

Let me know what do you think!

Reviewed By: jhcross

Differential Revision: D4992913

fbshipit-source-id: 737939be336ad145f84e8733cd255d4f7188ef70
2017-05-08 15:19:48 -07:00
Yury Zemlyanskiy
31643d5ecb Inference code for seq2seq model
Summary: Beam search implementation

Differential Revision: D4975939

fbshipit-source-id: 67d8b73390221583f36b4367f23626a2aa80f4b4
2017-05-02 22:47:28 -07:00
Yury Zemlyanskiy
12a024241a Move BeamSearchForwardOnly to OSS
Summary: Step 1 for inference code in OSS

Differential Revision: D4960547

fbshipit-source-id: 4c3121e5cb3c2402be08947c1e1afa0dd6eb921a
2017-04-27 13:35:53 -07:00